Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71c60ade8a | |||
| bf3dc635d9 | |||
| 8ca899aaf5 | |||
| 15facf48eb | |||
| 71fc90fcb8 | |||
| 856701fb6f | |||
| 6037b62612 | |||
| 8f88cb0030 | |||
| c224562423 | |||
| 5c07aef526 | |||
| d54d37061f | |||
| a6afec0e11 | |||
| 205112021b | |||
| 853f2737f1 | |||
| 7c61107f87 | |||
| 7a22474efd | |||
| f2cf4e0d58 | |||
| db4bebfa57 | |||
| 435b77e1df | |||
| 6f80e442cf | |||
| 0fcbf5e3ed | |||
| 3cf6308b79 | |||
| 7e5a4da659 | |||
| d27fcaf342 | |||
| 5b28a065c0 | |||
| e74e1eaf70 | |||
| ff7c6333bb | |||
| 2c85df3499 | |||
| 6f11f28448 | |||
| 21a315ca71 | |||
| d8b05082d6 | |||
| de91073b2e | |||
| e88b5f57bf | |||
| 64a17c8c19 | |||
| ebeacba8b5 | |||
| 58251b26a2 | |||
| 5c10990cbc | |||
| f71936da86 |
@@ -25,6 +25,10 @@ aria-data/brain-import/*
|
||||
!aria-data/brain-import/.gitkeep
|
||||
!aria-data/brain-import/README.md
|
||||
|
||||
# .aria-debug/ — App-Crash-Logs die tools/fetch-app-logs.sh hier ablegt.
|
||||
# Komplett lokal, enthaelt potentiell private Stacktraces / Daten.
|
||||
.aria-debug/
|
||||
|
||||
# ── ARIAs Gedächtnis (Vector-DB, Skills, Models) ──
|
||||
# Backup via Diagnostic → Gehirn-Export (tar.gz), nicht via Git.
|
||||
aria-data/brain/data/
|
||||
|
||||
@@ -200,7 +200,7 @@ Die Diagnostic-UI hat sechs Top-Tabs:
|
||||
- **Main** — Live-Chat-Test, Status (Brain / RVS / Proxy), End-to-End-Trace
|
||||
- **Gehirn** — Memory-Verwaltung (Vector-DB), Token/Call-Metrics (Subscription-Quota), Bootstrap & Migration, Komplett-Gehirn Export/Import
|
||||
- **Skills** — Liste mit Logs, Run, Activate/Deactivate, Export/Import als tar.gz
|
||||
- **Trigger** — Timer + Watcher anlegen/anzeigen/loeschen, Live-Variablen-Anzeige (disk_free, current_lat, hour_of_day, …), near(lat, lon, m) als Condition-Funktion
|
||||
- **Trigger** — Timer + Watcher anlegen/anzeigen/loeschen, Live-Variablen-Anzeige (disk_free, current_lat, hour_of_day, …), GPS-Funktionen `near() / entered_near() / left_near()` für unterschiedliche Geofencing-Modi
|
||||
- **Dateien** — alle Dateien aus `/shared/uploads/` mit Multi-Select, Bulk-Download (ZIP) + Bulk-Delete
|
||||
- **Einstellungen** — Reparatur (Container-Restart), Wipe, Sprachausgabe, Whisper, Sprachmodell, Runtime-Config, App-Onboarding (QR), Komplett-Reset
|
||||
|
||||
@@ -319,7 +319,14 @@ Erreichbar unter `http://<VM-IP>:3001`. Teilt das Netzwerk mit der Bridge.
|
||||
- **Main**: Brain/RVS/Proxy-Status, Chat-Test, "ARIA denkt..."-Indikator, End-to-End-Trace, Container-Logs
|
||||
- **Gehirn**: Memory-Browser (Vector-DB), Suche mit zwei Modi (**📝 Wortlich** = Substring-Match Default + **🧠 Semantisch** mit Score-Threshold), **Advanced Search** (aufklappbares Panel, beliebig viele AND/OR-verknuepfte Felder, + Button fuer mehr Zeilen), Type+Pinned-Filter (greifen auch in der Suche), klappbare Type-Kategorien (Default eingeklappt), Add/Edit/Delete mit Category-Autosuggest, **📎 Anhaenge** pro Memory (Bilder/PDFs/...): Upload + Thumbnail-Vorschau + Lightbox + Lösch-Button, 📎N-Badge in der Liste, automatischer Cleanup beim Memory-Delete. ℹ-Info-Modal das erklaert welche Types FEST in den Prompt vs. Cold Memory wandern. **📄 Druckansicht** (Strg+P → PDF). Konversation-Status mit Destillat-Trigger, **Token/Call-Metrics mit Subscription-Quota-Tracking**, Bootstrap & Migration (3 Wiederherstellungs-Wege), Gehirn-Export/Import (tar.gz)
|
||||
- **Skills**: Liste aller Skills mit Logs pro Run, Activate/Deactivate, Export/Import als tar.gz, "von ARIA"-Badge fuer selbst gebaute
|
||||
- **Trigger**: passive Aufweck-Quellen. **Timer** (einmalig, ISO-Timestamp oder via `in_seconds` als Server-Berechnung) + **Watcher** (recurring, mit Condition + Throttle). Liste aktiver Trigger + Logs pro Feuer-Event. Modal mit Type-Dropdown, Live-Anzeige aller verfuegbaren Condition-Variablen (`disk_free_gb`, `hour_of_day`, `current_lat/lon`, `last_user_message_ago_sec`, …) und Condition-Funktionen (`near(lat, lon, m)` fuer GPS-Geofencing). Sicherer Condition-Parser via Python `ast` (Whitelist, kein `eval`). Der System-Prompt enthaelt zusaetzlich einen `## Aktuelle Zeit`-Block (UTC + Europa/Berlin) damit ARIA Timer-Zeitpunkte korrekt setzen kann.
|
||||
- **Trigger**: passive Aufweck-Quellen. **Timer** (einmalig, ISO-Timestamp oder via `in_seconds` als Server-Berechnung) + **Watcher** (recurring, mit Condition + Throttle). Liste aktiver Trigger + Logs pro Feuer-Event. Modal mit Type-Dropdown, Live-Anzeige aller verfuegbaren Condition-Variablen (`disk_free_gb`, `hour_of_day`, `current_lat/lon`, `last_user_message_ago_sec`, …). **Drei GPS-Funktionen** mit unterschiedlicher Semantik:
|
||||
- `near(lat, lon, r)` — SOLANGE im Radius (mit Throttle gegen Spam). Use-Case: „bin ich noch in der Nähe von X?"
|
||||
- `entered_near(lat, lon, r)` — EINMAL beim Eintritt (Übergang außen→innen). Use-Case: Blitzer-Warner mit r=2000 → 2 km Vorwarnung, oder Ankunfts-Erinnerung mit r=100
|
||||
- `left_near(lat, lon, r)` — EINMAL beim Verlassen (Übergang innen→außen). Use-Case: „Hast du am Parkplatz X was vergessen?"
|
||||
|
||||
Sicherer Condition-Parser via Python `ast` (Whitelist, kein `eval`). Der System-Prompt enthaelt zusaetzlich einen `## Aktuelle Zeit`-Block (UTC + Europa/Berlin) damit ARIA Timer-Zeitpunkte korrekt setzen kann.
|
||||
|
||||
**Auflösung**: Background-Loop tickt alle 8s (vorher 30s — bei 100 km/h durch einen 300m-Radius war eine Vorbeifahrt nur ~22s drin und konnte verpasst werden). Plus event-getrieben: Bridge ruft nach jedem `location_update` von der App sofort einen `/triggers/check-now` im Brain — Watcher sehen die frische Position in Millisekunden statt im Polling-Takt. `near()`-Funktionen ignorieren GPS-Daten älter als 5 Minuten (verhindert Phantom-Fires bei abgeschaltetem Tracking).
|
||||
- **Dateien**: Browser fuer `/shared/uploads/` mit Multi-Select + "Alle markieren" + Bulk-Download (ZIP bei 2+) + Bulk-Delete. Live-Update der Chat-Bubbles beim Delete.
|
||||
- **Einstellungen**: Reparatur (Container-Restart fuer Brain/Bridge/Qdrant), Komplett-Reset, Betriebsmodi, Sprachausgabe + Voice-Cloning + F5-TTS-Tuning + Voice Export/Import, Whisper, Sprachmodell (brainModel), Onboarding-QR, App-Cleanup
|
||||
|
||||
@@ -355,8 +362,13 @@ Erreichbar unter `http://<VM-IP>:3001`. Teilt das Netzwerk mit der Bridge.
|
||||
- **Lokale Voice-Wahl**: Pro Geraet eigene Stimme moeglich (in Settings). Diagnostic-Wechsel ueberschreibt alle App-Wahlen.
|
||||
- **Voice-Ready Toast**: Beim Wechsel zeigt die App "Stimme X bereit (X.Ys)" sobald der Preload durch ist
|
||||
- **Play-Button**: Jede ARIA-Nachricht kann nochmal vorgelesen werden (aus Cache wenn vorhanden, sonst neu rendern)
|
||||
- **Chat-Suche**: Lupe in der Statusleiste filtert Nachrichten live
|
||||
- **Chat-Suche**: Lupe in der Statusleiste — Highlight + Next/Prev springt zum Treffer (Bubble landet am Text-Anfang oben am Viewport)
|
||||
- **Jump-to-Bottom-Button**: erscheint rechts unten sobald man weg von der neuesten Nachricht scrollt, ein Tap fuehrt zurueck
|
||||
- **Delivery-Status pro User-Bubble** (WhatsApp-Style): `⏱` (queued, wartet auf Verbindung) → `⏳` (sending) → `✓` (Bridge hat ACK gesendet) → `✓✓` (ARIA hat verarbeitet). Bei Netzausfall werden Nachrichten lokal als queued gehalten und beim Reconnect automatisch geflusht. Bei drei ACK-Timeouts → `⚠ tippen f. Retry`. Idempotenz auf der Bridge (LRU ueber `clientMsgId`) verhindert Doppelte beim Retry
|
||||
- **Mülltonne pro Bubble** (mit Confirm): gezielt eine Nachricht loeschen — geht nicht nur aus der UI weg, sondern auch aus `chat_backup.jsonl`, Brain-Conversation-Window und allen anderen Clients (RVS-Broadcast). Wichtig damit ARIA den Turn auch beim naechsten Prompt nicht mehr im Kontext hat
|
||||
- **🗂️ Notizen-Inbox + Memory-Editor**: Neben der Lupe oeffnet `🗂️` ein Vollbild-Modal mit allen Memory/Trigger/Skill-Spezial-Bubbles aus dem Chat plus dem vollen DB-Browser. Tap auf eine Memory oeffnet ein **Detail/Edit-Modal**: Felder editieren, Anhaenge hoch-/runterladen + loeschen, Memory komplett loeschen. Identischer Editor auch in Settings → 🧠 Gedaechtnis. Spezial-Bubbles werden aus dem Chat-Stream gefiltert (keine ewig-unten-haengenden Notiz-Bubbles mehr)
|
||||
- **Bubble-Header dynamic**: „ARIA hat etwas gemerkt" / „Notiz geaendert" (gelb) / „Notiz geloescht" (rot) — je nach action im memory_saved-Event
|
||||
- **App-Crash-Reporting**: ungefangene JS-Errors + React-Render-Fehler landen automatisch in `/shared/logs/app.log` via RVS — kein ADB noetig, Logs holen via `tools/fetch-app-logs.sh` oder Diagnostic GET `/api/app-log`. ErrorBoundary verhindert White-Screen, zeigt stattdessen Error-Box im Modal mit Stack-Trace + Schliessen-Button
|
||||
- **Mehrere Anhaenge**: Bilder + Dateien sammeln, Text hinzufuegen, dann zusammen senden
|
||||
- **Paste-Support**: Bilder aus Zwischenablage einfuegen (Diagnostic)
|
||||
- **Anhaenge**: Bridge speichert in Shared Volume, ARIA kann darauf zugreifen, Re-Download ueber RVS
|
||||
@@ -867,10 +879,12 @@ docker exec aria-brain curl localhost:8080/memory/stats
|
||||
- [x] **Phase B Punkt 2:** Migration aus `aria-data/brain-import/` → atomare Memory-Punkte (Identity / Rule / Preference / Tool / Skill, idempotent ueber migration_key) + Bootstrap-Snapshot Export/Import (nur pinned)
|
||||
- [x] **Phase B Punkt 3:** Brain Conversation-Loop (Single-Chat UI, Rolling Window 50 Turns, Schwelle 60 → automatisches Destillat, manueller Trigger)
|
||||
- [x] **Phase B Punkt 4:** Skills-System (Python-only via local-venv, skill_create als Tool, dynamische run_<skill> Tools, Diagnostic Skills-Tab mit Logs/Toggle/Export/Import, skill_created Live-Notification in App+Diagnostic, harte Schwelle "pip → Skill")
|
||||
- [x] **Phase B Punkt 5:** Triggers-System (passive Aufweck-Quellen — Timer + Watcher mit safe Condition-Parser, GPS-near(), Diagnostic Trigger-Tab, kontinuierliches GPS-Tracking in der App fuer Use-Cases wie Blitzer-Warner). Inklusive Brain → Bridge HTTP-Push (Port 8090 intern) damit Trigger-Antworten ueber RVS in App + Diagnostic + TTS landen.
|
||||
- [x] **Phase B Punkt 5:** Triggers-System (passive Aufweck-Quellen — Timer + Watcher mit safe Condition-Parser, drei GPS-Funktionen `near()` / `entered_near()` / `left_near()` für unterschiedliche Geofencing-Modi, Diagnostic Trigger-Tab, kontinuierliches GPS-Tracking in der App fuer Use-Cases wie Blitzer-Warner). Tick-Frequenz 8s + event-getriebene Auswertung bei jedem `location_update` (statt 30s-Polling) damit auch Auto-Vorbeifahrten bei 100+ km/h durch kleine Radien zuverlässig erwischt werden. `near()`-Funktionen ignorieren GPS-Daten älter als 5 Minuten. Inklusive Brain → Bridge HTTP-Push (Port 8090 intern) damit Trigger-Antworten ueber RVS in App + Diagnostic + TTS landen.
|
||||
- [x] **Proxy Tool-Use durchreichen**: claude-max-api-proxy patcht via eigene Adapter (`proxy-patches/`) den `tools`/`tool_calls`-Roundtrip — Claude Code rief vorher ihre internen Tools (Bash, sleep) statt der ARIA-Brain-Tools (trigger_timer, skill_*, ...). Jetzt funktioniert Tool-Use End-to-End.
|
||||
- [x] **Single Source of Truth — Qdrant**: `memory_save`-Tool fuer ARIA, Claude-Code-Auto-Memory abgeklemmt (tmpfs ueber `~/.claude/projects` im Proxy-Container), `brain-import/` zum reinen Drop-Folder degradiert, Cold-Memory mit Score-Threshold (0.30) gegen Embedder-Noise/Crosstalk, Diagnostic-Gehirn-UI mit Wortlich-/Semantisch-Suche, Advanced Search (AND/OR mit + Button), Memory-Druckansicht, Muelltonne pro Chat-Bubble. DB ist jetzt durchgaengig die einzige Wissensquelle, kein paralleles File-Memory mehr.
|
||||
- [x] **Memory-Anhaenge mit Vision-Pipeline**: Pro Memory koennen Bilder/PDFs/beliebige Dateien angehaengt werden (unter `/shared/memory-attachments/<id>/`, max 20 MB). Diagnostic-UI mit Thumbnail-Vorschau + Lightbox, App `memory_saved`-Bubble mit Tap-to-Load via RVS, System-Prompt zeigt Anhang-Pfade. **ARIA sieht Bilder echt** via Claude Code's eingebautes multi-modales `Read`-Tool — kein Proxy-Patch noetig. `memory_save` hat `attach_paths`-Parameter sodass ARIA ein User-Foto im selben Tool-Call lesen, Infos extrahieren (Kennzeichen, Marken, Texte) und als Memory + Anhang persistieren kann. Bilder bleiben am Memory haengen — bei spaeteren Detail-Fragen liest ARIA das Bild einfach nochmal.
|
||||
- [x] **Memory-Editor in der App** (5 Etappen): Notizen-Inbox-Button neben der Lupe oeffnet ein Modal mit allen Spezial-Bubbles aus dem aktuellen Chat plus dem vollen DB-Browser. Tap auf eine Memory → Detail-Modal mit Anhang-Vorschau, Stift-Icon wechselt in Edit-Mode (Felder editieren + Anhaenge hoch-/runterladen + loeschen). Identischer Editor unter Settings → 🧠 Gedaechtnis. Bubble-Header dynamic je nach Aktion (created/updated/deleted). RVS-Brain-Proxy als Fundament (`brain_request`/`brain_response`) damit die App beliebige Brain-HTTP-Endpoints adressieren kann. `memory_search` + `memory_update` als ARIA-Tools damit sie aktiv die DB pruefen und Eintraege patchen kann statt zu fragmentieren.
|
||||
- [x] **App-Crash-Reporting via RVS**: ErrorBoundary + global JS-Error-Handler + Promise-Rejection-Tracker schicken Crashes als `app_log`-Event durch RVS. Bridge sammelt in `/shared/logs/app.log`, Diagnostic GET `/api/app-log`. `tools/fetch-app-logs.sh` holt die Logs auf die Dev-Maschine (gitignored `.aria-debug/`). Damit kann Stefan unterwegs ohne ADB debuggen — der erste Bug (URLSearchParams in Hermes) wurde so in 5 Minuten gefunden.
|
||||
- [x] Sprachmodell-Setting wieder funktional (brainModel in runtime.json statt aria-core)
|
||||
- [x] App-Chat-Sync: kompletter Server-Sync bei Reconnect (Server = Source of Truth) + chat_cleared Live-Update. Lokal-only Bubbles (Skill-Notifications, laufende Voice ohne STT) bleiben erhalten.
|
||||
- [x] App: Chat-Suche mit Next/Prev Navigation statt Filter
|
||||
|
||||
+4
-1
@@ -13,7 +13,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||
import ChatScreen from './src/screens/ChatScreen';
|
||||
import SettingsScreen from './src/screens/SettingsScreen';
|
||||
import rvs from './src/services/rvs';
|
||||
import { initLogger } from './src/services/logger';
|
||||
import { initLogger, installGlobalCrashReporter } from './src/services/logger';
|
||||
|
||||
// --- Navigation ---
|
||||
|
||||
@@ -49,6 +49,9 @@ const App: React.FC = () => {
|
||||
// initLogger ist async aber blockt nichts — solange er noch laueft,
|
||||
// loggen wir normal (Default an), danach respektiert console.log das Setting.
|
||||
initLogger().catch(() => {});
|
||||
// Crash-Reporter installieren — ungefangene JS-Errors landen via RVS
|
||||
// bei der Bridge (sichtbar in /shared/logs/app.log + Diagnostic-API)
|
||||
installGlobalCrashReporter();
|
||||
const initConnection = async () => {
|
||||
const config = await rvs.loadConfig();
|
||||
if (config) {
|
||||
|
||||
@@ -79,8 +79,8 @@ android {
|
||||
applicationId "com.ariacockpit"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 10300
|
||||
versionName "0.1.3.0"
|
||||
versionCode 10407
|
||||
versionName "0.1.4.7"
|
||||
// Fallback fuer Libraries mit Product Flavors
|
||||
missingDimensionStrategy 'react-native-camera', 'general'
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "aria-cockpit",
|
||||
"version": "0.1.3.0",
|
||||
"version": "0.1.4.7",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"android": "react-native run-android",
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* ErrorBoundary — fängt React-Render-Fehler und zeigt eine Error-Box
|
||||
* statt White-Screen-of-Death. Plus: Crash wird zum logger geschickt,
|
||||
* der das ueber RVS an die Bridge weiterleitet.
|
||||
*
|
||||
* Einsatz: kritische Komponenten/Modals damit ein Bug nicht die ganze
|
||||
* App killt.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||
|
||||
import { reportAppError } from '../services/logger';
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
/** Optional: Bezeichnung der eingegrenzten Section fuer's Log. */
|
||||
scope?: string;
|
||||
/** Optional: Reset-Callback (z.B. Modal schliessen) — Button ist dann sichtbar. */
|
||||
onReset?: () => void;
|
||||
}
|
||||
|
||||
interface State {
|
||||
err: Error | null;
|
||||
info: string;
|
||||
}
|
||||
|
||||
export class ErrorBoundary extends React.Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = { err: null, info: '' };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(err: Error): Partial<State> {
|
||||
return { err };
|
||||
}
|
||||
|
||||
componentDidCatch(err: Error, info: any) {
|
||||
const stack = info?.componentStack || '';
|
||||
this.setState({ info: stack });
|
||||
reportAppError({
|
||||
scope: this.props.scope || 'ErrorBoundary',
|
||||
message: err?.message || String(err),
|
||||
stack: (err?.stack || '') + '\n--- componentStack ---\n' + stack,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.err) {
|
||||
return (
|
||||
<View style={s.box}>
|
||||
<Text style={s.title}>⚠️ Etwas ist schiefgegangen</Text>
|
||||
<Text style={s.scope}>{this.props.scope || 'unbekannte Komponente'}</Text>
|
||||
<ScrollView style={s.scroll}>
|
||||
<Text style={s.msg}>{this.state.err.message || String(this.state.err)}</Text>
|
||||
{this.state.info ? <Text style={s.stack}>{this.state.info}</Text> : null}
|
||||
</ScrollView>
|
||||
{this.props.onReset ? (
|
||||
<TouchableOpacity style={s.btn} onPress={() => { this.setState({err:null,info:''}); this.props.onReset?.(); }}>
|
||||
<Text style={s.btnText}>Schliessen + zurueck</Text>
|
||||
</TouchableOpacity>
|
||||
) : (
|
||||
<TouchableOpacity style={s.btn} onPress={() => this.setState({err:null,info:''})}>
|
||||
<Text style={s.btnText}>Erneut versuchen</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
<Text style={s.hint}>
|
||||
Crash wurde an die Bridge gemeldet — sichtbar in der Diagnostic-Web-UI unter /api/app-log
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
const s = StyleSheet.create({
|
||||
box: { flex:1, padding:16, backgroundColor:'#1A0A0A' },
|
||||
title: { color:'#FF6B6B', fontWeight:'bold', fontSize:16, marginBottom:6 },
|
||||
scope: { color:'#FF9500', fontSize:12, marginBottom:10 },
|
||||
scroll: { flex:1, backgroundColor:'#0D0D1A', borderRadius:6, padding:10, marginBottom:10 },
|
||||
msg: { color:'#FF6B6B', fontSize:13, marginBottom:8 },
|
||||
stack: { color:'#8888AA', fontSize:11, fontFamily:'monospace' },
|
||||
btn: { backgroundColor:'#0096FF', paddingVertical:10, borderRadius:6, alignItems:'center' },
|
||||
btnText: { color:'#fff', fontWeight:'600' },
|
||||
hint: { color:'#555570', fontSize:10, marginTop:8, textAlign:'center' },
|
||||
});
|
||||
|
||||
export default ErrorBoundary;
|
||||
@@ -0,0 +1,272 @@
|
||||
/**
|
||||
* Memory-Browser — Liste mit Suche + Filter, Tap oeffnet MemoryDetailModal.
|
||||
*
|
||||
* Eingesetzt von:
|
||||
* - SettingsScreen → Sektion "Gedächtnis" (kompletter Editor)
|
||||
* - Inbox-Modal (Notizen-Button neben Lupe) — kann aber auch Bubbles
|
||||
* aus dem Chat als zusaetzlichen Filter zeigen
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
FlatList,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
Alert,
|
||||
Modal,
|
||||
} from 'react-native';
|
||||
|
||||
import brainApi, { Memory } from '../services/brainApi';
|
||||
import MemoryDetailModal from './MemoryDetailModal';
|
||||
|
||||
const TYPE_LABELS: Record<string, string> = {
|
||||
identity: 'Identität', rule: 'Regeln', preference: 'Präferenzen',
|
||||
tool: 'Tools', skill: 'Skills', fact: 'Fakten',
|
||||
conversation: 'Konversation', reminder: 'Reminder',
|
||||
};
|
||||
const TYPE_OPTIONS = ['', 'identity', 'rule', 'preference', 'tool', 'skill', 'fact', 'conversation', 'reminder'];
|
||||
|
||||
interface Props {
|
||||
/** Wenn gesetzt: nur diese IDs anzeigen (z.B. Inbox-Modal mit Chat-Bubbles-Filter). */
|
||||
restrictToIds?: string[];
|
||||
/** Headline ueber der Liste. */
|
||||
title?: string;
|
||||
/** Style-Erweiterung fuer den Container. */
|
||||
flatStyle?: boolean;
|
||||
/** Wenn gesetzt: kein eigenes DetailModal mounten — Parent kuemmert sich. */
|
||||
onOpenMemory?: (id: string) => void;
|
||||
}
|
||||
|
||||
export const MemoryBrowser: React.FC<Props> = ({ restrictToIds, title, flatStyle, onOpenMemory }) => {
|
||||
const [items, setItems] = useState<Memory[]>([]);
|
||||
const [filtered, setFiltered] = useState<Memory[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [q, setQ] = useState('');
|
||||
const [typeFilter, setTypeFilter] = useState('');
|
||||
const [pinnedFilter, setPinnedFilter] = useState<'all' | 'pinned' | 'cold'>('all');
|
||||
const [showTypeMenu, setShowTypeMenu] = useState(false);
|
||||
const [openId, setOpenId] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(() => {
|
||||
setLoading(true); setErr(null);
|
||||
brainApi.listMemories({ limit: 500 })
|
||||
.then(setItems)
|
||||
.catch(e => setErr(String(e?.message || e)))
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
useEffect(() => { load(); }, [load]);
|
||||
|
||||
// Filter clientseitig — bei kleiner DB (<1000) easy
|
||||
useEffect(() => {
|
||||
let out = items;
|
||||
if (restrictToIds && restrictToIds.length) {
|
||||
const set = new Set(restrictToIds);
|
||||
out = out.filter(m => set.has(m.id));
|
||||
}
|
||||
if (typeFilter) out = out.filter(m => m.type === typeFilter);
|
||||
if (pinnedFilter === 'pinned') out = out.filter(m => m.pinned);
|
||||
else if (pinnedFilter === 'cold') out = out.filter(m => !m.pinned);
|
||||
if (q.trim()) {
|
||||
const needle = q.toLowerCase();
|
||||
out = out.filter(m =>
|
||||
(m.title || '').toLowerCase().includes(needle) ||
|
||||
(m.content || '').toLowerCase().includes(needle) ||
|
||||
(m.category || '').toLowerCase().includes(needle) ||
|
||||
(m.tags || []).some(t => t.toLowerCase().includes(needle))
|
||||
);
|
||||
}
|
||||
setFiltered(out);
|
||||
}, [items, q, typeFilter, pinnedFilter, restrictToIds]);
|
||||
|
||||
const [showNewMemoryDialog, setShowNewMemoryDialog] = useState(false);
|
||||
const [newMemoryTitle, setNewMemoryTitle] = useState('');
|
||||
|
||||
const onAddNew = () => {
|
||||
setNewMemoryTitle('');
|
||||
setShowNewMemoryDialog(true);
|
||||
};
|
||||
|
||||
const confirmAddNew = async () => {
|
||||
const t = newMemoryTitle.trim();
|
||||
if (!t) { setShowNewMemoryDialog(false); return; }
|
||||
setShowNewMemoryDialog(false);
|
||||
try {
|
||||
const m = await brainApi.saveMemory({
|
||||
type: 'fact', title: t,
|
||||
content: '(noch leer — bitte editieren)',
|
||||
});
|
||||
load();
|
||||
if (onOpenMemory) onOpenMemory(m.id);
|
||||
else setOpenId(m.id);
|
||||
} catch (e: any) {
|
||||
Alert.alert('Fehler', String(e?.message || e));
|
||||
}
|
||||
};
|
||||
|
||||
const renderItem = ({ item }: { item: Memory }) => {
|
||||
const attCount = (item.attachments || []).length;
|
||||
return (
|
||||
<TouchableOpacity style={s.row} onPress={() => onOpenMemory ? onOpenMemory(item.id) : setOpenId(item.id)}>
|
||||
<View style={{flex:1}}>
|
||||
<Text style={s.rowTitle} numberOfLines={1}>
|
||||
{item.pinned ? '📌 ' : ''}{item.title || '(ohne Titel)'}
|
||||
{attCount > 0 ? <Text style={s.attBadge}>{` 📎${attCount}`}</Text> : null}
|
||||
</Text>
|
||||
<Text style={s.rowMeta} numberOfLines={1}>
|
||||
{TYPE_LABELS[item.type] || item.type}
|
||||
{item.category ? ` · [${item.category}]` : ''}
|
||||
</Text>
|
||||
<Text style={s.rowPreview} numberOfLines={2}>{item.content}</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={[s.container, flatStyle && {padding:0,backgroundColor:'transparent'}]}>
|
||||
{title ? <Text style={s.heading}>{title}</Text> : null}
|
||||
|
||||
<View style={s.searchRow}>
|
||||
<TextInput
|
||||
style={s.search}
|
||||
value={q}
|
||||
onChangeText={setQ}
|
||||
placeholder="Suche in Titel, Inhalt, Tags…"
|
||||
placeholderTextColor="#555570"
|
||||
/>
|
||||
<TouchableOpacity style={s.iconBtn} onPress={load}>
|
||||
<Text style={{color:'#0096FF'}}>↻</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<View style={s.filterRow}>
|
||||
<TouchableOpacity style={s.filterBtn} onPress={() => setShowTypeMenu(true)}>
|
||||
<Text style={s.filterText}>{typeFilter ? (TYPE_LABELS[typeFilter] || typeFilter) : 'Alle Typen'} ▾</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={s.filterBtn} onPress={() => {
|
||||
setPinnedFilter(pinnedFilter === 'all' ? 'pinned' : pinnedFilter === 'pinned' ? 'cold' : 'all');
|
||||
}}>
|
||||
<Text style={s.filterText}>
|
||||
{pinnedFilter === 'pinned' ? '📌 Nur Pinned' : pinnedFilter === 'cold' ? 'Nur Cold' : 'Alle'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={[s.filterBtn,{backgroundColor:'#0096FF'}]} onPress={onAddNew}>
|
||||
<Text style={[s.filterText,{color:'#fff'}]}>+ Neu</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
{err ? <Text style={s.err}>{err}</Text> : null}
|
||||
|
||||
{loading && items.length === 0 ? (
|
||||
<ActivityIndicator color="#0096FF" style={{marginTop:20}} />
|
||||
) : (
|
||||
<FlatList
|
||||
data={filtered}
|
||||
keyExtractor={m => m.id}
|
||||
renderItem={renderItem}
|
||||
// nestedScrollEnabled: notwendig damit die FlatList auf Android
|
||||
// scrollt wenn sie in einer aeusseren ScrollView haengt (Settings-
|
||||
// Screen ist ScrollView). Ohne das frisst der aeussere ScrollView
|
||||
// alle Gesten und die innere Liste ist tot.
|
||||
nestedScrollEnabled={true}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
ListEmptyComponent={
|
||||
<Text style={{color:'#555570',textAlign:'center',padding:20,fontStyle:'italic'}}>
|
||||
{items.length === 0 ? '(keine Memories in der DB)' : '(keine Treffer für diese Filter)'}
|
||||
</Text>
|
||||
}
|
||||
contentContainerStyle={{paddingBottom:20}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Text style={s.footer}>
|
||||
{filtered.length}/{items.length} Memories
|
||||
</Text>
|
||||
|
||||
{/* Type-Filter-Auswahl */}
|
||||
<Modal visible={showTypeMenu} transparent animationType="fade" onRequestClose={() => setShowTypeMenu(false)}>
|
||||
<TouchableOpacity style={s.menuBack} activeOpacity={1} onPress={() => setShowTypeMenu(false)}>
|
||||
<View style={s.menuBox}>
|
||||
{TYPE_OPTIONS.map(t => (
|
||||
<TouchableOpacity
|
||||
key={t || 'all'}
|
||||
style={s.menuItem}
|
||||
onPress={() => { setTypeFilter(t); setShowTypeMenu(false); }}
|
||||
>
|
||||
<Text style={s.menuItemText}>
|
||||
{t ? (TYPE_LABELS[t] || t) : 'Alle Typen'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</Modal>
|
||||
|
||||
{/* Eigenes DetailModal nur wenn der Parent kein Callback uebergibt
|
||||
(vermeidet Modal-in-Modal-Stacking auf Android). */}
|
||||
{!onOpenMemory && (
|
||||
<MemoryDetailModal
|
||||
memoryId={openId}
|
||||
visible={!!openId}
|
||||
onClose={() => { setOpenId(null); load(); }}
|
||||
onDeleted={() => { setOpenId(null); load(); }}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* "Neue Memory"-Dialog (Alert.prompt ist iOS-only, daher eigenes Modal) */}
|
||||
<Modal visible={showNewMemoryDialog} transparent animationType="fade" onRequestClose={() => setShowNewMemoryDialog(false)}>
|
||||
<View style={s.menuBack}>
|
||||
<View style={[s.menuBox, {padding:16, minWidth:280}]}>
|
||||
<Text style={{color:'#FFD60A', fontWeight:'bold', fontSize:14, marginBottom:10}}>Neue Memory anlegen</Text>
|
||||
<Text style={{color:'#8888AA', fontSize:11, marginBottom:6}}>Titel:</Text>
|
||||
<TextInput
|
||||
value={newMemoryTitle}
|
||||
onChangeText={setNewMemoryTitle}
|
||||
autoFocus
|
||||
placeholder="z.B. Stefans Auto"
|
||||
placeholderTextColor="#555570"
|
||||
style={{backgroundColor:'#1E1E2E', color:'#E0E0F0', padding:8, borderRadius:4, fontSize:13, marginBottom:12}}
|
||||
/>
|
||||
<View style={{flexDirection:'row', gap:8, justifyContent:'flex-end'}}>
|
||||
<TouchableOpacity onPress={() => setShowNewMemoryDialog(false)} style={{padding:8}}>
|
||||
<Text style={{color:'#8888AA'}}>Abbrechen</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={confirmAddNew} style={{backgroundColor:'#0096FF', paddingHorizontal:14, paddingVertical:8, borderRadius:4}}>
|
||||
<Text style={{color:'#fff', fontWeight:'600'}}>Anlegen</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Modal>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const s = StyleSheet.create({
|
||||
container: { flex:1, padding:8, backgroundColor:'#0D0D1A' },
|
||||
heading: { color:'#0096FF', fontWeight:'bold', fontSize:14, marginBottom:8 },
|
||||
searchRow: { flexDirection:'row', gap:6, marginBottom:6 },
|
||||
search: { flex:1, backgroundColor:'#1E1E2E', color:'#E0E0F0', padding:8, borderRadius:6, fontSize:13 },
|
||||
iconBtn: { paddingHorizontal:12, justifyContent:'center', backgroundColor:'#1E1E2E', borderRadius:6 },
|
||||
filterRow: { flexDirection:'row', gap:6, marginBottom:8 },
|
||||
filterBtn: { backgroundColor:'#1E1E2E', paddingHorizontal:10, paddingVertical:6, borderRadius:6 },
|
||||
filterText: { color:'#E0E0F0', fontSize:12 },
|
||||
err: { color:'#FF6B6B', fontSize:12, marginVertical:6 },
|
||||
row: { backgroundColor:'#1E1E2E', padding:10, borderRadius:6, marginBottom:6 },
|
||||
rowTitle: { color:'#E0E0F0', fontWeight:'600', fontSize:13 },
|
||||
attBadge: { color:'#34C759', fontWeight:'normal', fontSize:11 },
|
||||
rowMeta: { color:'#8888AA', fontSize:11, marginTop:2 },
|
||||
rowPreview: { color:'#666680', fontSize:11, marginTop:4 },
|
||||
footer: { color:'#555570', fontSize:10, textAlign:'center', paddingVertical:6 },
|
||||
menuBack: { flex:1, backgroundColor:'rgba(0,0,0,0.7)', justifyContent:'center', alignItems:'center' },
|
||||
menuBox: { backgroundColor:'#0D0D1A', borderRadius:8, paddingVertical:4, minWidth:200 },
|
||||
menuItem: { paddingVertical:10, paddingHorizontal:14 },
|
||||
menuItemText: { color:'#E0E0F0', fontSize:13 },
|
||||
});
|
||||
|
||||
export default MemoryBrowser;
|
||||
@@ -0,0 +1,364 @@
|
||||
/**
|
||||
* Memory-Detail-Modal — Anzeige + Edit eines einzelnen Memory-Eintrags.
|
||||
*
|
||||
* Zwei Modi:
|
||||
* - read-only: zeigt alle Felder + Anhang-Vorschau (Klick auf Bild = Vollbild)
|
||||
* - edit: Form mit Save/Delete/Anhang-hochladen
|
||||
*
|
||||
* Memory-Daten werden beim Oeffnen aus dem Brain (via brainApi → RVS) frisch
|
||||
* gezogen. Optimistic Updates sind explizit nicht da — der DB-Stand ist die
|
||||
* Truth.
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Alert,
|
||||
Image,
|
||||
Modal,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Switch,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import DocumentPicker, { DocumentPickerResponse } from 'react-native-document-picker';
|
||||
import RNFS from 'react-native-fs';
|
||||
|
||||
import brainApi, { Memory, MemoryAttachment } from '../services/brainApi';
|
||||
|
||||
interface Props {
|
||||
memoryId: string | null;
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
onDeleted?: (id: string) => void;
|
||||
}
|
||||
|
||||
const TYPE_OPTIONS = [
|
||||
{ value: 'identity', label: 'identity (FEST)' },
|
||||
{ value: 'rule', label: 'rule (FEST)' },
|
||||
{ value: 'preference', label: 'preference (FEST)' },
|
||||
{ value: 'tool', label: 'tool (FEST)' },
|
||||
{ value: 'skill', label: 'skill (FEST)' },
|
||||
{ value: 'fact', label: 'fact (Cold)' },
|
||||
{ value: 'conversation', label: 'conversation (Cold)' },
|
||||
{ value: 'reminder', label: 'reminder (Cold)' },
|
||||
];
|
||||
|
||||
export const MemoryDetailModal: React.FC<Props> = ({ memoryId, visible, onClose, onDeleted }) => {
|
||||
const [memory, setMemory] = useState<Memory | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
|
||||
// Edit-Felder
|
||||
const [eTitle, setETitle] = useState('');
|
||||
const [eContent, setEContent] = useState('');
|
||||
const [eCategory, setECategory] = useState('');
|
||||
const [eTags, setETags] = useState('');
|
||||
const [ePinned, setEPinned] = useState(false);
|
||||
|
||||
// Bild-Vollbild
|
||||
const [fullscreen, setFullscreen] = useState<string | null>(null);
|
||||
|
||||
// Memory laden beim Oeffnen
|
||||
useEffect(() => {
|
||||
if (!visible || !memoryId) {
|
||||
setMemory(null); setEditing(false); setErr(null); return;
|
||||
}
|
||||
setLoading(true); setErr(null);
|
||||
brainApi.getMemory(memoryId)
|
||||
.then(m => {
|
||||
setMemory(m);
|
||||
setETitle(m.title || '');
|
||||
setEContent(m.content || '');
|
||||
setECategory(m.category || '');
|
||||
setETags((m.tags || []).join(', '));
|
||||
setEPinned(!!m.pinned);
|
||||
})
|
||||
.catch(e => setErr(String(e?.message || e)))
|
||||
.finally(() => setLoading(false));
|
||||
}, [visible, memoryId]);
|
||||
|
||||
const reload = () => {
|
||||
if (!memoryId) return;
|
||||
setLoading(true);
|
||||
brainApi.getMemory(memoryId)
|
||||
.then(m => setMemory(m))
|
||||
.catch(e => setErr(String(e?.message || e)))
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
|
||||
const onSave = async () => {
|
||||
if (!memoryId) return;
|
||||
setSaving(true); setErr(null);
|
||||
try {
|
||||
const tags = eTags.split(',').map(t => t.trim()).filter(Boolean);
|
||||
const m = await brainApi.updateMemory(memoryId, {
|
||||
title: eTitle.trim(),
|
||||
content: eContent.trim(),
|
||||
category: eCategory.trim(),
|
||||
tags,
|
||||
pinned: ePinned,
|
||||
});
|
||||
setMemory(m);
|
||||
setEditing(false);
|
||||
} catch (e: any) {
|
||||
setErr(String(e?.message || e));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const onDelete = () => {
|
||||
if (!memoryId || !memory) return;
|
||||
Alert.alert(
|
||||
'Memory loeschen?',
|
||||
`"${memory.title}"\n\nWird permanent aus der DB entfernt, inkl. aller Anhaenge.`,
|
||||
[
|
||||
{ text: 'Abbrechen', style: 'cancel' },
|
||||
{
|
||||
text: 'Loeschen',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
try {
|
||||
await brainApi.deleteMemory(memoryId);
|
||||
if (onDeleted) onDeleted(memoryId);
|
||||
onClose();
|
||||
} catch (e: any) {
|
||||
Alert.alert('Fehler', String(e?.message || e));
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
);
|
||||
};
|
||||
|
||||
const onPickAndUpload = async () => {
|
||||
if (!memoryId) return;
|
||||
try {
|
||||
const picked: DocumentPickerResponse[] = await DocumentPicker.pick({
|
||||
type: [DocumentPicker.types.images, DocumentPicker.types.pdf, DocumentPicker.types.allFiles],
|
||||
copyTo: 'cachesDirectory',
|
||||
});
|
||||
for (const f of picked) {
|
||||
setBusy(`Lade ${f.name}…`);
|
||||
// RNFS lesen → base64 → API
|
||||
const localPath = (f.fileCopyUri || f.uri).replace(/^file:\/\//, '');
|
||||
const b64 = await RNFS.readFile(localPath, 'base64');
|
||||
await brainApi.uploadAttachment(memoryId, f.name || 'datei', b64);
|
||||
}
|
||||
setBusy(null);
|
||||
reload();
|
||||
} catch (e: any) {
|
||||
setBusy(null);
|
||||
if (DocumentPicker.isCancel(e)) return;
|
||||
Alert.alert('Upload-Fehler', String(e?.message || e));
|
||||
}
|
||||
};
|
||||
|
||||
const onDeleteAttachment = (att: MemoryAttachment) => {
|
||||
if (!memoryId) return;
|
||||
Alert.alert(
|
||||
'Anhang loeschen?',
|
||||
`"${att.name}"`,
|
||||
[
|
||||
{ text: 'Abbrechen', style: 'cancel' },
|
||||
{
|
||||
text: 'Loeschen',
|
||||
style: 'destructive',
|
||||
onPress: async () => {
|
||||
try {
|
||||
const m = await brainApi.deleteAttachment(memoryId, att.name);
|
||||
setMemory(m);
|
||||
} catch (e: any) {
|
||||
Alert.alert('Fehler', String(e?.message || e));
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
);
|
||||
};
|
||||
|
||||
const onTapAttachment = async (att: MemoryAttachment) => {
|
||||
if (!memoryId) return;
|
||||
if ((att.mime || '').startsWith('image/')) {
|
||||
try {
|
||||
setBusy('Lade Bild…');
|
||||
const data = await brainApi.getAttachmentBytes(memoryId, att.name);
|
||||
// Temp-File schreiben damit <Image source={uri: file://...}> es zeigen kann
|
||||
const safe = att.name.replace(/[^A-Za-z0-9._-]/g, '_');
|
||||
const localPath = `${RNFS.CachesDirectoryPath}/memory_${memoryId}_${safe}`;
|
||||
await RNFS.writeFile(localPath, data.base64, 'base64');
|
||||
setBusy(null);
|
||||
setFullscreen('file://' + localPath);
|
||||
} catch (e: any) {
|
||||
setBusy(null);
|
||||
Alert.alert('Fehler', String(e?.message || e));
|
||||
}
|
||||
} else {
|
||||
Alert.alert('Anhang', `${att.name}\n${att.mime}\n${att.size} Byte\n\nPfad: ${att.path}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal visible={visible} animationType="slide" transparent onRequestClose={onClose}>
|
||||
<View style={s.backdrop}>
|
||||
<View style={s.box}>
|
||||
<View style={s.header}>
|
||||
<Text style={s.title}>{editing ? 'Memory bearbeiten' : 'Memory-Detail'}</Text>
|
||||
<TouchableOpacity onPress={onClose} hitSlop={{top:8,bottom:8,left:8,right:8}}>
|
||||
<Text style={s.closeX}>×</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<ScrollView style={s.body} contentContainerStyle={{paddingBottom:20}}>
|
||||
{loading ? (
|
||||
<ActivityIndicator color="#0096FF" style={{marginTop:30}} />
|
||||
) : err && !memory ? (
|
||||
<Text style={s.err}>{err}</Text>
|
||||
) : memory ? (
|
||||
editing ? (
|
||||
<View>
|
||||
<Text style={s.label}>Typ</Text>
|
||||
<Text style={{color:'#888',fontSize:12,marginBottom:8}}>{memory.type} (kann hier nicht geaendert werden)</Text>
|
||||
|
||||
<Text style={s.label}>Titel</Text>
|
||||
<TextInput style={s.input} value={eTitle} onChangeText={setETitle} />
|
||||
|
||||
<Text style={s.label}>Inhalt</Text>
|
||||
<TextInput
|
||||
style={[s.input, {minHeight:120, textAlignVertical:'top'}]}
|
||||
value={eContent}
|
||||
onChangeText={setEContent}
|
||||
multiline
|
||||
/>
|
||||
|
||||
<Text style={s.label}>Kategorie</Text>
|
||||
<TextInput style={s.input} value={eCategory} onChangeText={setECategory} />
|
||||
|
||||
<Text style={s.label}>Tags (komma-getrennt)</Text>
|
||||
<TextInput style={s.input} value={eTags} onChangeText={setETags} />
|
||||
|
||||
<View style={{flexDirection:'row',alignItems:'center',marginTop:10,gap:8}}>
|
||||
<Switch value={ePinned} onValueChange={setEPinned} />
|
||||
<Text style={{color:'#E0E0F0'}}>📌 Pinned (immer im System-Prompt)</Text>
|
||||
</View>
|
||||
|
||||
{err ? <Text style={s.err}>{err}</Text> : null}
|
||||
|
||||
<View style={{flexDirection:'row',gap:8,marginTop:14}}>
|
||||
<TouchableOpacity style={[s.btn,s.btnSecondary]} onPress={() => setEditing(false)} disabled={saving}>
|
||||
<Text style={s.btnText}>Abbrechen</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={[s.btn,s.btnPrimary,{flex:1}]} onPress={onSave} disabled={saving}>
|
||||
<Text style={s.btnText}>{saving ? 'Speichere…' : 'Speichern'}</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
) : (
|
||||
<View>
|
||||
<View style={{flexDirection:'row',alignItems:'flex-start',justifyContent:'space-between'}}>
|
||||
<Text style={s.bigTitle}>{memory.pinned ? '📌 ' : ''}{memory.title}</Text>
|
||||
<TouchableOpacity onPress={() => setEditing(true)} style={s.iconBtn}>
|
||||
<Text style={s.iconBtnText}>✎</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<Text style={s.meta}>
|
||||
{memory.type}{memory.category ? ` · [${memory.category}]` : ''}
|
||||
</Text>
|
||||
{(memory.tags || []).length > 0 ? (
|
||||
<View style={s.tagsRow}>
|
||||
{memory.tags.map(t => <Text key={t} style={s.tag}>{t}</Text>)}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
<Text style={s.contentBlock}>{memory.content}</Text>
|
||||
|
||||
<Text style={s.sectionHead}>📎 Anhaenge</Text>
|
||||
{(memory.attachments || []).length === 0 ? (
|
||||
<Text style={{color:'#555570',fontStyle:'italic',fontSize:12}}>(keine)</Text>
|
||||
) : (
|
||||
(memory.attachments || []).map((a) => {
|
||||
const isImage = (a.mime || '').startsWith('image/');
|
||||
return (
|
||||
<View key={a.name} style={s.attRow}>
|
||||
<TouchableOpacity style={{flexDirection:'row',alignItems:'center',gap:8,flex:1}} onPress={() => onTapAttachment(a)}>
|
||||
<Text style={{fontSize:18}}>{isImage ? '🖼️' : '📄'}</Text>
|
||||
<View style={{flex:1}}>
|
||||
<Text style={{color:'#E0E0F0',fontSize:12}} numberOfLines={1}>{a.name}</Text>
|
||||
<Text style={{color:'#555570',fontSize:10}}>{a.mime} · {Math.round(a.size/1024)} KB</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={() => onDeleteAttachment(a)} style={s.attDelete}>
|
||||
<Text style={{color:'#FF6B6B',fontSize:12}}>🗑</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
})
|
||||
)}
|
||||
<TouchableOpacity style={[s.btn,s.btnSecondary,{marginTop:8}]} onPress={onPickAndUpload}>
|
||||
<Text style={s.btnText}>⬆ Datei anhaengen</Text>
|
||||
</TouchableOpacity>
|
||||
{busy ? <Text style={{color:'#8888AA',fontSize:11,marginTop:4}}>{busy}</Text> : null}
|
||||
|
||||
<Text style={s.timestamps}>
|
||||
angelegt: {(memory.created_at || '').slice(0,16).replace('T',' ')}{'\n'}
|
||||
geaendert: {(memory.updated_at || '').slice(0,16).replace('T',' ')}{'\n'}
|
||||
id: {memory.id}
|
||||
</Text>
|
||||
|
||||
<TouchableOpacity style={[s.btn,s.btnDanger,{marginTop:14}]} onPress={onDelete}>
|
||||
<Text style={s.btnText}>🗑 Memory komplett loeschen</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)
|
||||
) : null}
|
||||
</ScrollView>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<Modal visible={!!fullscreen} transparent onRequestClose={() => setFullscreen(null)}>
|
||||
<TouchableOpacity style={s.fsBack} onPress={() => setFullscreen(null)}>
|
||||
{fullscreen ? <Image source={{uri:fullscreen}} style={s.fsImg} resizeMode="contain" /> : null}
|
||||
</TouchableOpacity>
|
||||
</Modal>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
const s = StyleSheet.create({
|
||||
backdrop: { flex:1, backgroundColor:'rgba(0,0,0,0.75)', justifyContent:'flex-end' },
|
||||
box: { backgroundColor:'#0D0D1A', borderTopLeftRadius:12, borderTopRightRadius:12, maxHeight:'92%' },
|
||||
header: { flexDirection:'row', justifyContent:'space-between', alignItems:'center', padding:14, borderBottomColor:'#1E1E2E', borderBottomWidth:1 },
|
||||
title: { color:'#FFD60A', fontWeight:'bold', fontSize:15 },
|
||||
closeX: { color:'#8888AA', fontSize:24, paddingHorizontal:6 },
|
||||
body: { padding:14 },
|
||||
err: { color:'#FF6B6B', fontSize:12, marginTop:8 },
|
||||
label: { color:'#8888AA', fontSize:11, marginBottom:3, marginTop:8 },
|
||||
input: { backgroundColor:'#080810', borderColor:'#1E1E2E', borderWidth:1, borderRadius:4, padding:8, color:'#E0E0F0', fontSize:13 },
|
||||
bigTitle: { color:'#E0E0F0', fontWeight:'bold', fontSize:16, flex:1, marginRight:6 },
|
||||
iconBtn: { padding:6, backgroundColor:'#1E1E2E', borderRadius:6 },
|
||||
iconBtnText: { color:'#0096FF', fontSize:14 },
|
||||
meta: { color:'#8888AA', fontSize:11, marginTop:4 },
|
||||
tagsRow: { flexDirection:'row', flexWrap:'wrap', gap:4, marginTop:6 },
|
||||
tag: { backgroundColor:'#1E1E2E', color:'#8888AA', fontSize:10, paddingHorizontal:6, paddingVertical:2, borderRadius:8 },
|
||||
contentBlock: { color:'#E0E0F0', fontSize:13, marginTop:12, lineHeight:18 },
|
||||
sectionHead: { color:'#0096FF', fontSize:11, marginTop:14, marginBottom:6, textTransform:'uppercase', letterSpacing:0.5 },
|
||||
attRow: { flexDirection:'row', alignItems:'center', backgroundColor:'#080810', padding:8, borderRadius:6, marginBottom:4, gap:6 },
|
||||
attDelete: { padding:4 },
|
||||
timestamps: { color:'#555570', fontSize:10, marginTop:12, fontFamily:'monospace' },
|
||||
btn: { paddingVertical:10, paddingHorizontal:14, borderRadius:6, alignItems:'center' },
|
||||
btnPrimary: { backgroundColor:'#0096FF' },
|
||||
btnSecondary: { backgroundColor:'#1E1E2E' },
|
||||
btnDanger: { backgroundColor:'#3B1010', borderWidth:1, borderColor:'#FF6B6B' },
|
||||
btnText: { color:'#fff', fontSize:13, fontWeight:'600' },
|
||||
fsBack: { flex:1, backgroundColor:'rgba(0,0,0,0.95)', justifyContent:'center', alignItems:'center' },
|
||||
fsImg: { width:'95%', height:'85%' },
|
||||
});
|
||||
|
||||
export default MemoryDetailModal;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -52,6 +52,7 @@ import {
|
||||
} from '../services/audio';
|
||||
import audioService from '../services/audio';
|
||||
import gpsTrackingService from '../services/gpsTracking';
|
||||
import MemoryBrowser from '../components/MemoryBrowser';
|
||||
import { isVerboseLogging, setVerboseLogging } from '../services/logger';
|
||||
import {
|
||||
isWakeReadySoundEnabled,
|
||||
@@ -100,6 +101,7 @@ const SETTINGS_SECTIONS = [
|
||||
{ id: 'voice_output', icon: '🔊', label: 'Sprachausgabe', desc: 'Stimmen, Pre-Roll, Geschwindigkeit' },
|
||||
{ id: 'storage', icon: '📁', label: 'Speicher', desc: 'Anhang-Speicherort, Auto-Download' },
|
||||
{ id: 'files', icon: '📂', label: 'Dateien', desc: 'ARIA- und User-Dateien — anzeigen, löschen' },
|
||||
{ id: 'memory', icon: '🧠', label: 'Gedächtnis', desc: 'ARIA-Memories durchsuchen, anlegen, bearbeiten, löschen' },
|
||||
{ id: 'protocol', icon: '📜', label: 'Protokoll', desc: 'Privatsphaere, Backup' },
|
||||
{ id: 'about', icon: 'ℹ️', label: 'Ueber', desc: 'App-Version, Update' },
|
||||
] as const;
|
||||
@@ -866,7 +868,7 @@ const SettingsScreen: React.FC = () => {
|
||||
})()}
|
||||
</View>
|
||||
</Modal>
|
||||
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
|
||||
<ScrollView style={styles.container} contentContainerStyle={styles.content} nestedScrollEnabled={true}>
|
||||
|
||||
{currentSection === null && (
|
||||
<>
|
||||
@@ -1673,6 +1675,18 @@ const SettingsScreen: React.FC = () => {
|
||||
</View>
|
||||
</>)}
|
||||
|
||||
{/* === Gedaechtnis === */}
|
||||
{currentSection === 'memory' && (<>
|
||||
<Text style={styles.sectionTitle}>Gedächtnis</Text>
|
||||
<Text style={{color: '#8888AA', fontSize: 12, marginBottom: 8, paddingHorizontal: 4}}>
|
||||
Alle Memory-Einträge aus ARIAs Vector-DB. Tippen zum Bearbeiten — mit Anhängen, pinned-Status,
|
||||
Tags. Neue Einträge anlegen via "+ Neu".
|
||||
</Text>
|
||||
<View style={{height: 600, marginBottom: 8}}>
|
||||
<MemoryBrowser />
|
||||
</View>
|
||||
</>)}
|
||||
|
||||
{/* === Logs === */}
|
||||
{currentSection === 'protocol' && (<>
|
||||
<Text style={styles.sectionTitle}>Protokoll</Text>
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* Brain-API-Client fuer die App.
|
||||
*
|
||||
* Die App hat keinen direkten HTTP-Zugriff aufs Brain (nur via RVS). Wir
|
||||
* tunneln alle Memory-Operationen ueber den generischen brain_request /
|
||||
* brain_response RVS-Channel den die Bridge implementiert.
|
||||
*
|
||||
* Pattern: pro Call eine eindeutige requestId, Listener wartet auf passende
|
||||
* brain_response, Promise loest auf / wird abgelehnt bei status>=400.
|
||||
*/
|
||||
|
||||
import rvs from './rvs';
|
||||
|
||||
type AnyJson = any;
|
||||
|
||||
interface PendingRequest {
|
||||
resolve: (data: AnyJson) => void;
|
||||
reject: (err: Error) => void;
|
||||
timer: ReturnType<typeof setTimeout>;
|
||||
expectBinary?: boolean;
|
||||
}
|
||||
|
||||
const pending = new Map<string, PendingRequest>();
|
||||
let installed = false;
|
||||
|
||||
function _ensureListener() {
|
||||
if (installed) return;
|
||||
installed = true;
|
||||
rvs.onMessage((msg: any) => {
|
||||
if (!msg || msg.type !== 'brain_response') return;
|
||||
const p = msg.payload || {};
|
||||
const reqId: string = p.requestId || '';
|
||||
const handler = pending.get(reqId);
|
||||
if (!handler) return;
|
||||
pending.delete(reqId);
|
||||
clearTimeout(handler.timer);
|
||||
const status: number = Number(p.status || 0);
|
||||
if (status >= 200 && status < 300) {
|
||||
if (handler.expectBinary) {
|
||||
handler.resolve({ base64: p.base64 || '', contentType: p.contentType || '' });
|
||||
} else {
|
||||
handler.resolve(p.json !== undefined ? p.json : (p.text !== undefined ? p.text : null));
|
||||
}
|
||||
} else {
|
||||
const detail = (p.json && p.json.detail) || p.text || `HTTP ${status}`;
|
||||
handler.reject(new Error(`Brain ${status}: ${detail}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let _nextId = 0;
|
||||
function _newRequestId(): string {
|
||||
_nextId += 1;
|
||||
return `brain_${Date.now().toString(36)}_${_nextId}`;
|
||||
}
|
||||
|
||||
/** Mini-Query-String-Builder ohne URLSearchParams (Hermes-Polyfill kennt
|
||||
* kein URLSearchParams.set, crasht). Akzeptiert object mit string/number/
|
||||
* bool-Values; undefined/null/leere Strings werden ausgelassen. */
|
||||
function _qs(params: Record<string, unknown>): string {
|
||||
const parts: string[] = [];
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v === undefined || v === null || v === '') continue;
|
||||
parts.push(`${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`);
|
||||
}
|
||||
return parts.length ? `?${parts.join('&')}` : '';
|
||||
}
|
||||
|
||||
interface SendOpts {
|
||||
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
||||
body?: AnyJson;
|
||||
bodyBase64?: string;
|
||||
contentType?: string;
|
||||
expectBinary?: boolean;
|
||||
timeoutMs?: number;
|
||||
}
|
||||
|
||||
function _send(path: string, opts: SendOpts = {}): Promise<AnyJson> {
|
||||
_ensureListener();
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestId = _newRequestId();
|
||||
const timer = setTimeout(() => {
|
||||
if (pending.delete(requestId)) {
|
||||
reject(new Error(`Brain-Timeout fuer ${path}`));
|
||||
}
|
||||
}, opts.timeoutMs || 30000);
|
||||
pending.set(requestId, { resolve, reject, timer, expectBinary: opts.expectBinary });
|
||||
rvs.send('brain_request' as any, {
|
||||
requestId,
|
||||
method: opts.method || 'GET',
|
||||
path,
|
||||
...(opts.body !== undefined ? { body: opts.body } : {}),
|
||||
...(opts.bodyBase64 ? { bodyBase64: opts.bodyBase64 } : {}),
|
||||
...(opts.contentType ? { contentType: opts.contentType } : {}),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ── Typen ────────────────────────────────────────────────────────────
|
||||
|
||||
export interface MemoryAttachment {
|
||||
name: string;
|
||||
mime: string;
|
||||
size: number;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface Memory {
|
||||
id: string;
|
||||
type: string;
|
||||
title: string;
|
||||
content: string;
|
||||
pinned: boolean;
|
||||
category: string;
|
||||
source: string;
|
||||
tags: string[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
conversation_id?: string | null;
|
||||
score?: number | null;
|
||||
attachments?: MemoryAttachment[];
|
||||
}
|
||||
|
||||
// ── Memory CRUD ──────────────────────────────────────────────────────
|
||||
|
||||
export const brainApi = {
|
||||
/** Einzelne Memory holen (mit allen Feldern inkl. Anhaenge) */
|
||||
getMemory(id: string): Promise<Memory> {
|
||||
return _send(`/memory/get/${encodeURIComponent(id)}`);
|
||||
},
|
||||
|
||||
/** Liste aller Memories, optional nach Type gefiltert. */
|
||||
listMemories(opts: { type?: string; limit?: number } = {}): Promise<Memory[]> {
|
||||
const qs = _qs({ type: opts.type, limit: opts.limit || 500 });
|
||||
return _send(`/memory/list${qs}`);
|
||||
},
|
||||
|
||||
/** Volltext-Substring-Suche. */
|
||||
searchText(q: string, opts: { type?: string; includePinned?: boolean; k?: number } = {}): Promise<Memory[]> {
|
||||
const qs = _qs({
|
||||
q,
|
||||
type: opts.type,
|
||||
include_pinned: opts.includePinned !== false,
|
||||
k: opts.k || 50,
|
||||
});
|
||||
return _send(`/memory/search-text${qs}`);
|
||||
},
|
||||
|
||||
/** Semantische Suche (Embedder). */
|
||||
searchSemantic(q: string, opts: { type?: string; includePinned?: boolean; k?: number; threshold?: number } = {}): Promise<Memory[]> {
|
||||
const qs = _qs({
|
||||
q,
|
||||
type: opts.type,
|
||||
include_pinned: opts.includePinned !== false,
|
||||
k: opts.k || 10,
|
||||
score_threshold: opts.threshold ?? 0.30,
|
||||
});
|
||||
return _send(`/memory/search${qs}`);
|
||||
},
|
||||
|
||||
/** Memory anlegen. */
|
||||
saveMemory(body: {
|
||||
type: string;
|
||||
title: string;
|
||||
content: string;
|
||||
pinned?: boolean;
|
||||
category?: string;
|
||||
tags?: string[];
|
||||
}): Promise<Memory> {
|
||||
return _send('/memory/save', {
|
||||
method: 'POST',
|
||||
body: { source: 'app', ...body },
|
||||
});
|
||||
},
|
||||
|
||||
/** Memory aktualisieren (Patch — nur uebergebene Felder werden geaendert). */
|
||||
updateMemory(id: string, body: Partial<Pick<Memory, 'title' | 'content' | 'pinned' | 'category' | 'tags'>>): Promise<Memory> {
|
||||
return _send(`/memory/update/${encodeURIComponent(id)}`, {
|
||||
method: 'PATCH',
|
||||
body,
|
||||
});
|
||||
},
|
||||
|
||||
/** Memory loeschen. */
|
||||
deleteMemory(id: string): Promise<{ deleted: string }> {
|
||||
return _send(`/memory/delete/${encodeURIComponent(id)}`, {
|
||||
method: 'DELETE',
|
||||
timeoutMs: 15000,
|
||||
});
|
||||
},
|
||||
|
||||
// ── Anhaenge ────────────────────────────────────────────────────────
|
||||
|
||||
/** Datei als Anhang an die Memory haengen (Base64-Upload). */
|
||||
uploadAttachment(memoryId: string, name: string, base64: string): Promise<Memory> {
|
||||
return _send(`/memory/${encodeURIComponent(memoryId)}/attachments`, {
|
||||
method: 'POST',
|
||||
body: { name, data_base64: base64 },
|
||||
timeoutMs: 120000,
|
||||
});
|
||||
},
|
||||
|
||||
/** Anhang loeschen. */
|
||||
deleteAttachment(memoryId: string, filename: string): Promise<Memory> {
|
||||
return _send(
|
||||
`/memory/${encodeURIComponent(memoryId)}/attachments/${encodeURIComponent(filename)}`,
|
||||
{ method: 'DELETE' },
|
||||
);
|
||||
},
|
||||
|
||||
/** Anhang-Bytes holen (fuer Vorschau / Download). Liefert Base64. */
|
||||
getAttachmentBytes(memoryId: string, filename: string): Promise<{ base64: string; contentType: string }> {
|
||||
return _send(
|
||||
`/memory/${encodeURIComponent(memoryId)}/attachments/${encodeURIComponent(filename)}`,
|
||||
{ expectBinary: true, timeoutMs: 60000 },
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default brainApi;
|
||||
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { Platform } from 'react-native';
|
||||
import rvs from './rvs';
|
||||
|
||||
export const VERBOSE_LOGGING_KEY = 'aria_verbose_logging';
|
||||
|
||||
@@ -39,3 +41,77 @@ export function setVerboseLogging(verbose: boolean): void {
|
||||
applyState();
|
||||
AsyncStorage.setItem(VERBOSE_LOGGING_KEY, String(verbose)).catch(() => {});
|
||||
}
|
||||
|
||||
// ─── App-Crash-Reporting via RVS ────────────────────────────────────
|
||||
//
|
||||
// Wenn die App crasht — egal ob React-Render-Fehler (ErrorBoundary) oder
|
||||
// ungefangener JS-Error (ErrorUtils-Handler) — schicken wir den Crash
|
||||
// als RVS-Message vom Typ "app_log" an die Bridge. Die schreibt in
|
||||
// /shared/logs/app.log, sodass wir/Diagnostic die Crashes mitlesen
|
||||
// koennen ohne ADB.
|
||||
|
||||
interface AppErrorEvent {
|
||||
scope: string;
|
||||
message: string;
|
||||
stack?: string;
|
||||
level?: 'error' | 'warn' | 'info';
|
||||
}
|
||||
|
||||
let _reportingInstalled = false;
|
||||
|
||||
/** Schickt einen App-Fehler via RVS an die Bridge. */
|
||||
export function reportAppError(ev: AppErrorEvent): void {
|
||||
try {
|
||||
rvs.send('app_log' as any, {
|
||||
ts: Date.now(),
|
||||
platform: Platform.OS,
|
||||
level: ev.level || 'error',
|
||||
scope: ev.scope,
|
||||
message: ev.message,
|
||||
stack: (ev.stack || '').slice(0, 8000),
|
||||
});
|
||||
} catch {
|
||||
// RVS noch nicht connected — Fehler geht im console weiter.
|
||||
}
|
||||
// Plus lokal: console.error, damit Stefan's adb (wenn doch mal verfuegbar)
|
||||
// den Crash sieht.
|
||||
console.error(`[app-error scope=${ev.scope}]`, ev.message, '\n', ev.stack || '');
|
||||
}
|
||||
|
||||
/** Installiert einen globalen JS-Error-Handler der ungefangene Errors via
|
||||
* RVS an die Bridge schickt. Beim App-Start aufrufen. */
|
||||
export function installGlobalCrashReporter(): void {
|
||||
if (_reportingInstalled) return;
|
||||
_reportingInstalled = true;
|
||||
try {
|
||||
const g: any = global as any;
|
||||
const prev = g.ErrorUtils?.getGlobalHandler?.();
|
||||
g.ErrorUtils?.setGlobalHandler?.((err: any, isFatal: boolean) => {
|
||||
reportAppError({
|
||||
scope: isFatal ? 'global-fatal' : 'global-nonfatal',
|
||||
message: (err && err.message) || String(err),
|
||||
stack: err && err.stack,
|
||||
});
|
||||
// Original-Handler weiterhin aufrufen damit React-Native das System-
|
||||
// Crash-Overlay zeigt (im Dev-Build) bzw. in Production sauber stirbt.
|
||||
if (typeof prev === 'function') {
|
||||
try { prev(err, isFatal); } catch {}
|
||||
}
|
||||
});
|
||||
// unhandled Promise-Rejections — manche RN-Versionen haben das nicht
|
||||
// automatisch im ErrorUtils.
|
||||
g.HermesInternal?.enablePromiseRejectionTracker?.({
|
||||
allRejections: true,
|
||||
onUnhandled: (id: number, err: any) => {
|
||||
reportAppError({
|
||||
scope: 'promise-unhandled',
|
||||
level: 'warn',
|
||||
message: (err && err.message) || String(err),
|
||||
stack: err && err.stack,
|
||||
});
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
// ErrorUtils nicht da → nix machen
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -134,10 +134,19 @@ META_TOOLS = [
|
||||
"function": {
|
||||
"name": "trigger_watcher",
|
||||
"description": (
|
||||
"Lege einen Watcher-Trigger an — pollt alle paar Minuten eine Condition, "
|
||||
"Lege einen Watcher-Trigger an — pollt eine Condition, "
|
||||
"feuert wenn sie wahr wird (mit Throttle damit's nicht spammt). "
|
||||
"Use-Case: 'sag bescheid wenn Disk unter 5GB', 'pingt mich wenn um 8 Uhr'. "
|
||||
"Welche Variablen verfuegbar sind und ihre Bedeutung steht im System-Prompt."
|
||||
"Welche Variablen verfuegbar sind und ihre Bedeutung steht im System-Prompt.\n\n"
|
||||
"Fuer GPS-Trigger gibt es DREI Modi — waehle nach Use-Case:\n"
|
||||
"- **`near(lat, lon, r)`**: SOLANGE im Radius (mit Throttle gegen Spam). "
|
||||
"Use-Case: 'bin ich noch in der Naehe von X?'. Empfohlener throttle 300-3600s.\n"
|
||||
"- **`entered_near(lat, lon, r)`**: EINMAL beim Eintritt (Uebergang draussen→innen). "
|
||||
"Use-Case: Blitzer-Warner, Ankunfts-Erinnerung. Mit grossem r (z.B. 2000) "
|
||||
"wird's zur Vorwarnung 2 km vor dem Ziel. Empfohlener throttle: kurz (30-60s, "
|
||||
"nur gegen GPS-Jitter).\n"
|
||||
"- **`left_near(lat, lon, r)`**: EINMAL beim Verlassen (Uebergang innen→draussen). "
|
||||
"Use-Case: 'Hast du am Parkplatz X was vergessen?'. Empfohlener throttle: kurz."
|
||||
),
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
|
||||
+68
-19
@@ -27,7 +27,12 @@ import watcher as watcher_mod
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TICK_SEC = 30
|
||||
# Polling-Frequenz des Background-Loops. Vorher 30s → Auto-Vorbeifahrt
|
||||
# durch einen 300m-Radius bei >50 km/h konnte zwischen zwei Ticks komplett
|
||||
# verpasst werden. Mit 8s ist auch eine 18-Sekunden-Durchfahrt (120 km/h
|
||||
# durch 300m) garantiert mind. einmal getroffen. Der Loop ist billig
|
||||
# (paar Dateilesungen + AST-Eval), das macht Brain nicht warm.
|
||||
TICK_SEC = 8
|
||||
BRIDGE_URL = os.environ.get("BRIDGE_URL", "http://aria-bridge:8090")
|
||||
|
||||
|
||||
@@ -159,7 +164,12 @@ async def _fire(trigger: dict, agent_factory) -> None:
|
||||
|
||||
|
||||
async def _tick(agent_factory) -> None:
|
||||
"""Ein Pruefdurchlauf. Geht ueber alle Triggers, feuert was zu feuern ist."""
|
||||
"""Ein Pruefdurchlauf. Geht ueber alle Triggers, feuert was zu feuern ist.
|
||||
|
||||
near()-State-Tracking: entered_near/left_near brauchen die Information
|
||||
ob ein near()-Aufruf beim letzten Tick true war (Uebergang erkennen).
|
||||
Wir halten das pro Trigger als near_states-Dict im Manifest und
|
||||
aktualisieren es nach jedem Eval — auch wenn nicht gefeuert wird."""
|
||||
try:
|
||||
all_triggers = triggers_mod.list_triggers(active_only=True)
|
||||
except Exception as e:
|
||||
@@ -168,35 +178,74 @@ async def _tick(agent_factory) -> None:
|
||||
if not all_triggers:
|
||||
return
|
||||
now = datetime.now(timezone.utc)
|
||||
# Variablen einmal pro Tick sammeln (nicht pro Trigger — Disk-Stat ist teuer)
|
||||
try:
|
||||
vars_ = watcher_mod.collect_variables()
|
||||
except Exception as e:
|
||||
logger.warning("collect_variables: %s", e)
|
||||
vars_ = {}
|
||||
|
||||
# Watcher: last_checked_at jetzt updaten (auch wenn nicht gefeuert wird,
|
||||
# damit der Check-Interval respektiert wird)
|
||||
for t in all_triggers:
|
||||
if t.get("type") == "watcher":
|
||||
try:
|
||||
t["last_checked_at"] = _now_iso()
|
||||
triggers_mod.write(t["name"], t)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for trigger in all_triggers:
|
||||
if trigger.get("type") != "watcher":
|
||||
continue
|
||||
try:
|
||||
if _should_fire(trigger, vars_, now):
|
||||
# Variablen pro Trigger sammeln — wegen prev_near_states-Closure
|
||||
prev = trigger.get("near_states") or {}
|
||||
vars_ = watcher_mod.collect_variables(prev_near_states=prev)
|
||||
|
||||
# Condition evaluieren via _should_fire (intern ruft watcher.evaluate)
|
||||
fired = _should_fire(trigger, vars_, now)
|
||||
|
||||
# State immer updaten, egal ob gefeuert wurde — sonst greift
|
||||
# entered_near/left_near nicht
|
||||
new_states = vars_.get("_new_near_states") or {}
|
||||
trigger["near_states"] = new_states
|
||||
trigger["last_checked_at"] = _now_iso()
|
||||
try:
|
||||
triggers_mod.write(trigger["name"], trigger)
|
||||
except Exception as e:
|
||||
logger.warning("trigger.write %s: %s", trigger.get("name"), e)
|
||||
|
||||
if fired:
|
||||
# Feuern als eigener Task — wenn ARIA langsam antwortet,
|
||||
# darf der naechste Tick nicht blockieren
|
||||
asyncio.create_task(_fire(trigger, agent_factory))
|
||||
except Exception as e:
|
||||
logger.warning("Trigger-Check %s: %s", trigger.get("name"), e)
|
||||
|
||||
# Timer (one-shot) — separat ohne near-State
|
||||
timer_vars = None
|
||||
for trigger in all_triggers:
|
||||
if trigger.get("type") != "timer":
|
||||
continue
|
||||
try:
|
||||
if timer_vars is None:
|
||||
timer_vars = watcher_mod.collect_variables()
|
||||
if _should_fire(trigger, timer_vars, now):
|
||||
asyncio.create_task(_fire(trigger, agent_factory))
|
||||
except Exception as e:
|
||||
logger.warning("Timer-Check %s: %s", trigger.get("name"), e)
|
||||
|
||||
|
||||
# Module-Level-Slot fuer die agent_factory damit on-demand-Ticks (von
|
||||
# z.B. POST /triggers/check-now) Zugang haben ohne durch den ganzen
|
||||
# Lifespan-Pfad geschleust zu werden.
|
||||
_AGENT_FACTORY = None
|
||||
|
||||
|
||||
async def tick_now() -> dict:
|
||||
"""Sofortiger Trigger-Check — nicht warten auf den naechsten Loop-Tick.
|
||||
Wird genutzt wenn ein neues GPS-Update reinkommt: Bridge ruft das nach
|
||||
_persist_location, damit Watcher mit near() den frischen Wert sofort
|
||||
sehen statt bis zu TICK_SEC Sekunden zu warten."""
|
||||
if _AGENT_FACTORY is None:
|
||||
return {"ok": False, "error": "Background-Loop noch nicht gestartet"}
|
||||
try:
|
||||
await _tick(_AGENT_FACTORY)
|
||||
return {"ok": True}
|
||||
except Exception as exc:
|
||||
logger.exception("tick_now: %s", exc)
|
||||
return {"ok": False, "error": str(exc)}
|
||||
|
||||
|
||||
async def run_loop(agent_factory) -> None:
|
||||
"""Endlosschleife — wird vom main lifespan gestartet + gestoppt."""
|
||||
global _AGENT_FACTORY
|
||||
_AGENT_FACTORY = agent_factory
|
||||
logger.info("Trigger-Loop gestartet (TICK_SEC=%d)", TICK_SEC)
|
||||
while True:
|
||||
try:
|
||||
|
||||
@@ -167,6 +167,16 @@ def health():
|
||||
|
||||
# ─── Memory-Endpoints ─────────────────────────────────────────────────
|
||||
|
||||
@app.get("/memory/get/{point_id}", response_model=MemoryOut)
|
||||
def memory_get(point_id: str):
|
||||
"""Einzelner Memory mit allen Feldern (inkl. Anhaengen).
|
||||
Pfad-Prefix /memory/get/ vermeidet Konflikt mit /memory/list, /memory/save etc."""
|
||||
m = store().get(point_id)
|
||||
if not m:
|
||||
raise HTTPException(404, f"Memory {point_id} nicht gefunden")
|
||||
return MemoryOut.from_point(m)
|
||||
|
||||
|
||||
@app.get("/memory/stats")
|
||||
def memory_stats():
|
||||
s = store()
|
||||
@@ -647,6 +657,16 @@ def triggers_list(active_only: bool = False):
|
||||
return {"triggers": triggers_mod.list_triggers(active_only=active_only)}
|
||||
|
||||
|
||||
@app.post("/triggers/check-now")
|
||||
async def triggers_check_now():
|
||||
"""Sofortiger Trigger-Check, statt auf den naechsten Background-Tick
|
||||
zu warten. Wird von der Bridge nach jedem location_update gerufen
|
||||
damit GPS-Watcher (near()) den frischen Wert SOFORT sehen — bei
|
||||
Auto-Vorbeifahrt durch einen 300m-Radius hat man sonst nur ~20s
|
||||
Drinnen-Zeit, was unter TICK_SEC fallen kann."""
|
||||
return await background_mod.tick_now()
|
||||
|
||||
|
||||
@app.get("/triggers/conditions")
|
||||
def triggers_conditions():
|
||||
"""Verfuegbare Variablen + Funktionen fuer Watcher-Conditions
|
||||
|
||||
+11
-10
@@ -164,15 +164,17 @@ def build_skills_section(skills: List[dict]) -> str:
|
||||
"static-ffmpeg, beautifulsoup4, …). Falls etwas WIRKLICH nur via apt geht: "
|
||||
"Stefan fragen ob es ins Brain-Dockerfile soll.")
|
||||
lines.append("")
|
||||
lines.append("**Harte Regel — IMMER Skill anlegen wenn:** die Loesung erfordert eine "
|
||||
"pip-Library. Begruendung: Brain-Container hat keinen persistenten State "
|
||||
"ausser /data/skills/. Ohne Skill wuerde der Install bei jedem "
|
||||
"Container-Restart wiederholt.")
|
||||
lines.append("**Goldene Regel: NIE ungefragt Skills anlegen.** Selbst wenn die Aufgabe "
|
||||
"eine pip-Library braucht — erst die Aufgabe loesen (mit Bash, `pip install` "
|
||||
"im Brain ist ok, oder Workaround), und nur wenn Stefan EXPLIZIT sagt "
|
||||
"'mach daraus einen Skill' / 'leg den als Skill an' / 'dafuer einen Skill' "
|
||||
"rufst du `skill_create` auf. Begruendung: Skill-Setup (venv + pip install) "
|
||||
"blockt das Brain bis zu 12 Minuten. Ein unaufgefordert angelegter Skill "
|
||||
"macht ARIA stumm und nervt Stefan jedes Mal.")
|
||||
lines.append("")
|
||||
lines.append("**Sonst — Skill nur wenn alle vier zutreffen:**")
|
||||
lines.append("**Wenn Stefan einen Skill explizit moechte, pruef:**")
|
||||
lines.append("")
|
||||
lines.append("1. **Wiederkehrend** — die Aufgabe wird realistisch nochmal gestellt. "
|
||||
"Einmal-Faelle (\"wie spaet ist es jetzt\") kein Skill.")
|
||||
lines.append("1. **Wiederkehrend** — die Aufgabe wird realistisch nochmal gestellt.")
|
||||
lines.append("2. **Nicht-trivial** — mehrere Schritte. Ein einzelner Shell-Befehl "
|
||||
"(`date`, `hostname`, `ls`) ist KEIN Skill — das macht Bash direkt.")
|
||||
lines.append("3. **Parametrisierbar** — der Skill nimmt Eingaben (URL, Datei, Suchbegriff) "
|
||||
@@ -180,9 +182,8 @@ def build_skills_section(skills: List[dict]) -> str:
|
||||
lines.append("4. **Wiederverwendbar als ganzes** — Stefan wuerde es zukuenftig per Name "
|
||||
"ansprechen (\"mach mir den YouTube zu MP3\") statt jedes Mal zu erklaeren.")
|
||||
lines.append("")
|
||||
lines.append("Wenn nichts installiert werden muss UND nicht alle vier zutreffen: einfach "
|
||||
"die Aufgabe loesen ohne Skill anzulegen. Stefan kann jederzeit sagen "
|
||||
"'bau daraus einen Skill'.")
|
||||
lines.append("Wenn auch nur EINE der vier nicht zutrifft: hoeflich nachfragen ob er "
|
||||
"wirklich einen permanenten Skill will oder die Aufgabe einmalig reicht.")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ logger = logging.getLogger(__name__)
|
||||
RUNTIME_CONFIG_FILE = Path("/shared/config/runtime.json")
|
||||
ENV_MODEL = os.environ.get("BRAIN_MODEL", "claude-sonnet-4")
|
||||
PROXY_URL = os.environ.get("PROXY_URL", "http://proxy:3456")
|
||||
PROXY_TIMEOUT_SEC = float(os.environ.get("PROXY_TIMEOUT_SEC", "300"))
|
||||
PROXY_TIMEOUT_SEC = float(os.environ.get("PROXY_TIMEOUT_SEC", "1200"))
|
||||
|
||||
|
||||
def _read_model_from_runtime() -> str:
|
||||
|
||||
+81
-7
@@ -25,7 +25,7 @@ import shutil
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -91,6 +91,12 @@ def _cpu_load_1min() -> float:
|
||||
|
||||
_DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
|
||||
|
||||
# Maximales GPS-Alter fuer near()-Auswertung. Wenn die App laenger nicht
|
||||
# gepushed hat (z.B. Tracking aus, Mobilfunk weg, App geschlossen), gilt
|
||||
# die Position als "unbekannt" und near() liefert False — verhindert
|
||||
# Phantom-Fires basierend auf einer wochen-alten Position.
|
||||
NEAR_MAX_AGE_SEC = 5 * 60
|
||||
|
||||
|
||||
def _gps_state() -> dict[str, Any]:
|
||||
"""Letzte bekannte Position aus /shared/state/location.json.
|
||||
@@ -119,8 +125,22 @@ def _user_activity_age() -> int:
|
||||
return int(time.time() - ts)
|
||||
|
||||
|
||||
def collect_variables() -> dict[str, Any]:
|
||||
"""Liefert aktuellen Snapshot aller Built-in-Variablen + near()-Helper."""
|
||||
def _near_key(lat: float, lon: float, radius_m: float) -> str:
|
||||
"""Stabiler Schluessel pro near()-Aufruf — fuer entered_near/left_near
|
||||
State-Tracking pro Trigger pro Aufrufstelle."""
|
||||
return f"{float(lat):.6f},{float(lon):.6f},{int(float(radius_m))}"
|
||||
|
||||
|
||||
def collect_variables(prev_near_states: Optional[Dict[str, bool]] = None) -> Dict[str, Any]:
|
||||
"""Liefert aktuellen Snapshot aller Built-in-Variablen + near()-Helper.
|
||||
|
||||
prev_near_states: pro Trigger gespeicherter Zustand vom letzten Eval
|
||||
(für entered_near/left_near). Wird vom background-Loop reingegeben.
|
||||
Nach dem Eval kann man `vars_['_new_near_states']` auslesen, um den
|
||||
Update-Snapshot zurueck ins Trigger-Manifest zu schreiben."""
|
||||
if prev_near_states is None:
|
||||
prev_near_states = {}
|
||||
new_near_states: Dict[str, bool] = {}
|
||||
free_gb, free_pct = _disk_stats()
|
||||
now = datetime.now()
|
||||
gps = _gps_state()
|
||||
@@ -176,12 +196,17 @@ def collect_variables() -> dict[str, Any]:
|
||||
|
||||
# Funktion-Helper — wird vom Parser als ast.Call mit Name "near" erkannt.
|
||||
# Closure ueber die GPS-Werte, damit eval keine extra Variablen braucht.
|
||||
def _near(lat: float, lon: float, radius_m: float) -> bool:
|
||||
"""Haversine-Distanz: True wenn aktuelle Position < radius_m vom Punkt."""
|
||||
def _compute_near(lat: float, lon: float, radius_m: float) -> bool:
|
||||
"""Haversine-Distanz: True wenn aktuelle Position < radius_m vom Punkt.
|
||||
Plus Age-Schutz: GPS-Daten aelter als NEAR_MAX_AGE_SEC werden als
|
||||
veraltet betrachtet → False."""
|
||||
cur_lat = vars_.get("current_lat")
|
||||
cur_lon = vars_.get("current_lon")
|
||||
if cur_lat is None or cur_lon is None:
|
||||
return False
|
||||
age = vars_.get("location_age_sec")
|
||||
if isinstance(age, (int, float)) and age >= 0 and age > NEAR_MAX_AGE_SEC:
|
||||
return False
|
||||
try:
|
||||
R = 6371000.0
|
||||
phi1 = math.radians(float(cur_lat))
|
||||
@@ -194,7 +219,39 @@ def collect_variables() -> dict[str, Any]:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _near(lat: float, lon: float, radius_m: float) -> bool:
|
||||
"""True solange im Radius drin. Plus State-Tracking fuer
|
||||
entered_near/left_near — wir merken uns das letzte Ergebnis
|
||||
damit Uebergaenge erkannt werden koennen."""
|
||||
current = _compute_near(lat, lon, radius_m)
|
||||
new_near_states[_near_key(lat, lon, radius_m)] = current
|
||||
return current
|
||||
|
||||
def _entered_near(lat: float, lon: float, radius_m: float) -> bool:
|
||||
"""True NUR beim Uebergang draussen → innen. Use-Case: einmal
|
||||
feuern wenn der User in den Radius reinfaehrt (Blitzer-Warner,
|
||||
Ankunft-Erinnerung). Bei groesserem Radius = Vorwarnung."""
|
||||
current = _compute_near(lat, lon, radius_m)
|
||||
key = _near_key(lat, lon, radius_m)
|
||||
new_near_states[key] = current
|
||||
prev = bool(prev_near_states.get(key, False))
|
||||
return current and not prev
|
||||
|
||||
def _left_near(lat: float, lon: float, radius_m: float) -> bool:
|
||||
"""True NUR beim Uebergang innen → draussen. Use-Case: 'Hast
|
||||
du am Parkplatz X was vergessen?' beim Verlassen."""
|
||||
current = _compute_near(lat, lon, radius_m)
|
||||
key = _near_key(lat, lon, radius_m)
|
||||
new_near_states[key] = current
|
||||
prev = bool(prev_near_states.get(key, False))
|
||||
return prev and not current
|
||||
|
||||
vars_["near"] = _near
|
||||
vars_["entered_near"] = _entered_near
|
||||
vars_["left_near"] = _left_near
|
||||
# Update-Snapshot fuer den Caller (background-Loop schreibt das pro
|
||||
# Trigger zurueck damit beim naechsten Tick prev_near_states stimmt)
|
||||
vars_["_new_near_states"] = new_near_states
|
||||
return vars_
|
||||
|
||||
|
||||
@@ -236,8 +293,25 @@ def describe_functions() -> list[dict]:
|
||||
{
|
||||
"name": "near",
|
||||
"signature": "near(lat, lon, radius_m)",
|
||||
"desc": "True wenn die aktuelle GPS-Position innerhalb von radius_m Metern "
|
||||
"vom Punkt (lat, lon) liegt. Haversine. Bei unbekannter Position: False.",
|
||||
"desc": "True SOLANGE die aktuelle GPS-Position innerhalb von radius_m "
|
||||
"Metern vom Punkt (lat, lon) liegt. Feuert wiederholt (mit throttle). "
|
||||
"Use-Case: 'bin noch in der Naehe von X?'. "
|
||||
"Haversine. Bei unbekannter oder > 5min alter Position: False.",
|
||||
},
|
||||
{
|
||||
"name": "entered_near",
|
||||
"signature": "entered_near(lat, lon, radius_m)",
|
||||
"desc": "True NUR im Moment des Eintritts in den Radius (Uebergang "
|
||||
"draussen → innen). Use-Case: einmaliger Fire bei Ankunft / "
|
||||
"Blitzer-Warnung. Mit grossem Radius (z.B. 2000) wird das zur "
|
||||
"Vorwarnung bevor man am Punkt ist.",
|
||||
},
|
||||
{
|
||||
"name": "left_near",
|
||||
"signature": "left_near(lat, lon, radius_m)",
|
||||
"desc": "True NUR im Moment des Verlassens des Radius (Uebergang "
|
||||
"innen → draussen). Use-Case: 'Hast du am Parkplatz X was "
|
||||
"vergessen?' beim Wegfahren.",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
+228
-15
@@ -25,6 +25,7 @@ import time
|
||||
import sys
|
||||
import tempfile
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
@@ -475,6 +476,13 @@ class ARIABridge:
|
||||
self.current_mode = self._load_persisted_mode()
|
||||
self.running = False
|
||||
|
||||
# Idempotenz: zuletzt gesehene clientMsgIds (App-seitig generiert).
|
||||
# Beim Reconnect/Retry sendet die App dieselbe ID nochmal — wir
|
||||
# antworten erneut mit ACK aber leiten NICHT doppelt an Brain weiter.
|
||||
# OrderedDict als FIFO mit Capping (Insertion-Order).
|
||||
self._seen_client_msg_ids: "OrderedDict[str, float]" = OrderedDict()
|
||||
self._SEEN_CLIENT_MSG_LIMIT = 200
|
||||
|
||||
# Komponenten (TTS: F5-TTS remote auf der Gamebox, lokales TTS wurde entfernt)
|
||||
self.tts_enabled = True
|
||||
self.xtts_voice = ""
|
||||
@@ -938,7 +946,12 @@ class ARIABridge:
|
||||
def _persist_location(self, location: Optional[dict]) -> None:
|
||||
"""Speichert die letzte bekannte GPS-Position fuer Watcher.
|
||||
Erwartet {lat, lon} oder {lat, lng}. Nicht-Dicts und fehlende
|
||||
Koordinaten werden ignoriert."""
|
||||
Koordinaten werden ignoriert.
|
||||
|
||||
Plus: triggert sofort einen on-demand Trigger-Check im Brain
|
||||
(POST /triggers/check-now). Ohne das wartet der Watcher-Loop
|
||||
bis zu TICK_SEC Sekunden — bei Auto-Vorbeifahrt durch einen
|
||||
300m-Radius (18-43s drin) kann das den Trigger verpassen."""
|
||||
if not isinstance(location, dict):
|
||||
return
|
||||
try:
|
||||
@@ -950,9 +963,31 @@ class ARIABridge:
|
||||
"lat": float(lat),
|
||||
"lon": float(lon),
|
||||
})
|
||||
except Exception:
|
||||
return
|
||||
# Fire-and-forget: Brain-on-demand-Tick. Wenn Brain nicht antwortet
|
||||
# oder langsam ist, blockt das nicht den GPS-Pfad.
|
||||
try:
|
||||
asyncio.create_task(self._trigger_brain_check_now())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def _trigger_brain_check_now(self) -> None:
|
||||
"""Brain-Endpoint POST /triggers/check-now anstossen."""
|
||||
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
||||
def _post():
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
f"{brain_url}/triggers/check-now",
|
||||
data=b"", method="POST",
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=8) as r:
|
||||
return r.status
|
||||
except Exception:
|
||||
return None
|
||||
await asyncio.get_event_loop().run_in_executor(None, _post)
|
||||
|
||||
def _persist_user_activity(self) -> None:
|
||||
"""Markiert dass der User gerade etwas gemacht hat (Chat/Voice).
|
||||
Watcher: last_user_message_ago_sec basiert darauf."""
|
||||
@@ -1281,10 +1316,12 @@ class ARIABridge:
|
||||
self._pending_files_flush_task = None
|
||||
text = self._build_pending_files_message(user_text)
|
||||
self._pending_files = []
|
||||
await self.send_to_core(text, source="app-file+chat")
|
||||
# create_task statt await — sonst blockt der RVS-recv-Loop bis Brain
|
||||
# fertig ist (siehe chat-handler oben).
|
||||
asyncio.create_task(self.send_to_core(text, source="app-file+chat"))
|
||||
return True
|
||||
|
||||
async def send_to_core(self, text: str, source: str = "bridge") -> None:
|
||||
async def send_to_core(self, text: str, source: str = "bridge", client_msg_id: Optional[str] = None) -> None:
|
||||
"""Sendet Text an aria-brain (HTTP /chat) und broadcastet die Antwort.
|
||||
|
||||
Nicht-Streaming: wir warten bis Brain fertig ist, dann pushen wir
|
||||
@@ -1298,8 +1335,13 @@ class ARIABridge:
|
||||
logger.info("[brain] chat ← %s '%s'", source, text[:80])
|
||||
|
||||
# User-Nachricht in chat_backup.jsonl loggen — wird beim App-Reconnect
|
||||
# / Diagnostic-Reload als History-Quelle gelesen.
|
||||
self._append_chat_backup({"role": "user", "text": text, "source": source})
|
||||
# / Diagnostic-Reload als History-Quelle gelesen. clientMsgId speichern
|
||||
# damit die App beim chat_history_response ihre lokale Bubble
|
||||
# dedupen kann (sonst verschwindet sie nach Offline→Online-Race).
|
||||
entry: dict = {"role": "user", "text": text, "source": source}
|
||||
if client_msg_id:
|
||||
entry["clientMsgId"] = client_msg_id
|
||||
self._append_chat_backup(entry)
|
||||
|
||||
# agent_activity → thinking. _emit_activity statt direktem _send_to_rvs
|
||||
# damit der State-Cache fuer die spaetere idle-Dedup richtig steht.
|
||||
@@ -1311,8 +1353,10 @@ class ARIABridge:
|
||||
url, data=payload, method="POST",
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
# Cold-Start kann lange dauern, 5min Timeout
|
||||
with urllib.request.urlopen(req, timeout=300) as resp:
|
||||
# 20 Min Timeout — lange Multi-Tool-Workflows (Karten,
|
||||
# PDFs, viele curl-Calls) brauchen das. 5 Min waren chronisch
|
||||
# zu knapp und haben ARIA mitten in der Arbeit gekappt.
|
||||
with urllib.request.urlopen(req, timeout=1200) as resp:
|
||||
return resp.status, resp.read().decode("utf-8", errors="ignore")
|
||||
except Exception as exc:
|
||||
return None, str(exc)
|
||||
@@ -1503,6 +1547,36 @@ class ARIABridge:
|
||||
except Exception:
|
||||
break
|
||||
|
||||
async def _send_chat_ack(self, client_msg_id: Optional[str]) -> None:
|
||||
"""Bestaetigt der App den Empfang einer chat/audio-Nachricht.
|
||||
App nutzt das fuer Delivery-Status (✓ = sent). Ohne ACK wuerde die
|
||||
App nach Timeout retryen — gegen Verlust bei Netz-Hicksern.
|
||||
"""
|
||||
if not client_msg_id:
|
||||
return
|
||||
await self._send_to_rvs({
|
||||
"type": "chat_ack",
|
||||
"payload": {"clientMsgId": client_msg_id},
|
||||
"timestamp": int(asyncio.get_event_loop().time() * 1000),
|
||||
})
|
||||
|
||||
def _is_duplicate_client_msg(self, client_msg_id: Optional[str]) -> bool:
|
||||
"""Prueft ob wir diese clientMsgId schon verarbeitet haben.
|
||||
Wenn ja → True (Caller soll ACK senden aber NICHT an Brain forwarden).
|
||||
Wenn nein → in den Seen-Cache aufnehmen + False zurueck.
|
||||
"""
|
||||
if not client_msg_id:
|
||||
return False
|
||||
if client_msg_id in self._seen_client_msg_ids:
|
||||
logger.info("[rvs] Idempotenz: cmid=%s bereits verarbeitet, ignoriere",
|
||||
client_msg_id)
|
||||
return True
|
||||
self._seen_client_msg_ids[client_msg_id] = time.time()
|
||||
# Capping: aelteste Eintraege rauswerfen
|
||||
while len(self._seen_client_msg_ids) > self._SEEN_CLIENT_MSG_LIMIT:
|
||||
self._seen_client_msg_ids.popitem(last=False)
|
||||
return False
|
||||
|
||||
async def _handle_rvs_message(self, raw_message: str) -> None:
|
||||
"""Verarbeitet Nachrichten von der App (via RVS).
|
||||
|
||||
@@ -1527,6 +1601,13 @@ class ARIABridge:
|
||||
sender = payload.get("sender", "")
|
||||
if sender in ("aria", "stt"):
|
||||
return
|
||||
# Delivery-ACK: immer zurueckschicken (auch bei Idempotenz-Hit),
|
||||
# damit die App den Status auf 'sent' setzen kann. Idempotenz-
|
||||
# Check VERHINDERT aber die Doppel-Weiterleitung an Brain.
|
||||
client_msg_id = payload.get("clientMsgId") or None
|
||||
await self._send_chat_ack(client_msg_id)
|
||||
if self._is_duplicate_client_msg(client_msg_id):
|
||||
return
|
||||
text = payload.get("text", "")
|
||||
# Voice-Override fuer Folgenachrichten setzen — gilt bis zum naechsten
|
||||
# chat-Event. Leerer String "" = explizit Default-Voice (override loeschen).
|
||||
@@ -1562,7 +1643,16 @@ class ARIABridge:
|
||||
" [BARGE-IN]" if interrupted else "",
|
||||
" [GPS]" if location else "",
|
||||
text[:80])
|
||||
await self.send_to_core(core_text, source="app" + (" [barge-in]" if interrupted else ""))
|
||||
# KEIN await: send_to_core kann 20 Min dauern. Wenn wir
|
||||
# hier awaiten, blockt der `async for raw_message in ws`-
|
||||
# Loop solange → RVS-Server droppt uns nach ~4 Min idle.
|
||||
# Als Task: Brain laeuft im Hintergrund, RVS-recv bleibt
|
||||
# bedienbar, Pings werden beantwortet, Verbindung lebt.
|
||||
asyncio.create_task(self.send_to_core(
|
||||
core_text,
|
||||
source="app" + (" [barge-in]" if interrupted else ""),
|
||||
client_msg_id=client_msg_id,
|
||||
))
|
||||
return
|
||||
|
||||
if msg_type == "cancel_request":
|
||||
@@ -1738,7 +1828,8 @@ class ARIABridge:
|
||||
|
||||
if not file_b64:
|
||||
text = f"Stefan hat eine Datei gesendet ({file_name}, {file_type}) aber die Daten sind leer angekommen."
|
||||
await self.send_to_core(text, source="app-file")
|
||||
# create_task statt await — RVS-recv darf nicht blocken
|
||||
asyncio.create_task(self.send_to_core(text, source="app-file"))
|
||||
return
|
||||
|
||||
if file_type.startswith("image/"):
|
||||
@@ -1824,6 +1915,95 @@ class ARIABridge:
|
||||
logger.warning("[rvs] delete_message fehlgeschlagen: %s", result.get("error"))
|
||||
return
|
||||
|
||||
elif msg_type == "app_log":
|
||||
# App schickt Crash/Error/Info-Log via RVS — wir schreiben das
|
||||
# in /shared/logs/app.log (JSONL) damit Diagnostic + Claude
|
||||
# mitlesen koennen, auch ohne ADB-Zugriff aufs Handy.
|
||||
try:
|
||||
log_dir = Path("/shared/logs")
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
line = {
|
||||
"ts": payload.get("ts") or int(time.time() * 1000),
|
||||
"platform": payload.get("platform", "?"),
|
||||
"level": payload.get("level", "info"),
|
||||
"scope": payload.get("scope", ""),
|
||||
"message": payload.get("message", ""),
|
||||
"stack": payload.get("stack", ""),
|
||||
}
|
||||
with (log_dir / "app.log").open("a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(line, ensure_ascii=False) + "\n")
|
||||
logger.info("[app-log] %s %s: %s",
|
||||
line["level"], line["scope"], line["message"][:120])
|
||||
except Exception as exc:
|
||||
logger.warning("[app-log] schreiben fehlgeschlagen: %s", exc)
|
||||
return
|
||||
|
||||
elif msg_type == "brain_request":
|
||||
# Generischer RVS-Proxy fuer die Brain-HTTP-API.
|
||||
# payload: {requestId, method, path, body?, bodyBase64?, contentType?}
|
||||
# - method: GET | POST | PATCH | DELETE
|
||||
# - path: z.B. "/memory/list" oder "/memory/get/<id>"
|
||||
# - body: JSON-Objekt (wird als JSON encoded)
|
||||
# - bodyBase64: rohe Bytes als Base64 (fuer Upload mit contentType)
|
||||
# - contentType: default application/json
|
||||
# Antwort als brain_response {requestId, status, json?, base64?}.
|
||||
req_id = payload.get("requestId") or ""
|
||||
method = (payload.get("method") or "GET").upper()
|
||||
path = payload.get("path") or ""
|
||||
if not req_id or not path or not path.startswith("/"):
|
||||
logger.warning("[rvs] brain_request ungueltig: %r", payload)
|
||||
return
|
||||
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
||||
url = brain_url.rstrip("/") + path
|
||||
headers: dict[str, str] = {}
|
||||
data: Optional[bytes] = None
|
||||
ct = payload.get("contentType") or "application/json"
|
||||
if payload.get("bodyBase64"):
|
||||
try:
|
||||
data = base64.b64decode(payload["bodyBase64"])
|
||||
except Exception:
|
||||
data = None
|
||||
if data is not None:
|
||||
headers["Content-Type"] = ct
|
||||
elif payload.get("body") is not None:
|
||||
data = json.dumps(payload["body"]).encode("utf-8")
|
||||
headers["Content-Type"] = "application/json"
|
||||
logger.info("[rvs] brain_request %s %s (%d Byte)", method, path, len(data or b""))
|
||||
|
||||
def _do_call():
|
||||
try:
|
||||
req = urllib.request.Request(url, data=data, method=method, headers=headers)
|
||||
with urllib.request.urlopen(req, timeout=120) as r:
|
||||
return r.status, r.read(), r.headers.get("Content-Type", "")
|
||||
except urllib.error.HTTPError as e:
|
||||
try:
|
||||
body = e.read()
|
||||
except Exception:
|
||||
body = b""
|
||||
return e.code, body, e.headers.get("Content-Type", "") if e.headers else ""
|
||||
except Exception as exc:
|
||||
return None, str(exc).encode("utf-8"), "text/plain"
|
||||
|
||||
status, body_bytes, response_ct = await asyncio.get_event_loop().run_in_executor(None, _do_call)
|
||||
out: dict = {"requestId": req_id, "status": status or 0}
|
||||
if response_ct and "json" in response_ct:
|
||||
try:
|
||||
out["json"] = json.loads(body_bytes.decode("utf-8", errors="ignore"))
|
||||
except Exception:
|
||||
out["text"] = body_bytes.decode("utf-8", errors="ignore")[:2000]
|
||||
elif response_ct and "text" in response_ct:
|
||||
out["text"] = body_bytes.decode("utf-8", errors="ignore")[:4000]
|
||||
else:
|
||||
# Binaer (z.B. attachment-download) → base64 zurueck
|
||||
out["base64"] = base64.b64encode(body_bytes).decode("ascii")
|
||||
out["contentType"] = response_ct or "application/octet-stream"
|
||||
await self._send_to_rvs({
|
||||
"type": "brain_response",
|
||||
"payload": out,
|
||||
"timestamp": int(asyncio.get_event_loop().time() * 1000),
|
||||
})
|
||||
return
|
||||
|
||||
elif msg_type == "file_list_request":
|
||||
# App fragt die Liste aller /shared/uploads/-Dateien an.
|
||||
logger.info("[rvs] file_list_request von App")
|
||||
@@ -2037,6 +2217,12 @@ class ARIABridge:
|
||||
|
||||
elif msg_type == "audio":
|
||||
# Audio von der App → decodieren → STT → an aria-core
|
||||
# Delivery-ACK + Idempotenz wie bei chat — App nutzt die ACKs
|
||||
# auch fuer Sprach-Bubbles (Status auf der Bubble: ✓ sent).
|
||||
client_msg_id = payload.get("clientMsgId") or None
|
||||
await self._send_chat_ack(client_msg_id)
|
||||
if self._is_duplicate_client_msg(client_msg_id):
|
||||
return
|
||||
audio_b64 = payload.get("base64", "")
|
||||
mime_type = payload.get("mimeType", "audio/mp4")
|
||||
duration_ms = payload.get("durationMs", 0)
|
||||
@@ -2067,7 +2253,8 @@ class ARIABridge:
|
||||
" [GPS]" if location else "",
|
||||
f" reqId={audio_request_id[:16]}" if audio_request_id else "")
|
||||
asyncio.create_task(self._process_app_audio(
|
||||
audio_b64, mime_type, interrupted, audio_request_id, location))
|
||||
audio_b64, mime_type, interrupted, audio_request_id, location,
|
||||
client_msg_id=client_msg_id))
|
||||
|
||||
elif msg_type == "stt_response":
|
||||
# Antwort der whisper-bridge auf unseren stt_request
|
||||
@@ -2126,7 +2313,8 @@ class ARIABridge:
|
||||
async def _process_app_audio(self, audio_b64: str, mime_type: str,
|
||||
interrupted: bool = False,
|
||||
audio_request_id: str = "",
|
||||
location: Optional[dict] = None) -> None:
|
||||
location: Optional[dict] = None,
|
||||
client_msg_id: Optional[str] = None) -> None:
|
||||
"""App-Audio → STT → aria-core. Primaer via whisper-bridge (RVS), Fallback lokal.
|
||||
|
||||
interrupted=True wenn der User waehrend ARIA noch sprach/dachte aufgenommen hat
|
||||
@@ -2182,7 +2370,9 @@ class ARIABridge:
|
||||
|
||||
# Dann an Brain — der blockt synchron bis ARIA fertig ist.
|
||||
core_text = self._build_core_text(text, interrupted, location)
|
||||
await self.send_to_core(core_text, source="app-voice" + (" [barge-in]" if interrupted else ""))
|
||||
await self.send_to_core(core_text,
|
||||
source="app-voice" + (" [barge-in]" if interrupted else ""),
|
||||
client_msg_id=client_msg_id)
|
||||
else:
|
||||
logger.info("[rvs] Keine Sprache erkannt — ignoriert")
|
||||
|
||||
@@ -2329,17 +2519,22 @@ class ARIABridge:
|
||||
status = await asyncio.get_event_loop().run_in_executor(None, _do_request)
|
||||
logger.info("[cancel] Diagnostic /api/cancel: %s", status)
|
||||
|
||||
async def _emit_activity(self, activity: str, tool: str = "") -> None:
|
||||
async def _emit_activity(self, activity: str, tool: str = "", force: bool = False) -> None:
|
||||
"""Sendet agent_activity an die App — nur wenn sich der State geaendert hat.
|
||||
|
||||
Trailing Agent-Events nach chat:final werden 3s lang unterdrueckt
|
||||
(nur 'idle' kommt immer durch)."""
|
||||
(nur 'idle' kommt immer durch).
|
||||
|
||||
force=True: kein State-Dedup — wird vom Proxy-Tool-Hook genutzt
|
||||
damit auch wiederholte gleiche Tool-Aufrufe (z.B. 3x Bash
|
||||
hintereinander) im Gedanken-Stream als eigene Eintraege sichtbar
|
||||
bleiben."""
|
||||
if activity != "idle" and self._last_chat_final_at > 0:
|
||||
since_final = asyncio.get_event_loop().time() - self._last_chat_final_at
|
||||
if since_final < 3.0:
|
||||
return
|
||||
state = (activity, tool)
|
||||
if state == self._last_activity_state:
|
||||
if not force and state == self._last_activity_state:
|
||||
return
|
||||
self._last_activity_state = state
|
||||
await self._send_to_rvs({
|
||||
@@ -2487,6 +2682,24 @@ class ARIABridge:
|
||||
self._handle_trigger_fired(reply, trigger_name, ttype, events)
|
||||
)
|
||||
await _send_response(writer, 200, {"ok": True})
|
||||
elif method == "POST" and path == "/internal/agent-activity":
|
||||
# Vom Proxy gefeuert bei jedem Claude-Code-tool_use-Event
|
||||
# (Bash, Read, Edit, Grep, ...). Wir spiegeln das als
|
||||
# RVS agent_activity an App+Diagnostic damit der Gedanken-
|
||||
# Stream live mitlaufen kann.
|
||||
try:
|
||||
data = json.loads(body.decode("utf-8", "ignore"))
|
||||
except Exception as exc:
|
||||
await _send_response(writer, 400, {"error": f"bad json: {exc}"})
|
||||
return
|
||||
tool = (data.get("tool") or "").strip()
|
||||
if not tool:
|
||||
await _send_response(writer, 400, {"error": "tool erforderlich"})
|
||||
return
|
||||
# Force-emit (kein Dedup): User soll JEDEN Tool-Call sehen
|
||||
# selbst wenn derselbe Name zweimal in Folge kommt.
|
||||
asyncio.create_task(self._emit_activity("tool", tool, force=True))
|
||||
await _send_response(writer, 200, {"ok": True})
|
||||
elif method == "POST" and path == "/internal/delete-chat-message":
|
||||
try:
|
||||
data = json.loads(body.decode("utf-8", "ignore"))
|
||||
|
||||
@@ -301,6 +301,7 @@
|
||||
<input type="checkbox" id="gps-debug-toggle" onchange="toggleGpsDebug()" style="margin-right:4px;vertical-align:middle;">
|
||||
GPS-Position einblenden
|
||||
</label>
|
||||
<button class="btn secondary" onclick="openThoughtStream()" id="btn-thoughts" title="Gedanken-Stream — was ARIA intern tut" style="padding:4px 10px;font-size:11px;">💭 Gedanken <span id="thoughts-count" style="color:#8888AA;"></span></button>
|
||||
<button class="btn secondary" onclick="toggleChatFullscreen()" id="btn-chat-fs" style="padding:4px 10px;font-size:11px;">Vollbild</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -342,6 +343,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Gedanken-Stream Modal — chronologisches Log was ARIA intern tut.
|
||||
Zentrales Modal (max 720px breit), Liste mit Auto-Scroll ans Ende
|
||||
wenn neue Eintraege reinkommen. -->
|
||||
<div id="thought-stream-modal" style="display:none;position:fixed;top:0;left:0;width:100vw;height:100vh;background:rgba(0,0,0,0.7);z-index:1100;align-items:center;justify-content:center;padding:24px;" onclick="if(event.target===this) closeThoughtStream();">
|
||||
<div style="background:#0D0D1A;border:1px solid #1E1E2E;border-radius:12px;width:100%;max-width:720px;height:70vh;display:flex;flex-direction:column;">
|
||||
<div style="display:flex;align-items:center;padding:14px;border-bottom:1px solid #1E1E2E;">
|
||||
<h2 style="margin:0;color:#FFD60A;flex:1;font-size:16px;">💭 Gedanken-Stream <span id="thoughts-count-modal" style="color:#8888AA;font-weight:normal;"></span></h2>
|
||||
<button class="btn secondary" onclick="clearThoughtStream()" id="btn-clear-thoughts" title="Stream leeren" style="padding:4px 10px;font-size:11px;color:#FF3B30;border-color:#FF3B30;margin-right:6px;">🗑 Leeren</button>
|
||||
<button class="btn secondary" onclick="closeThoughtStream()" style="padding:4px 12px;">Schliessen</button>
|
||||
</div>
|
||||
<div id="thought-stream-list" style="flex:1;overflow-y:auto;padding:8px 0;font-size:13px;font-family:monospace;">
|
||||
<!-- gefuellt durch renderThoughtStream() -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sessions + alter Brain-Viewer entfernt — Memories laufen jetzt
|
||||
komplett ueber den Gehirn-Tab gegen die Vector-DB im aria-brain. -->
|
||||
|
||||
@@ -2166,6 +2183,9 @@
|
||||
}
|
||||
|
||||
function updateThinkingIndicator(msg) {
|
||||
// Gedanken-Stream fuettern — JEDES Event (auch idle als ✓ fertig)
|
||||
pushThought(msg.activity || '', msg.tool || '');
|
||||
|
||||
const indicators = [
|
||||
document.getElementById('thinking-indicator'),
|
||||
document.getElementById('thinking-indicator-fs'),
|
||||
@@ -2202,6 +2222,114 @@
|
||||
}, 120000);
|
||||
}
|
||||
|
||||
// ── Gedanken-Stream ─────────────────────────────
|
||||
// Chronologisches Log von agent_activity-Events. Wird in localStorage
|
||||
// persistiert (ueberlebt Page-Reload), capped auf MAX_THOUGHTS.
|
||||
const THOUGHT_STORAGE_KEY = 'aria_thought_stream';
|
||||
const MAX_THOUGHTS = 500;
|
||||
let thoughtStream = [];
|
||||
let lastThoughtKey = '';
|
||||
let _thoughtSaveTimer = null;
|
||||
|
||||
function loadThoughtStream() {
|
||||
try {
|
||||
const raw = localStorage.getItem(THOUGHT_STORAGE_KEY);
|
||||
if (!raw) return;
|
||||
const parsed = JSON.parse(raw);
|
||||
if (Array.isArray(parsed)) thoughtStream = parsed.slice(-MAX_THOUGHTS);
|
||||
} catch {}
|
||||
updateThoughtsBadge();
|
||||
}
|
||||
|
||||
function persistThoughtStream() {
|
||||
if (_thoughtSaveTimer) clearTimeout(_thoughtSaveTimer);
|
||||
_thoughtSaveTimer = setTimeout(() => {
|
||||
try {
|
||||
if (thoughtStream.length === 0) localStorage.removeItem(THOUGHT_STORAGE_KEY);
|
||||
else localStorage.setItem(THOUGHT_STORAGE_KEY, JSON.stringify(thoughtStream.slice(-MAX_THOUGHTS)));
|
||||
} catch {}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function pushThought(activity, tool) {
|
||||
// Dedup gegen direkt aufeinanderfolgende identische Events. Tool-
|
||||
// Events NIE dedupen — drei Bash-Calls in Folge sollen drei Eintraege
|
||||
// ergeben, nicht einen.
|
||||
const key = `${activity}|${tool || ''}`;
|
||||
if (activity !== 'tool' && key === lastThoughtKey) return;
|
||||
lastThoughtKey = key;
|
||||
thoughtStream.push({ ts: Date.now(), activity, tool: tool || '' });
|
||||
if (thoughtStream.length > MAX_THOUGHTS) thoughtStream = thoughtStream.slice(-MAX_THOUGHTS);
|
||||
updateThoughtsBadge();
|
||||
// Wenn das Modal offen ist: live nachrendern + ans Ende scrollen
|
||||
const modal = document.getElementById('thought-stream-modal');
|
||||
if (modal && modal.style.display !== 'none') renderThoughtStream(true);
|
||||
persistThoughtStream();
|
||||
}
|
||||
|
||||
function updateThoughtsBadge() {
|
||||
const a = document.getElementById('thoughts-count');
|
||||
if (a) a.textContent = thoughtStream.length ? `(${thoughtStream.length})` : '';
|
||||
const b = document.getElementById('thoughts-count-modal');
|
||||
if (b) b.textContent = thoughtStream.length ? `(${thoughtStream.length})` : '';
|
||||
}
|
||||
|
||||
function openThoughtStream() {
|
||||
const modal = document.getElementById('thought-stream-modal');
|
||||
if (!modal) return;
|
||||
modal.style.display = 'flex';
|
||||
renderThoughtStream(true);
|
||||
}
|
||||
|
||||
function closeThoughtStream() {
|
||||
const modal = document.getElementById('thought-stream-modal');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
function clearThoughtStream() {
|
||||
if (thoughtStream.length === 0) return;
|
||||
if (!confirm(`Gedanken-Stream leeren? ${thoughtStream.length} Eintraege werden geloescht.`)) return;
|
||||
thoughtStream = [];
|
||||
lastThoughtKey = '';
|
||||
updateThoughtsBadge();
|
||||
renderThoughtStream(false);
|
||||
persistThoughtStream();
|
||||
}
|
||||
|
||||
function _escapeHtml(s) {
|
||||
return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
}
|
||||
|
||||
function renderThoughtStream(autoscroll) {
|
||||
const list = document.getElementById('thought-stream-list');
|
||||
if (!list) return;
|
||||
if (thoughtStream.length === 0) {
|
||||
list.innerHTML = '<div style="padding:24px;text-align:center;color:#555570;font-style:italic;">Noch keine Gedanken aufgezeichnet.<br>Sobald ARIA was tut, taucht\'s hier auf.</div>';
|
||||
return;
|
||||
}
|
||||
const rows = [];
|
||||
let prevTs = 0;
|
||||
for (const t of thoughtStream) {
|
||||
const gapMin = prevTs ? Math.floor((t.ts - prevTs) / 60000) : 0;
|
||||
if (gapMin >= 1) {
|
||||
const label = gapMin < 60 ? `${gapMin} Min` : `${Math.floor(gapMin/60)}h ${gapMin%60}m`;
|
||||
rows.push(`<div style="display:flex;align-items:center;padding:6px 16px;gap:8px;"><div style="flex:1;height:1px;background:#1E1E2E;"></div><span style="color:#555570;font-size:10px;">${label}</span><div style="flex:1;height:1px;background:#1E1E2E;"></div></div>`);
|
||||
}
|
||||
prevTs = t.ts;
|
||||
const d = new Date(t.ts);
|
||||
const time = `${String(d.getHours()).padStart(2,'0')}:${String(d.getMinutes()).padStart(2,'0')}:${String(d.getSeconds()).padStart(2,'0')}`;
|
||||
let icon, label, color;
|
||||
if (t.activity === 'idle') { icon = '✓'; label = 'fertig'; color = '#34C759'; }
|
||||
else if (t.activity === 'tool') { icon = '🔧'; label = t.tool || 'tool'; color = '#E0E0F0'; }
|
||||
else if (t.activity === 'assistant'){ icon = '✍️'; label = 'schreibt'; color = '#E0E0F0'; }
|
||||
else if (t.activity === 'thinking'){ icon = '💭'; label = 'denkt'; color = '#E0E0F0'; }
|
||||
else { icon = '•'; label = t.activity; color = '#E0E0F0'; }
|
||||
rows.push(`<div style="display:flex;padding:4px 16px;align-items:baseline;"><span style="color:#555570;width:78px;font-size:11px;">${time}</span><span style="width:24px;">${icon}</span><span style="color:${color};flex:1;">${_escapeHtml(label)}</span></div>`);
|
||||
}
|
||||
list.innerHTML = rows.join('');
|
||||
if (autoscroll) list.scrollTop = list.scrollHeight;
|
||||
}
|
||||
|
||||
// ── XTTS Panel ─────────────────────────────
|
||||
function renderVoiceList(voices) {
|
||||
const box = document.getElementById('xtts-voice-list');
|
||||
@@ -4696,6 +4824,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
loadThoughtStream();
|
||||
connectWS();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -1338,6 +1338,42 @@ const server = http.createServer((req, res) => {
|
||||
else broadcast({ type: "agent_activity", activity: "idle" });
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ ok: true }));
|
||||
} else if (req.url.startsWith("/api/app-log") && req.method === "GET") {
|
||||
// App-Crash-Reporting-Log lesen — die App schickt JS-Errors via RVS,
|
||||
// Bridge schreibt JSONL nach /shared/logs/app.log. Wir liefern die
|
||||
// letzten 200 Eintraege (oder ?limit=N).
|
||||
const url = new URL(req.url, "http://x");
|
||||
const limit = Math.max(1, Math.min(2000, parseInt(url.searchParams.get("limit") || "200", 10) || 200));
|
||||
try {
|
||||
const file = "/shared/logs/app.log";
|
||||
if (!fs.existsSync(file)) {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ count: 0, entries: [] }));
|
||||
return;
|
||||
}
|
||||
const raw = fs.readFileSync(file, "utf-8");
|
||||
const lines = raw.split("\n").filter(l => l.trim());
|
||||
const tail = lines.slice(-limit);
|
||||
const entries = tail.map(l => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ count: entries.length, entries }));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ error: err.message }));
|
||||
}
|
||||
return;
|
||||
} else if (req.url === "/api/app-log/clear" && req.method === "POST") {
|
||||
// App-Log leeren — nach erfolgreichem Debug.
|
||||
try {
|
||||
const file = "/shared/logs/app.log";
|
||||
if (fs.existsSync(file)) fs.unlinkSync(file);
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ ok: true }));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ ok: false, error: err.message }));
|
||||
}
|
||||
return;
|
||||
} else if (req.url === "/api/files-list" && req.method === "GET") {
|
||||
// Liste alle Dateien in /shared/uploads/ — die kommen entweder vom User
|
||||
// (Upload aus App/Diagnostic) oder von ARIA (aria_<name>.<ext> Pattern).
|
||||
|
||||
@@ -12,8 +12,10 @@ services:
|
||||
DIST=$$(find /usr/local/lib -path '*/claude-max-api-proxy/dist' -type d | head -1) &&
|
||||
sed -i 's/startServer({ port })/startServer({ port, host: process.env.HOST || \"127.0.0.1\" })/' $$DIST/server/standalone.js &&
|
||||
sed -i 's/\"--no-session-persistence\",/\"--no-session-persistence\",\"--dangerously-skip-permissions\",/' $$DIST/subprocess/manager.js &&
|
||||
sed -i 's/const DEFAULT_TIMEOUT = 300000;/const DEFAULT_TIMEOUT = 1200000;/' $$DIST/subprocess/manager.js &&
|
||||
cp /proxy-patches/openai-to-cli.js $$DIST/adapter/openai-to-cli.js &&
|
||||
cp /proxy-patches/cli-to-openai.js $$DIST/adapter/cli-to-openai.js &&
|
||||
cp /proxy-patches/routes.js $$DIST/server/routes.js &&
|
||||
claude-max-api"
|
||||
volumes:
|
||||
- ~/.claude:/root/.claude # Claude CLI Auth (Credentials in /root/.claude/.credentials.json)
|
||||
|
||||
@@ -297,6 +297,23 @@ Skills mit Tool-Use.
|
||||
- [x] **Gehirn-Kategorien standardmaessig eingeklappt**: Beim ersten Aufruf alle Type-Sections collapsed, Stefan klappt gezielt auf was er sehen will. State persistiert in localStorage
|
||||
- [x] **Klappbare Type-Header + Category-AutoSuggest + Info-Modal**: Type-Header (▼/▶) klappbar, Category-Feld im Neu/Edit-Modal mit `<datalist>`-Vorschlaegen aller existierenden Categories, ℹ-Button-Modal erklaert welche Types FEST im System-Prompt vs. Cold Memory sind
|
||||
|
||||
### GPS-Trigger-Verbesserungen (entered_near + left_near + Timing-Fix)
|
||||
|
||||
- [x] **near() bei Auto-Vorbeifahrten verpasst — gefixt**: Background-Loop tickte alle 30s, Vorbeifahrt durch 300m-Radius bei 50-120 km/h dauert nur 18-43s → Tick konnte komplett dazwischen liegen. Fix: `TICK_SEC` 30 → 8 (Loop ist billig, Brain merkt das nicht). Plus event-getrieben: Bridge ruft nach jedem `location_update` ein POST `/triggers/check-now` im Brain → Watcher sehen die frische Position in Millisekunden statt im Polling-Takt. Polling läuft parallel als Fallback für Watcher ohne GPS-Bezug
|
||||
- [x] **near() Age-Schutz**: GPS-Daten älter als 5 Minuten (`NEAR_MAX_AGE_SEC=300`) gelten als veraltet → `near()` liefert False. Vorher hätte ein wochen-alter Wert die Funktion weiter als „in der Nähe" eingeordnet → Phantom-Fires wenn Tracking aus war
|
||||
- [x] **Drei GPS-Modi statt einem**: `near()` bleibt = „solange drin". Neu: **`entered_near(lat, lon, r)`** feuert NUR beim Übergang außen→innen (Blitzer-Warner mit r=2000 = 2 km Vorwarnung, Ankunft mit r=100), **`left_near(lat, lon, r)`** feuert NUR beim Übergang innen→außen („Hast du am Parkplatz was vergessen?"). State-Tracking pro Trigger pro near-Aufruf (`near_states`-Dict im Manifest) — Background-Loop schreibt den letzten Auswertungswert immer zurück, damit beim nächsten Tick die Übergangs-Erkennung greift. ARIA's `trigger_watcher`-Tool-Description erklärt die drei Modi inkl. empfohlener Throttle-Werte (kurz für entered/left, lang für near)
|
||||
|
||||
### App-Memory-Editor + Crash-Reporting
|
||||
|
||||
- [x] **Bubble-Header dynamic** (created/updated/deleted): Die `🧠`-Bubble zeigt jetzt was passiert ist — "ARIA hat etwas gemerkt" / "Notiz geändert" / "Notiz gelöscht" (rot bei delete). Brain-Tools schicken `action`-Feld im memory_saved-Event mit
|
||||
- [x] **Tap auf Memory-Bubble → Detail-Modal**: Komponente `MemoryDetailModal` zeigt alle Felder (Titel, Type, Category, Tags, voller Content, Anhang-Vorschau mit Thumbnails). Stift-Icon wechselt in Edit-Mode mit Form-Feldern + 📌 Pinned-Toggle. **Anhänge hoch-/runterladen + löschen** im Modal (DocumentPicker, multipart-Upload via RVS-Brain-Proxy). Memory komplett löschen mit Confirm
|
||||
- [x] **Notizen-Inbox-Button (`🗂️`)** neben der Lupe in der Status-Leiste: Vollbild-Modal mit zwei Sections — „Aus diesem Chat" (kompakte Liste der Spezial-Bubbles aus dem aktuellen Verlauf, klickbar) + „Alle Memories aus der DB" mit dem `MemoryBrowser`. Spezial-Bubbles (memorySaved/triggerCreated/skillCreated) werden im Chat-Stream gefiltert (statt unten zu kleben)
|
||||
- [x] **Memory-Editor in App-Settings**: neue Sektion 🧠 „Gedächtnis" in den App-Einstellungen. Komplette CRUD-UI mit Wortlich-Suche, Type-Dropdown, Pinned/Cold-Filter, „+ Neu" anlegen. Selbe `MemoryBrowser`-Komponente wie in der Inbox
|
||||
- [x] **RVS-Brain-Proxy als Fundament**: Bridge implementiert generischen `brain_request` / `brain_response`-Channel — die App kann beliebige Brain-HTTP-Endpoints via RVS adressieren (GET/POST/PATCH/DELETE, JSON+Base64-Body, base64-encoded Binär-Antworten). `services/brainApi.ts` als Promise-basierter Client mit Request-ID-Routing, Timeout, automatischem Listener-Setup
|
||||
- [x] **App-Crash-Reporting via RVS**: ErrorBoundary-Komponente fängt React-Render-Fehler, `installGlobalCrashReporter` haengt sich an `ErrorUtils.setGlobalHandler` + `HermesInternal.enablePromiseRejectionTracker`. Crashes wandern als `app_log`-Event durch RVS, Bridge schreibt JSONL in `/shared/logs/app.log`. Diagnostic-Server liefert GET `/api/app-log[?limit=N]` + POST `/api/app-log/clear`. **`tools/fetch-app-logs.sh`** holt die Logs auf die Dev-Maschine (über `ARIA_DIAG_URL` aus `.claude/aria-vm.env`), speichert in `.aria-debug/` (gitignored), zeigt Stack-Trace kompakt auf stdout
|
||||
- [x] **`memory_search` + `memory_update` Tools**: ARIA kann die DB jetzt aktiv durchsuchen (Volltext/Semantic) und existierende Einträge per ID patchen statt fragmentierende neue anzulegen. Tool-Description sagt explizit „Memory ist Truth über Conversation-Window" — wenn der User korrigiert hat, gilt das was im Memory steht. Wichtig nach Diagnostic-Edits damit ARIA die neue Wahrheit sieht statt aus dem Window zu raten
|
||||
- [x] **App-Bugfixes**: (a) URLSearchParams crasht in Hermes — durch Mini-Query-Builder ersetzt (`brainApi._qs()`). (b) Cache leer + Datei-Tap → Auto-Re-Download via file_request statt Toast-Sackgasse, plus State-Cleanup (uri/localUri auf undefined). (c) Memory-Liste in Settings scrollt jetzt (nestedScrollEnabled auf FlatList + äußere ScrollView). (d) Modal-im-Modal auf Android gefixt — MemoryBrowser nimmt optionalen `onOpenMemory`-Callback, kein verschachteltes DetailModal mehr. (e) Alert.prompt (iOS-only) durch eigenes Text-Input-Modal ersetzt fuer „Neue Memory anlegen"
|
||||
|
||||
### Memory-Anhaenge mit Vision (Stufe A-E + attach_paths)
|
||||
|
||||
- [x] **Anhaenge an Memory-Eintraege** — Bilder/PDFs/beliebige Dateien koennen an jede Memory gehaengt werden, liegen physisch unter `/shared/memory-attachments/<memory-id>/`. Cleanup beim Memory-Delete automatisch. Limit 20 MB pro Datei
|
||||
@@ -324,14 +341,22 @@ Skills mit Tool-Use.
|
||||
- [x] Info-Buttons mit Modal-Erklaerungen im Gehirn-Tab
|
||||
- [x] Token/Call-Metrics + Subscription-Quota-Tracking: pro Claude-Call ein Log-Eintrag mit Token-Schaetzung (chars/4). Gehirn-Tab zeigt 1h/5h/24h/30d-Aggregat + Progress-Bar gegen Plan-Limit (Pro=45/5h, Max 5x=225/5h, Max 20x=900/5h, Custom). Warn-Schwelle 80%, kritisch 90%.
|
||||
|
||||
### Chat-Stabilitaet: Such-Scroll, Stuck-Watchdog, Delivery-Handshake
|
||||
|
||||
- [x] **Such-Scroll springt nicht mehr permanent**: `onScrollToIndexFailed` hatte 3 cascading `setTimeout`s (120/320/600 ms) — jeder failed Retry triggerte den Handler wieder → 3, 9, 27 Scrolls in der Pipeline. Plus `invertedMessages` war in den useEffect-Deps: jede neue ARIA-Nachricht re-triggerte den Such-Scroll. Fix: nur EIN Retry nach 300 ms, in einer Ref-getrackten Timer-Variable; bei neuem Such-Hit wird der pending Retry gecancelt. `invertedMessages`-Snapshot via Ref statt Dep
|
||||
- [x] **Jump-to-Bottom-Button** rechts unten in der Chat-Liste — taucht ab ~250 px Scroll-Weg auf, scrollt zur neuesten Nachricht (bei inverted FlatList `scrollToOffset(0)`)
|
||||
- [x] **AsyncStorage-Init-Race**: zwischen Mount und „Verlauf aus AsyncStorage geladen" konnte eine User-Nachricht oder ein WS-Event ankommen — `setMessages(parsed)` ueberschrieb's mit dem alten Stand und die frische Nachricht war spurlos weg. Fix: Merge per `id` (frischere `prev`-Eintraege schlagen Gespeichertes), sortiert nach `timestamp`. `messageIdCounter` wird nur noch erhoeht, nie zurueckgesetzt
|
||||
- [x] **Stuck-Thinking-Watchdog**: „ARIA denkt..." blieb gelegentlich kleben (Brain-Crash, WS-Disconnect ohne idle-Event, Cancel mit Race). Fix: jeder `agent_activity != idle` armiert einen 180s-Timer; ohne neues Lebenszeichen geht's auto-idle + Bubble „⚠ Habe gerade keine Verbindung zurueck bekommen". Watchdog wird beim ARIA-Reply, beim Cancel/Barge-In und beim Screen-Unmount gecleart
|
||||
- [x] **Delivery-Handshake (WhatsApp-Style)**: pro User-Bubble ein lokaler `clientMsgId` + `deliveryStatus` (queued/sending/sent/delivered/failed). Bridge sendet `chat_ack` zurueck (✓ sent) und schreibt die ID ins `chat_backup.jsonl`. ARIA-Reply markiert alle vorigen User-Bubbles als delivered (✓✓). LRU-Idempotenz auf der Bridge (200 cmids) verhindert Doppelte beim Retry. Offline-Queue: Nachrichten im Flugmodus bleiben lokal als ⏱-queued, beim Reconnect feuert `flushQueuedMessages`. ACK-Timeout 30 s, bis zu 3 Retries, danach ⚠ + Tap-fuer-Retry
|
||||
- [x] **Offline-Bubble verschwand nach Reconnect (Race)**: parallel laufen `chat_history_request` und `flushQueuedMessages` beim Reconnect; die History-Antwort kam an bevor die Bridge die Bubble persistiert hatte → Merge ersetzte den lokalen Stand → Bubble weg (war aber in Diagnostic drin). Fix: Bridge spiegelt `clientMsgId` im `chat_backup.jsonl`, App-Merge dedupt per cmid und behaelt lokale Bubbles deren ID der Server noch nicht kennt
|
||||
- [x] **Doppel-Bubble nach Retry**: Backup-Eintraege von vor dem cmid-Patch hatten keine `clientMsgId` — Server-Bubble (ohne cmid) und lokale failed-Bubble (mit cmid) standen beide im Merge. Plus ACK-Timer lief gelegentlich weiter obwohl die Bubble schon `delivered` war → Retry pushte den Status zurueck auf `sending`. Fix: Merge faellt zusaetzlich auf `text+timestamp`-Heuristik im 5-Min-Fenster zurueck; `dispatchWithAck` prueft per Ref ob die Bubble inzwischen `delivered` ist und cancelt dann; bei ARIA-Reply werden alle laufenden ACK-Timer gecleart
|
||||
|
||||
## Offen
|
||||
|
||||
### App Features
|
||||
- [ ] Chat-History zuverlaessiger laden (AsyncStorage Race Condition)
|
||||
- [ ] Custom-Wake-Word-Upload via Diagnostic (eigene .onnx-Files ohne App-Rebuild)
|
||||
|
||||
### Architektur
|
||||
- [ ] Bilder: Claude Vision direkt nutzen (aktuell nur Dateipfad an ARIA)
|
||||
- [ ] Diagnostic: System-Info Tab (Container-Status, Disk, RAM, CPU)
|
||||
- [ ] RVS Zombie-Connections endgueltig loesen
|
||||
- [ ] Gamebox: kleine Web-Oberflaeche fuer Credentials/Server-Config oder zentral aus Diagnostic per RVS push
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
/**
|
||||
* ARIA-patched API Route Handlers
|
||||
*
|
||||
* Erweiterung der npm-Version von claude-max-api-proxy:
|
||||
* - Bei jedem Claude-CLI-`assistant`-Event mit tool_use-Block (Bash, Read,
|
||||
* Edit, Grep, …) wird ein HTTP-POST an die Bridge gefeuert
|
||||
* (ARIA_TOOL_HOOK_URL, default http://aria-bridge:8090/internal/agent-activity).
|
||||
* Bridge spiegelt das als RVS `agent_activity` an App+Diagnostic →
|
||||
* Gedanken-Stream zeigt live was ARIA gerade tool-maessig macht.
|
||||
* - Fire-and-forget, fail-open. Wenn die Bridge nicht antwortet, bricht
|
||||
* der Brain-Call NICHT ab.
|
||||
*
|
||||
* Wird zur Container-Startzeit ueber die npm-Version geschrieben
|
||||
* (siehe docker-compose.yml proxy-Block).
|
||||
*/
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import http from "http";
|
||||
import { ClaudeSubprocess } from "../subprocess/manager.js";
|
||||
import { openaiToCli } from "../adapter/openai-to-cli.js";
|
||||
import { cliResultToOpenai, createDoneChunk, } from "../adapter/cli-to-openai.js";
|
||||
|
||||
const TOOL_HOOK_URL = process.env.ARIA_TOOL_HOOK_URL
|
||||
|| "http://aria-bridge:8090/internal/agent-activity";
|
||||
|
||||
/**
|
||||
* Pusht einen Tool-Use-Event an die Bridge. Fire-and-forget — keine Awaits,
|
||||
* keine Fehler nach oben. Logged Fehler still.
|
||||
*/
|
||||
function _emitToolEvent(toolName) {
|
||||
if (!toolName) return;
|
||||
try {
|
||||
const u = new URL(TOOL_HOOK_URL);
|
||||
const body = JSON.stringify({ tool: String(toolName) });
|
||||
const req = http.request({
|
||||
method: "POST",
|
||||
hostname: u.hostname,
|
||||
port: u.port || 80,
|
||||
path: u.pathname,
|
||||
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) },
|
||||
timeout: 2000,
|
||||
}, (res) => { res.resume(); });
|
||||
req.on("error", () => {});
|
||||
req.on("timeout", () => req.destroy());
|
||||
req.write(body);
|
||||
req.end();
|
||||
} catch (_) { /* niemals weiterwerfen */ }
|
||||
}
|
||||
|
||||
/**
|
||||
* Hookt die `assistant`-Events des Subprozesses. Jedes assistant-Message
|
||||
* kann mehrere content-Bloecke haben — tool_use-Bloecke pushen wir live.
|
||||
*/
|
||||
function _attachToolHook(subprocess) {
|
||||
subprocess.on("assistant", (message) => {
|
||||
try {
|
||||
const blocks = message?.message?.content || [];
|
||||
for (const b of blocks) {
|
||||
if (b && b.type === "tool_use" && b.name) {
|
||||
_emitToolEvent(b.name);
|
||||
}
|
||||
}
|
||||
} catch (_) { /* fail-open */ }
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Handle POST /v1/chat/completions
|
||||
*
|
||||
* Main endpoint for chat requests, supports both streaming and non-streaming
|
||||
*/
|
||||
export async function handleChatCompletions(req, res) {
|
||||
const requestId = uuidv4().replace(/-/g, "").slice(0, 24);
|
||||
const body = req.body;
|
||||
const stream = body.stream === true;
|
||||
try {
|
||||
// Validate request
|
||||
if (!body.messages || !Array.isArray(body.messages) || body.messages.length === 0) {
|
||||
res.status(400).json({
|
||||
error: {
|
||||
message: "messages is required and must be a non-empty array",
|
||||
type: "invalid_request_error",
|
||||
code: "invalid_messages",
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Convert to CLI input format
|
||||
const cliInput = openaiToCli(body);
|
||||
const subprocess = new ClaudeSubprocess();
|
||||
// ARIA-Patch: Tool-Use-Events live an die Bridge weiterleiten.
|
||||
// Greift fuer beide Branches (stream + non-stream).
|
||||
_attachToolHook(subprocess);
|
||||
if (stream) {
|
||||
await handleStreamingResponse(req, res, subprocess, cliInput, requestId);
|
||||
}
|
||||
else {
|
||||
await handleNonStreamingResponse(res, subprocess, cliInput, requestId);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Unknown error";
|
||||
console.error("[handleChatCompletions] Error:", message);
|
||||
if (!res.headersSent) {
|
||||
res.status(500).json({
|
||||
error: {
|
||||
message,
|
||||
type: "server_error",
|
||||
code: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handle streaming response (SSE)
|
||||
*
|
||||
* IMPORTANT: The Express req.on("close") event fires when the request body
|
||||
* is fully received, NOT when the client disconnects. For SSE connections,
|
||||
* we use res.on("close") to detect actual client disconnection.
|
||||
*/
|
||||
async function handleStreamingResponse(req, res, subprocess, cliInput, requestId) {
|
||||
// Set SSE headers
|
||||
res.setHeader("Content-Type", "text/event-stream");
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
res.setHeader("Connection", "keep-alive");
|
||||
res.setHeader("X-Request-Id", requestId);
|
||||
// CRITICAL: Flush headers immediately to establish SSE connection
|
||||
// Without this, headers are buffered and client times out waiting
|
||||
res.flushHeaders();
|
||||
// Send initial comment to confirm connection is alive
|
||||
res.write(":ok\n\n");
|
||||
return new Promise((resolve, reject) => {
|
||||
let isFirst = true;
|
||||
let lastModel = "claude-sonnet-4";
|
||||
let isComplete = false;
|
||||
// Handle actual client disconnect (response stream closed)
|
||||
res.on("close", () => {
|
||||
if (!isComplete) {
|
||||
// Client disconnected before response completed - kill subprocess
|
||||
subprocess.kill();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
// Handle streaming content deltas
|
||||
subprocess.on("content_delta", (event) => {
|
||||
const text = event.event.delta?.text || "";
|
||||
if (text && !res.writableEnded) {
|
||||
const chunk = {
|
||||
id: `chatcmpl-${requestId}`,
|
||||
object: "chat.completion.chunk",
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
model: lastModel,
|
||||
choices: [{
|
||||
index: 0,
|
||||
delta: {
|
||||
role: isFirst ? "assistant" : undefined,
|
||||
content: text,
|
||||
},
|
||||
finish_reason: null,
|
||||
}],
|
||||
};
|
||||
res.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
||||
isFirst = false;
|
||||
}
|
||||
});
|
||||
// Handle final assistant message (for model name)
|
||||
subprocess.on("assistant", (message) => {
|
||||
lastModel = message.message.model;
|
||||
});
|
||||
subprocess.on("result", (_result) => {
|
||||
isComplete = true;
|
||||
if (!res.writableEnded) {
|
||||
// Send final done chunk with finish_reason
|
||||
const doneChunk = createDoneChunk(requestId, lastModel);
|
||||
res.write(`data: ${JSON.stringify(doneChunk)}\n\n`);
|
||||
res.write("data: [DONE]\n\n");
|
||||
res.end();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
subprocess.on("error", (error) => {
|
||||
console.error("[Streaming] Error:", error.message);
|
||||
if (!res.writableEnded) {
|
||||
res.write(`data: ${JSON.stringify({
|
||||
error: { message: error.message, type: "server_error", code: null },
|
||||
})}\n\n`);
|
||||
res.end();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
subprocess.on("close", (code) => {
|
||||
// Subprocess exited - ensure response is closed
|
||||
if (!res.writableEnded) {
|
||||
if (code !== 0 && !isComplete) {
|
||||
// Abnormal exit without result - send error
|
||||
res.write(`data: ${JSON.stringify({
|
||||
error: { message: `Process exited with code ${code}`, type: "server_error", code: null },
|
||||
})}\n\n`);
|
||||
}
|
||||
res.write("data: [DONE]\n\n");
|
||||
res.end();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
// Start the subprocess
|
||||
subprocess.start(cliInput.prompt, {
|
||||
model: cliInput.model,
|
||||
sessionId: cliInput.sessionId,
|
||||
}).catch((err) => {
|
||||
console.error("[Streaming] Subprocess start error:", err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Handle non-streaming response
|
||||
*/
|
||||
async function handleNonStreamingResponse(res, subprocess, cliInput, requestId) {
|
||||
return new Promise((resolve) => {
|
||||
let finalResult = null;
|
||||
subprocess.on("result", (result) => {
|
||||
finalResult = result;
|
||||
});
|
||||
subprocess.on("error", (error) => {
|
||||
console.error("[NonStreaming] Error:", error.message);
|
||||
res.status(500).json({
|
||||
error: {
|
||||
message: error.message,
|
||||
type: "server_error",
|
||||
code: null,
|
||||
},
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
subprocess.on("close", (code) => {
|
||||
if (finalResult) {
|
||||
res.json(cliResultToOpenai(finalResult, requestId));
|
||||
}
|
||||
else if (!res.headersSent) {
|
||||
res.status(500).json({
|
||||
error: {
|
||||
message: `Claude CLI exited with code ${code} without response`,
|
||||
type: "server_error",
|
||||
code: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
// Start the subprocess
|
||||
subprocess
|
||||
.start(cliInput.prompt, {
|
||||
model: cliInput.model,
|
||||
sessionId: cliInput.sessionId,
|
||||
})
|
||||
.catch((error) => {
|
||||
res.status(500).json({
|
||||
error: {
|
||||
message: error.message,
|
||||
type: "server_error",
|
||||
code: null,
|
||||
},
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Handle GET /v1/models
|
||||
*
|
||||
* Returns available models
|
||||
*/
|
||||
export function handleModels(_req, res) {
|
||||
res.json({
|
||||
object: "list",
|
||||
data: [
|
||||
{
|
||||
id: "claude-opus-4",
|
||||
object: "model",
|
||||
owned_by: "anthropic",
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
},
|
||||
{
|
||||
id: "claude-sonnet-4",
|
||||
object: "model",
|
||||
owned_by: "anthropic",
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
},
|
||||
{
|
||||
id: "claude-haiku-4",
|
||||
object: "model",
|
||||
owned_by: "anthropic",
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Handle GET /health
|
||||
*
|
||||
* Health check endpoint
|
||||
*/
|
||||
export function handleHealth(_req, res) {
|
||||
res.json({
|
||||
status: "ok",
|
||||
provider: "claude-code-cli",
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=routes.js.map
|
||||
@@ -30,6 +30,8 @@ const ALLOWED_TYPES = new Set([
|
||||
"location_update", "location_tracking",
|
||||
"chat_history_request", "chat_history_response", "chat_cleared",
|
||||
"delete_message_request", "chat_message_deleted",
|
||||
"brain_request", "brain_response",
|
||||
"app_log",
|
||||
"file_delete_batch_request", "file_delete_batch_response",
|
||||
"file_zip_request", "file_zip_response",
|
||||
"xtts_delete_voice",
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# tools/
|
||||
|
||||
Hilfsskripte für die Dev-Maschine. Brauchen `.claude/aria-vm.env` (aus
|
||||
`.example` kopieren + lokale VM-IP eintragen).
|
||||
|
||||
## fetch-app-logs.sh
|
||||
|
||||
Holt App-Crash-Logs von der VM und speichert sie unter `.aria-debug/`
|
||||
(gitignored). Die App schickt JS-Errors und ungefangene Promise-
|
||||
Rejections via RVS an die Bridge — Bridge sammelt in
|
||||
`/shared/logs/app.log`, Diagnostic-Server gibt sie via
|
||||
`GET /api/app-log` raus.
|
||||
|
||||
```bash
|
||||
tools/fetch-app-logs.sh # 200 neueste Eintraege
|
||||
tools/fetch-app-logs.sh --limit 50 # weniger
|
||||
tools/fetch-app-logs.sh --watch # alle 5s pollen, neue rausgeben
|
||||
tools/fetch-app-logs.sh --clear # nach Abholen Log auf VM leeren
|
||||
```
|
||||
|
||||
Ausgabe enthaelt pro Eintrag: Uhrzeit, Level (error/warn/info), Scope
|
||||
(z.B. `ChatScreen.InboxModal` oder `global-fatal`), Message, und die
|
||||
ersten ~8 Stack-Frames. Die kompletten Daten liegen als JSON in
|
||||
`.aria-debug/app-log-<timestamp>.json`.
|
||||
|
||||
Workflow nach einem Crash:
|
||||
|
||||
1. App rebuilden mit Crash-Reporting (passiert automatisch ab dem
|
||||
`21a315c`-Commit)
|
||||
2. Crash in der App ausloesen
|
||||
3. `tools/fetch-app-logs.sh` auf der Dev-Maschine
|
||||
4. Stacktrace lesen / Claude geben
|
||||
5. Fix bauen
|
||||
6. `tools/fetch-app-logs.sh --clear` damit der Log wieder sauber ist
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env bash
|
||||
# fetch-app-logs.sh — App-Crash-Logs von der VM holen
|
||||
#
|
||||
# Nutzt .claude/aria-vm.env als Quelle fuer $ARIA_DIAG_URL und ruft
|
||||
# GET /api/app-log?limit=N. Speichert die Roh-Response unter
|
||||
# .aria-debug/app-log-<timestamp>.json und gibt eine kompakte
|
||||
# Zusammenfassung auf stdout aus (letzte Eintraege mit Stack-Trace).
|
||||
#
|
||||
# Verwendung:
|
||||
# tools/fetch-app-logs.sh # Default limit=200
|
||||
# tools/fetch-app-logs.sh --limit 50 # nur 50 holen
|
||||
# tools/fetch-app-logs.sh --clear # nach Abholen Log loeschen
|
||||
# tools/fetch-app-logs.sh --watch # alle 5s pollen, neue Eintraege ausgeben
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
LIMIT=200
|
||||
CLEAR=0
|
||||
WATCH=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--limit) LIMIT="$2"; shift 2 ;;
|
||||
--limit=*) LIMIT="${1#*=}"; shift ;;
|
||||
--clear) CLEAR=1; shift ;;
|
||||
--watch) WATCH=1; shift ;;
|
||||
-h|--help)
|
||||
sed -n '1,/^set/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//'
|
||||
exit 0 ;;
|
||||
*) echo "Unbekannte Option: $1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
ENV_FILE="$ROOT/.claude/aria-vm.env"
|
||||
OUT_DIR="$ROOT/.aria-debug"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "FEHLER: $ENV_FILE nicht vorhanden. Aus .example kopieren und IP anpassen." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
|
||||
if [[ -z "${ARIA_DIAG_URL:-}" ]]; then
|
||||
echo "FEHLER: ARIA_DIAG_URL nicht gesetzt in $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
fetch_once() {
|
||||
local ts json file
|
||||
ts="$(date +%Y%m%d_%H%M%S)"
|
||||
json="$(curl -s --max-time 10 "${ARIA_DIAG_URL%/}/api/app-log?limit=$LIMIT")" || {
|
||||
echo "FEHLER: curl gegen $ARIA_DIAG_URL fehlgeschlagen" >&2
|
||||
return 1
|
||||
}
|
||||
file="$OUT_DIR/app-log-$ts.json"
|
||||
echo "$json" > "$file"
|
||||
python3 - "$file" <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
data = json.loads(Path(sys.argv[1]).read_text())
|
||||
entries = data.get("entries") or []
|
||||
print(f"=== {len(entries)} Eintrag{'e' if len(entries)!=1 else ''} (gespeichert unter {sys.argv[1]}) ===")
|
||||
for e in entries[-20:]:
|
||||
ts = e.get("ts") or 0
|
||||
from datetime import datetime
|
||||
when = datetime.fromtimestamp(ts/1000).strftime("%H:%M:%S") if ts else "?"
|
||||
lvl = e.get("level","?")
|
||||
scope = e.get("scope","?")
|
||||
msg = (e.get("message") or "").splitlines()[0][:200]
|
||||
print(f"\n[{when}] {lvl:5} {scope}: {msg}")
|
||||
stack = (e.get("stack") or "").strip()
|
||||
if stack:
|
||||
for line in stack.splitlines()[:8]:
|
||||
print(f" {line}")
|
||||
if len(stack.splitlines()) > 8:
|
||||
print(f" ... ({len(stack.splitlines())-8} weitere Zeilen — siehe JSON)")
|
||||
PY
|
||||
return 0
|
||||
}
|
||||
|
||||
if [[ "$WATCH" == "1" ]]; then
|
||||
echo "Watching $ARIA_DIAG_URL/api/app-log — Ctrl+C zum Beenden"
|
||||
SEEN=""
|
||||
while true; do
|
||||
cur=$(curl -s --max-time 10 "${ARIA_DIAG_URL%/}/api/app-log?limit=$LIMIT") || cur=""
|
||||
hash=$(echo "$cur" | md5sum | awk '{print $1}')
|
||||
if [[ "$hash" != "$SEEN" && -n "$cur" ]]; then
|
||||
SEEN="$hash"
|
||||
fetch_once
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
else
|
||||
fetch_once
|
||||
fi
|
||||
|
||||
if [[ "$CLEAR" == "1" ]]; then
|
||||
echo
|
||||
echo "→ Log auf der VM leeren..."
|
||||
curl -s --max-time 5 -X POST "${ARIA_DIAG_URL%/}/api/app-log/clear" | python3 -m json.tool || true
|
||||
fi
|
||||
Reference in New Issue
Block a user