Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 882f3def99 | |||
| 092f085254 | |||
| 21eac63723 | |||
| 06316da36f | |||
| 7927ad05ae | |||
| 5b2c552a88 | |||
| f51ad1547d | |||
| 2a2700907c | |||
| 93ecbf6c43 | |||
| d430fa113e | |||
| 1fb512c2fd |
@@ -79,8 +79,8 @@ android {
|
|||||||
applicationId "com.ariacockpit"
|
applicationId "com.ariacockpit"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 10904
|
versionCode 10908
|
||||||
versionName "0.1.9.4"
|
versionName "0.1.9.8"
|
||||||
// Fallback fuer Libraries mit Product Flavors
|
// Fallback fuer Libraries mit Product Flavors
|
||||||
missingDimensionStrategy 'react-native-camera', 'general'
|
missingDimensionStrategy 'react-native-camera', 'general'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aria-cockpit",
|
"name": "aria-cockpit",
|
||||||
"version": "0.1.9.4",
|
"version": "0.1.9.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"android": "react-native run-android",
|
"android": "react-native run-android",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* SettingsScreen.tsx in der Section 'projects'.
|
* SettingsScreen.tsx in der Section 'projects'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Alert,
|
Alert,
|
||||||
@@ -33,9 +33,12 @@ interface Props {
|
|||||||
/** Optional — wenn als Modal genutzt, sonst inline */
|
/** Optional — wenn als Modal genutzt, sonst inline */
|
||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
/** Wird gerufen wenn sich das aktive Projekt aendert — ChatScreen
|
/** Wird gerufen wenn Stefan ein anderes Projekt fokussiert (App-lokale
|
||||||
* refresht dann seinen Banner-State. */
|
* UI-Entscheidung, wechselt den Chat-Focus). */
|
||||||
onActiveChanged?: (project: Project | null) => void;
|
onActiveChanged?: (project: Project | null) => void;
|
||||||
|
/** Queue-Status pro Kontext (key "__main__" = Hauptchat, sonst project_id).
|
||||||
|
* Wenn geliefert: Status-Dot pro Zeile gerendert. */
|
||||||
|
queueStatus?: Record<string, { busy: boolean; queue_size: number }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _fmtRel(unixSec: number): string {
|
function _fmtRel(unixSec: number): string {
|
||||||
@@ -48,7 +51,14 @@ function _fmtRel(unixSec: number): string {
|
|||||||
return new Date(unixSec * 1000).toLocaleDateString('de-DE');
|
return new Date(unixSec * 1000).toLocaleDateString('de-DE');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onActiveChanged }) => {
|
export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onActiveChanged, queueStatus }) => {
|
||||||
|
const _statusDot = (pid: string) => {
|
||||||
|
const s = queueStatus?.[pid];
|
||||||
|
if (!s) return { color: '#555570', label: '' };
|
||||||
|
if (s.busy) return { color: '#FF6E6E', label: 'arbeitet' };
|
||||||
|
if (s.queue_size > 0) return { color: '#FFD60A', label: `Queue: ${s.queue_size}` };
|
||||||
|
return { color: '#34C759', label: 'idle' };
|
||||||
|
};
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
const [activeId, setActiveId] = useState<string>('');
|
const [activeId, setActiveId] = useState<string>('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -60,17 +70,23 @@ export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onAc
|
|||||||
const [editName, setEditName] = useState('');
|
const [editName, setEditName] = useState('');
|
||||||
const [editDesc, setEditDesc] = useState('');
|
const [editDesc, setEditDesc] = useState('');
|
||||||
|
|
||||||
|
// Refs damit useCallback NICHT bei jeder Re-Render des Parents neu erzeugt
|
||||||
|
// wird (parent uebergibt oft inline-arrow-Callbacks, neue Identity jedes
|
||||||
|
// Render → useCallback re-runs → useEffect refeuert → infinite spinner).
|
||||||
|
const onActiveChangedRef = useRef(onActiveChanged);
|
||||||
|
useEffect(() => { onActiveChangedRef.current = onActiveChanged; }, [onActiveChanged]);
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
setLoading(true); setErr(null);
|
setLoading(true); setErr(null);
|
||||||
brainApi.getProjectStatus()
|
brainApi.getProjectStatus()
|
||||||
.then(status => {
|
.then(status => {
|
||||||
setProjects(status.projects || []);
|
setProjects(status.projects || []);
|
||||||
setActiveId(status.active_id || '');
|
setActiveId(status.active_id || '');
|
||||||
onActiveChanged?.(status.active);
|
onActiveChangedRef.current?.(status.active);
|
||||||
})
|
})
|
||||||
.catch(e => setErr(String(e?.message || e)))
|
.catch(e => setErr(String(e?.message || e)))
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [onActiveChanged]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => { if (visible) load(); }, [visible, load]);
|
useEffect(() => { if (visible) load(); }, [visible, load]);
|
||||||
|
|
||||||
@@ -82,13 +98,14 @@ export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onAc
|
|||||||
}, [visible, load]);
|
}, [visible, load]);
|
||||||
|
|
||||||
const switchTo = useCallback((id: string) => {
|
const switchTo = useCallback((id: string) => {
|
||||||
brainApi.switchProject(id)
|
// Multi-Threading: Focus-Wechsel ist reine App-lokale UI-Entscheidung.
|
||||||
.then(status => {
|
// Brain wird nicht mehr benachrichtigt (kein globaler active_project mehr).
|
||||||
setActiveId(status.active_id || '');
|
// Wir suchen das Projekt lokal aus der Liste, damit die App den Namen kennt.
|
||||||
onActiveChanged?.(status.active);
|
setActiveId(id);
|
||||||
})
|
const p = id ? (projects.find(x => x.id === id) || null) : null;
|
||||||
.catch(e => Alert.alert('Fehler', String(e?.message || e)));
|
onActiveChangedRef.current?.(p);
|
||||||
}, [onActiveChanged]);
|
if (onClose) onClose();
|
||||||
|
}, [projects, onClose]);
|
||||||
|
|
||||||
const createProject = useCallback(() => {
|
const createProject = useCallback(() => {
|
||||||
const name = newName.trim();
|
const name = newName.trim();
|
||||||
@@ -146,6 +163,7 @@ export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onAc
|
|||||||
|
|
||||||
const renderItem = ({ item }: { item: Project }) => {
|
const renderItem = ({ item }: { item: Project }) => {
|
||||||
const isActive = item.id === activeId;
|
const isActive = item.id === activeId;
|
||||||
|
const dot = _statusDot(item.id);
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => switchTo(item.id)}
|
onPress={() => switchTo(item.id)}
|
||||||
@@ -154,15 +172,19 @@ export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onAc
|
|||||||
>
|
>
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
||||||
|
{queueStatus && (
|
||||||
|
<View style={{ width: 8, height: 8, borderRadius: 4, backgroundColor: dot.color }} />
|
||||||
|
)}
|
||||||
<Text style={[s.rowName, isActive && { color: '#34C759' }]}>{item.name}</Text>
|
<Text style={[s.rowName, isActive && { color: '#34C759' }]}>{item.name}</Text>
|
||||||
{item.status === 'ended' && <Text style={s.statusBadge}>beendet</Text>}
|
{item.status === 'ended' && <Text style={s.statusBadge}>beendet</Text>}
|
||||||
{isActive && <Text style={s.activeBadge}>✓ AKTIV</Text>}
|
{isActive && <Text style={s.activeBadge}>✓ FOCUS</Text>}
|
||||||
</View>
|
</View>
|
||||||
{item.description ? (
|
{item.description ? (
|
||||||
<Text style={s.rowDesc} numberOfLines={2}>{item.description}</Text>
|
<Text style={s.rowDesc} numberOfLines={2}>{item.description}</Text>
|
||||||
) : null}
|
) : null}
|
||||||
<Text style={s.rowMeta}>
|
<Text style={s.rowMeta}>
|
||||||
{item.turn_count} Turns · zuletzt {_fmtRel(item.last_activity_at)}
|
{item.turn_count} Turns · zuletzt {_fmtRel(item.last_activity_at)}
|
||||||
|
{dot.label ? ` · ${dot.label}` : ''}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
@@ -185,18 +207,29 @@ export const ProjectsBrowser: React.FC<Props> = ({ visible = true, onClose, onAc
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Hauptchat-Eintrag (immer oben) */}
|
{/* Hauptchat-Eintrag (immer oben) */}
|
||||||
<TouchableOpacity
|
{(() => {
|
||||||
onPress={() => switchTo('')}
|
const dot = _statusDot('__main__');
|
||||||
style={[s.row, !activeId && s.rowActive]}
|
return (
|
||||||
>
|
<TouchableOpacity
|
||||||
<View style={{ flex: 1 }}>
|
onPress={() => switchTo('')}
|
||||||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
style={[s.row, !activeId && s.rowActive]}
|
||||||
<Text style={[s.rowName, !activeId && { color: '#34C759' }]}>💬 Hauptchat</Text>
|
>
|
||||||
{!activeId && <Text style={s.activeBadge}>✓ AKTIV</Text>}
|
<View style={{ flex: 1 }}>
|
||||||
</View>
|
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
||||||
<Text style={s.rowMeta}>Standard-Verlauf, keine Projekt-Zuordnung</Text>
|
{queueStatus && (
|
||||||
</View>
|
<View style={{ width: 8, height: 8, borderRadius: 4, backgroundColor: dot.color }} />
|
||||||
</TouchableOpacity>
|
)}
|
||||||
|
<Text style={[s.rowName, !activeId && { color: '#34C759' }]}>💬 Hauptchat</Text>
|
||||||
|
{!activeId && <Text style={s.activeBadge}>✓ FOCUS</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={s.rowMeta}>
|
||||||
|
Standard-Verlauf, keine Projekt-Zuordnung
|
||||||
|
{dot.label ? ` · ${dot.label}` : ''}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</TouchableOpacity>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<View style={{ padding: 24, alignItems: 'center' }}>
|
<View style={{ padding: 24, alignItems: 'center' }}>
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ interface ChatMessage {
|
|||||||
text: string;
|
text: string;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
attachments?: Attachment[];
|
attachments?: Attachment[];
|
||||||
|
/** Projekt-Zuordnung — leer = Hauptchat. Wird genutzt um Bubbles zu
|
||||||
|
* Projekt-Bloecken zu gruppieren (auf/einklappbar). */
|
||||||
|
projectId?: string;
|
||||||
/** Bridge-Message-ID zur Zuordnung von TTS-Audio */
|
/** Bridge-Message-ID zur Zuordnung von TTS-Audio */
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
/** Lokaler Pfad zur gecachten TTS-Audio-Datei (file://...) */
|
/** Lokaler Pfad zur gecachten TTS-Audio-Datei (file://...) */
|
||||||
@@ -283,7 +286,15 @@ const ChatScreen: React.FC = () => {
|
|||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
const [searchVisible, setSearchVisible] = useState(false);
|
const [searchVisible, setSearchVisible] = useState(false);
|
||||||
const [projectsVisible, setProjectsVisible] = useState(false);
|
const [projectsVisible, setProjectsVisible] = useState(false);
|
||||||
const [activeProject, setActiveProject] = useState<BrainProject | null>(null);
|
// Focus-One-View: welchen Chat sieht Stefan gerade?
|
||||||
|
// Leer = Hauptchat, sonst die project_id. Multi-Threading:
|
||||||
|
// Wechsel des Focus stoppt NICHT ARIAs Arbeit in anderen Projekten —
|
||||||
|
// die laufen im Brain weiter, wir sehen sie hier nur nicht.
|
||||||
|
const [focusedProjectId, setFocusedProjectId] = useState<string>('');
|
||||||
|
// Lookup-Map id → Projekt (fuer Drawer + Referenzen)
|
||||||
|
const [projectNameById, setProjectNameById] = useState<Record<string, string>>({});
|
||||||
|
// Queue-Status pro Kontext — polled alle 2s, fuer Status-Dots im Drawer
|
||||||
|
const [queueStatus, setQueueStatus] = useState<Record<string, { busy: boolean; queue_size: number }>>({});
|
||||||
const [searchIndex, setSearchIndex] = useState(0); // welcher Treffer aktiv ist
|
const [searchIndex, setSearchIndex] = useState(0); // welcher Treffer aktiv ist
|
||||||
const [pendingAttachments, setPendingAttachments] = useState<{file: any, isPhoto: boolean}[]>([]);
|
const [pendingAttachments, setPendingAttachments] = useState<{file: any, isPhoto: boolean}[]>([]);
|
||||||
const [agentActivity, setAgentActivity] = useState<{activity: string, tool: string}>({activity: 'idle', tool: ''});
|
const [agentActivity, setAgentActivity] = useState<{activity: string, tool: string}>({activity: 'idle', tool: ''});
|
||||||
@@ -460,20 +471,53 @@ const ChatScreen: React.FC = () => {
|
|||||||
}, [dispatchWithAck]);
|
}, [dispatchWithAck]);
|
||||||
|
|
||||||
// TTS- + GPS-Settings beim Mount + alle 2s neu laden (damit Settings-Toggle
|
// TTS- + GPS-Settings beim Mount + alle 2s neu laden (damit Settings-Toggle
|
||||||
// sofort greift, ohne Context- oder Event-System)
|
// Projekt-Namen laden (Lookup-Map) + focusedProjectId aus AsyncStorage
|
||||||
// Aktives Projekt initial laden + bei RVS-Reconnect refreshen.
|
// wiederherstellen (Default = Hauptchat wenn nichts gespeichert). Der
|
||||||
// Wird zusaetzlich nach jedem chat-Response refreshed (siehe handleAriaMessage).
|
// Brain hat mit Multi-Threading keinen global-aktiven Projekt-State mehr;
|
||||||
|
// Focus ist reine App-lokale UI-Info.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadProject = () => {
|
const loadNames = () => {
|
||||||
brainApi.getProjectStatus()
|
brainApi.listProjects(true)
|
||||||
.then(s => setActiveProject(s.active || null))
|
.then(list => {
|
||||||
|
const map: Record<string, string> = {};
|
||||||
|
for (const p of list) map[p.id] = p.name;
|
||||||
|
setProjectNameById(prev => ({ ...prev, ...map }));
|
||||||
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
loadProject();
|
loadNames();
|
||||||
const unsub = rvs.onStateChange(state => { if (state === 'connected') loadProject(); });
|
// Letzten Focus aus Storage restoren
|
||||||
|
AsyncStorage.getItem('aria_focused_project_id').then(v => {
|
||||||
|
if (v && typeof v === 'string') setFocusedProjectId(v);
|
||||||
|
}).catch(() => {});
|
||||||
|
const unsub = rvs.onStateChange(state => { if (state === 'connected') loadNames(); });
|
||||||
return () => unsub();
|
return () => unsub();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Focus in Storage spiegeln damit der letzte Kontext nach Neustart wieder
|
||||||
|
// da ist. Kein zwingender UX-Fix (Default = Hauptchat waere auch ok), aber
|
||||||
|
// fuer den Auto-Fall angenehm.
|
||||||
|
useEffect(() => {
|
||||||
|
AsyncStorage.setItem('aria_focused_project_id', focusedProjectId).catch(() => {});
|
||||||
|
}, [focusedProjectId]);
|
||||||
|
|
||||||
|
// Queue-Status alle 2s pollen — fuers Status-Dot im Focus-Header und
|
||||||
|
// fuer die Drawer-Anzeige. Nur wenn RVS verbunden ist (sonst 30s Timeout).
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
const poll = async () => {
|
||||||
|
if (rvs.getState() !== 'connected') return;
|
||||||
|
try {
|
||||||
|
const s = await brainApi.getProjectQueueStatus();
|
||||||
|
if (cancelled) return;
|
||||||
|
setQueueStatus(s.contexts || {});
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
poll();
|
||||||
|
const iv = setInterval(poll, 2000);
|
||||||
|
return () => { cancelled = true; clearInterval(iv); };
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadSettings = async () => {
|
const loadSettings = async () => {
|
||||||
const enabled = await AsyncStorage.getItem('aria_tts_enabled');
|
const enabled = await AsyncStorage.getItem('aria_tts_enabled');
|
||||||
@@ -757,6 +801,7 @@ const ChatScreen: React.FC = () => {
|
|||||||
timestamp: m.ts || Date.now(),
|
timestamp: m.ts || Date.now(),
|
||||||
attachments: attachments.length ? attachments : undefined,
|
attachments: attachments.length ? attachments : undefined,
|
||||||
backupTs: typeof m.ts === 'number' ? m.ts : undefined,
|
backupTs: typeof m.ts === 'number' ? m.ts : undefined,
|
||||||
|
projectId: typeof m.project_id === 'string' ? m.project_id : '',
|
||||||
...(cmid && { clientMsgId: cmid }),
|
...(cmid && { clientMsgId: cmid }),
|
||||||
// Server-Bubble = vom Brain verarbeitet → 'delivered' (✓✓)
|
// Server-Bubble = vom Brain verarbeitet → 'delivered' (✓✓)
|
||||||
...(role === 'user' && cmid && { deliveryStatus: 'delivered' as const }),
|
...(role === 'user' && cmid && { deliveryStatus: 'delivered' as const }),
|
||||||
@@ -812,12 +857,20 @@ const ChatScreen: React.FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// project_changed: ARIA hat in einem Tool-Call ein Projekt erstellt /
|
// project_changed: ARIA hat via Tool ein Projekt erstellt/betreten/exited/beendet.
|
||||||
// betreten / verlassen / beendet. Banner refreshen.
|
// App entscheidet ob sie den Focus wechselt basierend auf action + payload.
|
||||||
if (message.type === 'project_changed') {
|
if (message.type === 'project_changed') {
|
||||||
brainApi.getProjectStatus()
|
const p: any = message.payload || {};
|
||||||
.then(s => setActiveProject(s.active || null))
|
const action = p.action || '';
|
||||||
.catch(() => {});
|
// Neuer Projekt-Name in Lookup-Map merken
|
||||||
|
if (p.id && p.name) {
|
||||||
|
setProjectNameById(prev => ({ ...prev, [p.id]: p.name }));
|
||||||
|
}
|
||||||
|
if (action === 'entered' || action === 'created') {
|
||||||
|
if (p.id) setFocusedProjectId(p.id);
|
||||||
|
} else if (action === 'exited') {
|
||||||
|
setFocusedProjectId('');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1072,6 +1125,7 @@ const ChatScreen: React.FC = () => {
|
|||||||
attachments: message.payload.attachments as Attachment[] | undefined,
|
attachments: message.payload.attachments as Attachment[] | undefined,
|
||||||
messageId: (message.payload.messageId as string) || undefined,
|
messageId: (message.payload.messageId as string) || undefined,
|
||||||
backupTs: (message.payload.backupTs as number) || undefined,
|
backupTs: (message.payload.backupTs as number) || undefined,
|
||||||
|
projectId: ((message.payload as any).projectId as string) || '',
|
||||||
};
|
};
|
||||||
// ARIA hat geantwortet → alle User-Bubbles davor als 'delivered'
|
// ARIA hat geantwortet → alle User-Bubbles davor als 'delivered'
|
||||||
// markieren (WhatsApp-Doppelhaken ✓✓). Brain hat sie verarbeitet.
|
// markieren (WhatsApp-Doppelhaken ✓✓). Brain hat sie verarbeitet.
|
||||||
@@ -1614,7 +1668,17 @@ const ChatScreen: React.FC = () => {
|
|||||||
() => messages.filter(m => !m.memorySaved && !m.triggerCreated && !m.skillCreated),
|
() => messages.filter(m => !m.memorySaved && !m.triggerCreated && !m.skillCreated),
|
||||||
[messages],
|
[messages],
|
||||||
);
|
);
|
||||||
const invertedMessages = useMemo(() => [...chatVisibleMessages].reverse(), [chatVisibleMessages]);
|
|
||||||
|
// Focus-One-View (Multi-Threading, 06/2026): Chat zeigt NUR die Nachrichten
|
||||||
|
// des gerade fokussierten Kontexts. Hauptchat (focusedProjectId leer) →
|
||||||
|
// alle ungeтагtgeд Nachrichten. Projekt X aktiv → nur Nachrichten mit
|
||||||
|
// projectId === X. ARIA arbeitet weiterhin in allen Kontexten parallel;
|
||||||
|
// wir sehen nur den einen.
|
||||||
|
const messagesForRender = useMemo(() => {
|
||||||
|
return chatVisibleMessages.filter(m => (m.projectId || '') === focusedProjectId);
|
||||||
|
}, [chatVisibleMessages, focusedProjectId]);
|
||||||
|
|
||||||
|
const invertedMessages = useMemo(() => [...messagesForRender].reverse(), [messagesForRender]);
|
||||||
|
|
||||||
// Such-Treffer: alle Message-IDs die zur Query passen. NEUESTE ZUERST —
|
// Such-Treffer: alle Message-IDs die zur Query passen. NEUESTE ZUERST —
|
||||||
// analog zu WhatsApp/Telegram: User ist visuell unten im Chat, der erste
|
// analog zu WhatsApp/Telegram: User ist visuell unten im Chat, der erste
|
||||||
@@ -1816,6 +1880,7 @@ const ChatScreen: React.FC = () => {
|
|||||||
const location = await getCurrentLocation();
|
const location = await getCurrentLocation();
|
||||||
|
|
||||||
const cmid = nextClientMsgId();
|
const cmid = nextClientMsgId();
|
||||||
|
const activePid = focusedProjectId;
|
||||||
const userMsg: ChatMessage = {
|
const userMsg: ChatMessage = {
|
||||||
id: nextId(),
|
id: nextId(),
|
||||||
sender: 'user',
|
sender: 'user',
|
||||||
@@ -1824,16 +1889,18 @@ const ChatScreen: React.FC = () => {
|
|||||||
clientMsgId: cmid,
|
clientMsgId: cmid,
|
||||||
deliveryStatus: connectionStateRef.current === 'connected' ? 'sending' : 'queued',
|
deliveryStatus: connectionStateRef.current === 'connected' ? 'sending' : 'queued',
|
||||||
sendAttempts: 1,
|
sendAttempts: 1,
|
||||||
|
projectId: activePid,
|
||||||
};
|
};
|
||||||
setMessages(prev => capMessages([...prev, userMsg]));
|
setMessages(prev => capMessages([...prev, userMsg]));
|
||||||
|
|
||||||
console.log('[Chat] sende cmid=%s voice=%s speed=%s interrupted=%s',
|
console.log('[Chat] sende cmid=%s voice=%s speed=%s interrupted=%s project=%s',
|
||||||
cmid, localXttsVoiceRef.current || '(default)', ttsSpeedRef.current, wasInterrupted);
|
cmid, localXttsVoiceRef.current || '(default)', ttsSpeedRef.current, wasInterrupted, activePid || '(main)');
|
||||||
dispatchWithAck(cmid, 'chat', {
|
dispatchWithAck(cmid, 'chat', {
|
||||||
text,
|
text,
|
||||||
voice: localXttsVoiceRef.current,
|
voice: localXttsVoiceRef.current,
|
||||||
speed: ttsSpeedRef.current,
|
speed: ttsSpeedRef.current,
|
||||||
interrupted: wasInterrupted,
|
interrupted: wasInterrupted,
|
||||||
|
projectId: activePid,
|
||||||
...(location && { location }),
|
...(location && { location }),
|
||||||
});
|
});
|
||||||
}, [inputText, getCurrentLocation, pendingAttachments, sendPendingAttachments, interruptAriaIfBusy, dispatchWithAck]);
|
}, [inputText, getCurrentLocation, pendingAttachments, sendPendingAttachments, interruptAriaIfBusy, dispatchWithAck]);
|
||||||
@@ -2483,30 +2550,64 @@ const ChatScreen: React.FC = () => {
|
|||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
|
|
||||||
{/* Projekt-Indicator: zeigt Hauptchat oder aktives Projekt, Tap öffnet Liste */}
|
{/* Projekt-Indicator: zeigt Hauptchat oder aktives Projekt */}
|
||||||
<TouchableOpacity
|
{/* Focus-Indicator + Drawer-Toggle. Multi-Threading: das ist reine
|
||||||
onPress={() => setProjectsVisible(true)}
|
Anzeige „was sehe ich gerade" — ARIA arbeitet gleichzeitig in
|
||||||
style={{
|
allen Kontexten weiter, wir zeigen hier nur einen. */}
|
||||||
flexDirection: 'row', alignItems: 'center',
|
{(() => {
|
||||||
paddingHorizontal: 12, paddingVertical: 6,
|
const isMain = !focusedProjectId;
|
||||||
backgroundColor: activeProject ? 'rgba(52,199,89,0.10)' : 'transparent',
|
const focusedName = isMain ? '' : (projectNameById[focusedProjectId] || focusedProjectId);
|
||||||
borderBottomWidth: activeProject ? 2 : 1,
|
const focusedQueue = queueStatus[isMain ? '__main__' : focusedProjectId];
|
||||||
borderColor: activeProject ? '#34C759' : '#1E1E2E',
|
const dot = focusedQueue?.busy
|
||||||
}}
|
? { color: '#FF6E6E', label: 'arbeitet' }
|
||||||
>
|
: focusedQueue?.queue_size
|
||||||
<Text style={{ fontSize: 13, color: activeProject ? '#34C759' : '#8888AA', fontWeight: activeProject ? '700' : '500', flex: 1 }} numberOfLines={1}>
|
? { color: '#FFD60A', label: `Queue: ${focusedQueue.queue_size}` }
|
||||||
{activeProject ? `📁 ${activeProject.name}` : '💬 Hauptchat'}
|
: { color: '#34C759', label: 'idle' };
|
||||||
</Text>
|
// Anzahl anderer Kontexte die gerade aktiv sind (fuer Drawer-Badge)
|
||||||
<Text style={{ fontSize: 11, color: '#555570' }}>
|
const otherActive = Object.entries(queueStatus).filter(([k, v]) => {
|
||||||
{activeProject ? 'wechseln ›' : 'Projekte ›'}
|
const kFocus = isMain ? '__main__' : focusedProjectId;
|
||||||
</Text>
|
if (k === kFocus) return false;
|
||||||
</TouchableOpacity>
|
return v.busy || v.queue_size > 0;
|
||||||
|
}).length;
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row', alignItems: 'center',
|
||||||
|
paddingHorizontal: 12, paddingVertical: 8,
|
||||||
|
backgroundColor: isMain ? '#1A1A26' : 'rgba(52,199,89,0.10)',
|
||||||
|
borderBottomWidth: 2,
|
||||||
|
borderColor: isMain ? '#1E1E2E' : '#34C759',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => setProjectsVisible(true)}
|
||||||
|
style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}
|
||||||
|
hitSlop={{top:6,bottom:6,left:6,right:6}}
|
||||||
|
>
|
||||||
|
<Text style={{ fontSize: 20 }}>☰</Text>
|
||||||
|
{otherActive > 0 && (
|
||||||
|
<View style={{ backgroundColor: '#FF6E6E', borderRadius: 8, minWidth: 16, height: 16, paddingHorizontal: 4, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<Text style={{ color: '#fff', fontSize: 10, fontWeight: '700' }}>{otherActive}</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</TouchableOpacity>
|
||||||
|
<View style={{ flex: 1, marginLeft: 10, flexDirection: 'row', alignItems: 'center', gap: 8 }}>
|
||||||
|
<Text style={{ fontSize: 14, color: isMain ? '#E0E0F0' : '#34C759', fontWeight: '700', flex: 1 }} numberOfLines={1}>
|
||||||
|
{isMain ? '💬 Hauptchat' : `📁 ${focusedName}`}
|
||||||
|
</Text>
|
||||||
|
<View style={{ width: 8, height: 8, borderRadius: 4, backgroundColor: dot.color }} />
|
||||||
|
<Text style={{ fontSize: 10, color: '#8888AA' }}>{dot.label}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
|
||||||
{/* Projekt-Modal */}
|
{/* Projekt-Drawer als Modal */}
|
||||||
<ProjectsBrowser
|
<ProjectsBrowser
|
||||||
visible={projectsVisible}
|
visible={projectsVisible}
|
||||||
onClose={() => setProjectsVisible(false)}
|
onClose={() => setProjectsVisible(false)}
|
||||||
onActiveChanged={(p) => setActiveProject(p)}
|
onActiveChanged={(p) => setFocusedProjectId(p?.id || '')}
|
||||||
|
queueStatus={queueStatus}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Suchleiste mit Treffer-Navigation */}
|
{/* Suchleiste mit Treffer-Navigation */}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ import SkillBrowser from '../components/SkillBrowser';
|
|||||||
import OAuthBrowser from '../components/OAuthBrowser';
|
import OAuthBrowser from '../components/OAuthBrowser';
|
||||||
import VoiceIdEnrollment from '../components/VoiceIdEnrollment';
|
import VoiceIdEnrollment from '../components/VoiceIdEnrollment';
|
||||||
import ProjectsBrowser from '../components/ProjectsBrowser';
|
import ProjectsBrowser from '../components/ProjectsBrowser';
|
||||||
|
import brainApi from '../services/brainApi';
|
||||||
import { isVerboseLogging, setVerboseLogging, isDebugLogsToBridge, setDebugLogsToBridge, APP_LOG_EVENT } from '../services/logger';
|
import { isVerboseLogging, setVerboseLogging, isDebugLogsToBridge, setDebugLogsToBridge, APP_LOG_EVENT } from '../services/logger';
|
||||||
import {
|
import {
|
||||||
isWakeReadySoundEnabled,
|
isWakeReadySoundEnabled,
|
||||||
@@ -204,7 +205,9 @@ const SettingsScreen: React.FC = () => {
|
|||||||
const [availableVoices, setAvailableVoices] = useState<Array<{name: string, size: number}>>([]);
|
const [availableVoices, setAvailableVoices] = useState<Array<{name: string, size: number}>>([]);
|
||||||
// Datei-Manager
|
// Datei-Manager
|
||||||
const [fileManagerOpen, setFileManagerOpen] = useState(false);
|
const [fileManagerOpen, setFileManagerOpen] = useState(false);
|
||||||
const [fileManagerFiles, setFileManagerFiles] = useState<Array<{name: string; path: string; size: number; mtime: number; fromAria: boolean}>>([]);
|
const [fileManagerFiles, setFileManagerFiles] = useState<Array<{name: string; path: string; size: number; mtime: number; fromAria: boolean; projectId?: string}>>([]);
|
||||||
|
const [fileFilterProjectId, setFileFilterProjectId] = useState<string>('__all__');
|
||||||
|
const [fileFilterProjects, setFileFilterProjects] = useState<Array<{id: string; name: string}>>([]);
|
||||||
const [fileManagerLoading, setFileManagerLoading] = useState(false);
|
const [fileManagerLoading, setFileManagerLoading] = useState(false);
|
||||||
const [fileManagerError, setFileManagerError] = useState('');
|
const [fileManagerError, setFileManagerError] = useState('');
|
||||||
const [fileManagerSearch, setFileManagerSearch] = useState('');
|
const [fileManagerSearch, setFileManagerSearch] = useState('');
|
||||||
@@ -726,6 +729,20 @@ const SettingsScreen: React.FC = () => {
|
|||||||
return () => unsub();
|
return () => unsub();
|
||||||
}, [fileManagerOpen]);
|
}, [fileManagerOpen]);
|
||||||
|
|
||||||
|
// Beim Oeffnen des Datei-Managers: Projekt-Liste laden fuer den Filter.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!fileManagerOpen) return;
|
||||||
|
brainApi.listProjects(true)
|
||||||
|
.then(list => setFileFilterProjects(list.map(p => ({ id: p.id, name: p.name }))))
|
||||||
|
.catch(() => {});
|
||||||
|
// Default-Filter: fokussiertes Projekt aus AsyncStorage (falls Stefan
|
||||||
|
// grade in einem drin ist), sonst "alle". Multi-Threading: Focus ist
|
||||||
|
// App-lokal, kein Brain-Query mehr.
|
||||||
|
AsyncStorage.getItem('aria_focused_project_id')
|
||||||
|
.then(pid => { if (pid) setFileFilterProjectId(pid); })
|
||||||
|
.catch(() => {});
|
||||||
|
}, [fileManagerOpen]);
|
||||||
|
|
||||||
// --- QR-Code scannen ---
|
// --- QR-Code scannen ---
|
||||||
|
|
||||||
const openQRScanner = useCallback(() => {
|
const openQRScanner = useCallback(() => {
|
||||||
@@ -962,6 +979,29 @@ const SettingsScreen: React.FC = () => {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
{/* Projekt-Filter: scrollbare Pill-Reihe. „Alle Projekte" + „Hauptchat" +
|
||||||
|
ein Pill pro Projekt. Default = aktives Projekt (siehe useEffect oben). */}
|
||||||
|
<ScrollView horizontal showsHorizontalScrollIndicator={false}
|
||||||
|
style={{marginTop:6}} contentContainerStyle={{gap:6, paddingRight:8}}>
|
||||||
|
{[
|
||||||
|
{ id: '__all__', name: '📁 Alle Projekte' },
|
||||||
|
{ id: '', name: '💬 Hauptchat' },
|
||||||
|
...fileFilterProjects,
|
||||||
|
].map(p => (
|
||||||
|
<TouchableOpacity
|
||||||
|
key={p.id || 'mainchat'}
|
||||||
|
onPress={() => setFileFilterProjectId(p.id)}
|
||||||
|
style={{
|
||||||
|
paddingVertical:6, paddingHorizontal:12, borderRadius:14,
|
||||||
|
backgroundColor: fileFilterProjectId === p.id ? '#34C759' : '#1E1E2E',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={{color: fileFilterProjectId === p.id ? '#fff' : '#8888AA', fontSize:12}}>
|
||||||
|
{p.name}
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
))}
|
||||||
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
{fileManagerLoading ? (
|
{fileManagerLoading ? (
|
||||||
<Text style={{color:'#8888AA', textAlign:'center', marginTop:20}}>Lade...</Text>
|
<Text style={{color:'#8888AA', textAlign:'center', marginTop:20}}>Lade...</Text>
|
||||||
@@ -972,6 +1012,11 @@ const SettingsScreen: React.FC = () => {
|
|||||||
let files = fileManagerFiles;
|
let files = fileManagerFiles;
|
||||||
if (fileManagerFilter === 'aria') files = files.filter(f => f.fromAria);
|
if (fileManagerFilter === 'aria') files = files.filter(f => f.fromAria);
|
||||||
else if (fileManagerFilter === 'user') files = files.filter(f => !f.fromAria);
|
else if (fileManagerFilter === 'user') files = files.filter(f => !f.fromAria);
|
||||||
|
// Projekt-Filter: '__all__' = alles, '' = Hauptchat (kein project_id),
|
||||||
|
// sonst exakte project_id-Match.
|
||||||
|
if (fileFilterProjectId !== '__all__') {
|
||||||
|
files = files.filter(f => (f.projectId || '') === fileFilterProjectId);
|
||||||
|
}
|
||||||
if (fileManagerSearch) {
|
if (fileManagerSearch) {
|
||||||
const q = fileManagerSearch.toLowerCase();
|
const q = fileManagerSearch.toLowerCase();
|
||||||
files = files.filter(f => f.name.toLowerCase().includes(q));
|
files = files.filter(f => f.name.toLowerCase().includes(q));
|
||||||
|
|||||||
@@ -169,6 +169,16 @@ export interface ProjectStatus {
|
|||||||
projects: Project[];
|
projects: Project[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Queue-Status pro Kontext — was gerade arbeitet, was wartet.
|
||||||
|
* Key "__main__" = Hauptchat, sonst project_id. */
|
||||||
|
export interface QueueContextStatus {
|
||||||
|
busy: boolean;
|
||||||
|
queue_size: number;
|
||||||
|
}
|
||||||
|
export interface ProjectQueueStatus {
|
||||||
|
contexts: Record<string, QueueContextStatus>;
|
||||||
|
}
|
||||||
|
|
||||||
/** Skill-Manifest wie aus Brain `/skills/list` zurueckkommt. */
|
/** Skill-Manifest wie aus Brain `/skills/list` zurueckkommt. */
|
||||||
export interface Skill {
|
export interface Skill {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -590,6 +600,13 @@ export const brainApi = {
|
|||||||
body: patch,
|
body: patch,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** Queue-Status: pro Kontext (project_id oder __main__ fuer Hauptchat)
|
||||||
|
* ob gerade ein Request in Verarbeitung ist + wieviele in der Queue warten.
|
||||||
|
* Wird fuer Status-Dots im Drawer periodisch gepollt. */
|
||||||
|
getProjectQueueStatus(): Promise<ProjectQueueStatus> {
|
||||||
|
return _send('/projects/queue-status');
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default brainApi;
|
export default brainApi;
|
||||||
|
|||||||
+66
-29
@@ -836,10 +836,14 @@ META_TOOLS = [
|
|||||||
"function": {
|
"function": {
|
||||||
"name": "project_enter",
|
"name": "project_enter",
|
||||||
"description": (
|
"description": (
|
||||||
"Wechselt in ein bestehendes Projekt. Fuzzy-Match auf Namen — "
|
"Signalisiert der App/Diagnostic 'wechsel zu diesem Projekt'. Fuzzy-"
|
||||||
"'Spotify' findet das Projekt 'Spotify-Setup'. Nach dem Eintritt "
|
"Match auf Namen — 'Spotify' findet das Projekt 'Spotify-Setup'. "
|
||||||
"tagged jeder neue Turn die project_id. Bei sehr alten Projekten: "
|
"Der AKTUELLE Turn bleibt aber in seinem Chat-Kontext — wir haben "
|
||||||
"vorher project_summary aufrufen damit Du Stefan abholst."
|
"Multi-Threading, kein globales 'aktives Projekt' mehr. Wenn Stefan "
|
||||||
|
"im Hauptchat sagt 'lass uns in Spotify weiter machen': "
|
||||||
|
"project_enter aufrufen (App wechselt Ansicht), aber Deine Antwort "
|
||||||
|
"geht trotzdem im Hauptchat raus. Bei sehr alten Projekten vorher "
|
||||||
|
"project_summary aufrufen damit Du Stefan abholst."
|
||||||
),
|
),
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@@ -855,8 +859,10 @@ META_TOOLS = [
|
|||||||
"function": {
|
"function": {
|
||||||
"name": "project_exit",
|
"name": "project_exit",
|
||||||
"description": (
|
"description": (
|
||||||
"Verlässt das aktuelle Projekt — zurück zum Hauptthread. Nutze "
|
"Signalisiert der App/Diagnostic 'wechsel zurueck zum Hauptchat'. "
|
||||||
"wenn Stefan sagt 'Projekt Ende', 'zurück zum Hauptchat' o.ä."
|
"Nutze wenn Stefan sagt 'Projekt Ende' oder 'zurueck zum Hauptchat' "
|
||||||
|
"waehrend er visuell in einem Projekt ist. Der aktuelle Turn bleibt "
|
||||||
|
"in seinem Chat-Kontext — Multi-Threading."
|
||||||
),
|
),
|
||||||
"parameters": {"type": "object", "properties": {}},
|
"parameters": {"type": "object", "properties": {}},
|
||||||
},
|
},
|
||||||
@@ -1051,7 +1057,21 @@ class Agent:
|
|||||||
|
|
||||||
MAX_TOOL_ITERATIONS = 8 # Schutz vor Endlos-Loops
|
MAX_TOOL_ITERATIONS = 8 # Schutz vor Endlos-Loops
|
||||||
|
|
||||||
def chat(self, user_message: str, source: str = "") -> str:
|
def chat(self, user_message: str, source: str = "",
|
||||||
|
project_id: Optional[str] = None,
|
||||||
|
pending_queue: Optional[list[str]] = None) -> str:
|
||||||
|
"""Verarbeitet eine User-Nachricht — pro Request project_id explizit
|
||||||
|
angegeben (leer = Hauptchat). Kein globaler active_project-State mehr —
|
||||||
|
so laufen parallele /chat-Requests fuer verschiedene Projekte echt
|
||||||
|
parallel (Multi-Threading-Architektur seit 06/2026).
|
||||||
|
|
||||||
|
pending_queue: Liste weiterer User-Nachrichten die in DIESEM Projekt
|
||||||
|
NACH dem aktuellen Turn warten. ARIA sieht sie im System-Prompt und
|
||||||
|
soll pruefen ob eine spaetere Nachricht den aktuellen Task
|
||||||
|
korrigiert / annuliert (dann Skip-Antwort statt Ausfuehren).
|
||||||
|
|
||||||
|
Wenn project_id=None (Backward-Compat fuer Aufrufer die den Param nicht
|
||||||
|
setzen): wird als Hauptchat behandelt."""
|
||||||
user_message = (user_message or "").strip()
|
user_message = (user_message or "").strip()
|
||||||
if not user_message:
|
if not user_message:
|
||||||
raise ValueError("Leere Nachricht")
|
raise ValueError("Leere Nachricht")
|
||||||
@@ -1059,9 +1079,8 @@ class Agent:
|
|||||||
# Events vom letzten Turn weglassen
|
# Events vom letzten Turn weglassen
|
||||||
self._pending_events = []
|
self._pending_events = []
|
||||||
|
|
||||||
# Aktives Projekt (leer = Hauptthread) — bestimmt das Tagging der
|
# Projekt-Kontext pro Request statt aus globalem State
|
||||||
# neuen Turns + das Conversation-Window-Filter fuer den LLM-Prompt.
|
active_project_id = (project_id or "").strip()
|
||||||
active_project_id = projects_mod.get_active()
|
|
||||||
active_project = projects_mod.get_project(active_project_id) if active_project_id else None
|
active_project = projects_mod.get_project(active_project_id) if active_project_id else None
|
||||||
|
|
||||||
# Fast-Path: einfache "reines Steuern"-Commands ueberspringen Claude komplett.
|
# Fast-Path: einfache "reines Steuern"-Commands ueberspringen Claude komplett.
|
||||||
@@ -1127,6 +1146,28 @@ class Agent:
|
|||||||
oauth_callback_host=oauth_host,
|
oauth_callback_host=oauth_host,
|
||||||
oauth_callback_port=oauth_port,
|
oauth_callback_port=oauth_port,
|
||||||
oauth_callback_tls=oauth_tls)
|
oauth_callback_tls=oauth_tls)
|
||||||
|
# Queue-Aware Prompting: wenn nach diesem Turn weitere Nachrichten
|
||||||
|
# in der Warteschlange liegen, muss ARIA pruefen ob eine spaetere die
|
||||||
|
# aktuelle Aufgabe korrigiert/annuliert (→ Skip statt Doppelarbeit).
|
||||||
|
if pending_queue:
|
||||||
|
queue_lines = "\n".join(f" - {m[:280]}" for m in pending_queue[:5])
|
||||||
|
more_hint = ""
|
||||||
|
if len(pending_queue) > 5:
|
||||||
|
more_hint = f"\n ... und {len(pending_queue) - 5} weitere"
|
||||||
|
system_prompt += (
|
||||||
|
f"\n\n## QUEUE — NACH DIESEM TASK WARTEN\n"
|
||||||
|
f"{queue_lines}{more_hint}\n"
|
||||||
|
f"\nBEVOR DU DEN AKTUELLEN TASK LOESST:\n"
|
||||||
|
f" 1. Pruefe die Queue oben — widerspricht/annuliert eine der spaeteren "
|
||||||
|
f"Nachrichten den aktuellen Task?\n"
|
||||||
|
f" 2. Wenn ja: antworte ganz kurz 'Task ubersprungen — wird durch spaetere "
|
||||||
|
f"Nachricht korrigiert' und mach KEINE Aktion. Der spaetere Task laeuft dann "
|
||||||
|
f"ganz normal als naechste Anfrage durch.\n"
|
||||||
|
f" 3. Wenn nein / unabhaengige Ergaenzung: Task normal loesen.\n"
|
||||||
|
f"Beispiel: aktueller Task 'titelleiste rot', Queue enthaelt "
|
||||||
|
f"'doch nicht, mach sie blau' → skip, blau kommt als naechste Anfrage."
|
||||||
|
)
|
||||||
|
|
||||||
# Aktuelle Projekt-Bühne als System-Hinweis ergaenzen, damit Claude
|
# Aktuelle Projekt-Bühne als System-Hinweis ergaenzen, damit Claude
|
||||||
# weiss in welchem Kontext sie spricht und ihre project_* Tools korrekt
|
# weiss in welchem Kontext sie spricht und ihre project_* Tools korrekt
|
||||||
# einsetzt (z.B. bei „Projekt Ende" project_exit aufruft).
|
# einsetzt (z.B. bei „Projekt Ende" project_exit aufruft).
|
||||||
@@ -1217,19 +1258,17 @@ class Agent:
|
|||||||
err_text = f"[Fehler: {exc}]"
|
err_text = f"[Fehler: {exc}]"
|
||||||
logger.error("chat() Exception — schreibe Error-Marker als Assistant-Turn: %s", exc)
|
logger.error("chat() Exception — schreibe Error-Marker als Assistant-Turn: %s", exc)
|
||||||
try:
|
try:
|
||||||
# Aktive Projekt-ID NEU lesen — kann sich waehrend des Tool-Loops
|
# Turn-Kontext bleibt gleich — es gibt keinen globalen Wechsel
|
||||||
# geaendert haben (project_enter/exit als Tool-Call).
|
# mehr, jeder Request laeuft in seinem eigenen project_id-Kontext.
|
||||||
self.conversation.add("assistant", err_text,
|
self.conversation.add("assistant", err_text,
|
||||||
project_id=projects_mod.get_active())
|
project_id=active_project_id)
|
||||||
except Exception as add_exc:
|
except Exception as add_exc:
|
||||||
logger.warning("Konnte Error-Marker nicht persistieren: %s", add_exc)
|
logger.warning("Konnte Error-Marker nicht persistieren: %s", add_exc)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# 7. Assistant-Turn (final reply) in die Conversation
|
# 7. Assistant-Turn (final reply) in die Conversation
|
||||||
# NEU lesen — wenn der LLM project_enter/exit gerufen hat, ist der
|
|
||||||
# Final-Reply schon im neuen Projekt-Kontext.
|
|
||||||
self.conversation.add("assistant", final_reply,
|
self.conversation.add("assistant", final_reply,
|
||||||
project_id=projects_mod.get_active())
|
project_id=active_project_id)
|
||||||
return final_reply
|
return final_reply
|
||||||
|
|
||||||
# ── Tool-Dispatcher ───────────────────────────────────────
|
# ── Tool-Dispatcher ───────────────────────────────────────
|
||||||
@@ -1804,7 +1843,10 @@ class Agent:
|
|||||||
"project": p,
|
"project": p,
|
||||||
"action": "created",
|
"action": "created",
|
||||||
})
|
})
|
||||||
return f"OK — Projekt '{p['name']}' angelegt (id={p['id']}) und aktiv. Alle weiteren Turns gehen jetzt da rein bis Du project_exit oder project_enter aufrufst."
|
return (f"OK — Projekt '{p['name']}' angelegt (id={p['id']}). App/Diagnostic "
|
||||||
|
f"kriegen ein project_changed-Event und koennen dahin wechseln. "
|
||||||
|
f"Kommender Turn bleibt aber im aktuellen Chat-Kontext — "
|
||||||
|
f"Multi-Threading, jeder Chat ist eigenstaendig.")
|
||||||
if name == "project_enter":
|
if name == "project_enter":
|
||||||
pname = (arguments.get("name") or "").strip()
|
pname = (arguments.get("name") or "").strip()
|
||||||
if not pname:
|
if not pname:
|
||||||
@@ -1812,7 +1854,6 @@ class Agent:
|
|||||||
p = projects_mod.find_project(pname)
|
p = projects_mod.find_project(pname)
|
||||||
if not p:
|
if not p:
|
||||||
return f"Kein Projekt '{pname}' gefunden. Nutze project_list zum Aufzaehlen oder project_create wenn's neu sein soll."
|
return f"Kein Projekt '{pname}' gefunden. Nutze project_list zum Aufzaehlen oder project_create wenn's neu sein soll."
|
||||||
projects_mod.set_active(p["id"])
|
|
||||||
self._pending_events.append({
|
self._pending_events.append({
|
||||||
"type": "project_changed",
|
"type": "project_changed",
|
||||||
"project": p,
|
"project": p,
|
||||||
@@ -1822,31 +1863,27 @@ class Agent:
|
|||||||
hint = ""
|
hint = ""
|
||||||
if turn_count > 0:
|
if turn_count > 0:
|
||||||
hint = " Wenn Stefan nach dem Stand fragt: project_summary aufrufen."
|
hint = " Wenn Stefan nach dem Stand fragt: project_summary aufrufen."
|
||||||
return f"OK — in Projekt '{p['name']}' eingestiegen (id={p['id']}, {turn_count} bisherige Turns).{hint}"
|
return (f"OK — App/Diagnostic wird zum Projekt '{p['name']}' "
|
||||||
|
f"(id={p['id']}, {turn_count} bisherige Turns) umschalten. "
|
||||||
|
f"Der aktuelle Turn bleibt aber im aktuellen Chat-Kontext.{hint}")
|
||||||
if name == "project_exit":
|
if name == "project_exit":
|
||||||
active_id = projects_mod.get_active()
|
|
||||||
if not active_id:
|
|
||||||
return "Es ist gerade kein Projekt aktiv — bereits im Hauptthread."
|
|
||||||
p = projects_mod.get_project(active_id)
|
|
||||||
projects_mod.set_active("")
|
|
||||||
self._pending_events.append({
|
self._pending_events.append({
|
||||||
"type": "project_changed",
|
"type": "project_changed",
|
||||||
"project": p,
|
"project": None,
|
||||||
"action": "exited",
|
"action": "exited",
|
||||||
})
|
})
|
||||||
return f"OK — Projekt '{p['name'] if p else active_id}' verlassen. Zurueck im Hauptthread."
|
return ("OK — App/Diagnostic bekommt Signal 'zurueck zum Hauptchat'. "
|
||||||
|
"Der aktuelle Turn bleibt aber im aktuellen Chat-Kontext.")
|
||||||
if name == "project_list":
|
if name == "project_list":
|
||||||
items = projects_mod.list_projects()
|
items = projects_mod.list_projects()
|
||||||
if not items:
|
if not items:
|
||||||
return "(keine Projekte angelegt)"
|
return "(keine Projekte angelegt)"
|
||||||
active_id = projects_mod.get_active()
|
|
||||||
lines = []
|
lines = []
|
||||||
for p in items:
|
for p in items:
|
||||||
marker = " ← AKTIV" if p["id"] == active_id else ""
|
|
||||||
status_lbl = p.get("status", "active")
|
status_lbl = p.get("status", "active")
|
||||||
lines.append(
|
lines.append(
|
||||||
f"- {p['name']} (id={p['id']}, {p.get('turn_count', 0)} Turns, "
|
f"- {p['name']} (id={p['id']}, {p.get('turn_count', 0)} Turns, "
|
||||||
f"status={status_lbl}){marker}"
|
f"status={status_lbl})"
|
||||||
)
|
)
|
||||||
return "Projekte:\n" + "\n".join(lines)
|
return "Projekte:\n" + "\n".join(lines)
|
||||||
if name == "project_summary":
|
if name == "project_summary":
|
||||||
|
|||||||
+118
-19
@@ -607,6 +607,11 @@ def memory_import_bootstrap(body: BootstrapBundle):
|
|||||||
class ChatIn(BaseModel):
|
class ChatIn(BaseModel):
|
||||||
message: str
|
message: str
|
||||||
source: str = "" # "app" / "diagnostic" / "stt" — optional
|
source: str = "" # "app" / "diagnostic" / "stt" — optional
|
||||||
|
# Multi-Threading: Client bestimmt pro Request welches Projekt (leer = Hauptchat).
|
||||||
|
# Kein globaler active_project-State mehr im Brain — parallele Requests fuer
|
||||||
|
# verschiedene Projekte laufen echt parallel, nur Requests fuers gleiche
|
||||||
|
# Projekt queuen (per-Projekt-Lock).
|
||||||
|
project_id: str = ""
|
||||||
|
|
||||||
|
|
||||||
class ChatOut(BaseModel):
|
class ChatOut(BaseModel):
|
||||||
@@ -614,30 +619,124 @@ class ChatOut(BaseModel):
|
|||||||
turns: int
|
turns: int
|
||||||
distilling: bool
|
distilling: bool
|
||||||
events: list = Field(default_factory=list)
|
events: list = Field(default_factory=list)
|
||||||
|
# Echo der project_id die dieser Turn hatte. Bridge nutzt sie damit die
|
||||||
|
# ausgehende Chat-Bubble sauber getaggt in der richtigen Thread-Bahn der
|
||||||
|
# UI landet.
|
||||||
|
project_id: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
# Per-Projekt async-Locks fuer Queue-Behavior: Requests fuers gleiche Projekt
|
||||||
|
# warten aufeinander (queue), Requests fuer verschiedene Projekte laufen echt
|
||||||
|
# parallel. Hauptchat = Lock unter key "" (leerer String).
|
||||||
|
_project_locks: dict[str, asyncio.Lock] = {}
|
||||||
|
_project_locks_meta_lock = asyncio.Lock()
|
||||||
|
# Pro Projekt eine Liste noch-nicht-verarbeiteter Requests. Wird beim Enqueue
|
||||||
|
# ergaenzt, beim Fertig-Werden gepoppt. Ermoeglicht Queue-Aware-Prompting:
|
||||||
|
# waehrend ARIA an Task N arbeitet, sieht sie N+1..N+k als System-Prompt-Hinweis
|
||||||
|
# und kann entscheiden ob eine spaetere Nachricht die aktuelle korrigiert/
|
||||||
|
# annuliert → dann Skip-Antwort statt Ausfuehren.
|
||||||
|
_project_pending: dict[str, list[dict]] = {}
|
||||||
|
|
||||||
|
|
||||||
|
async def _get_project_lock(project_id: str) -> asyncio.Lock:
|
||||||
|
"""Holt (oder erzeugt) den asyncio.Lock fuer ein bestimmtes Projekt.
|
||||||
|
Nutzt _project_locks_meta_lock zur Vermeidung von Race Conditions
|
||||||
|
beim ersten-Zugriff pro Projekt."""
|
||||||
|
async with _project_locks_meta_lock:
|
||||||
|
lock = _project_locks.get(project_id)
|
||||||
|
if lock is None:
|
||||||
|
lock = asyncio.Lock()
|
||||||
|
_project_locks[project_id] = lock
|
||||||
|
return lock
|
||||||
|
|
||||||
|
|
||||||
|
def _project_queue_snapshot() -> dict:
|
||||||
|
"""Snapshot fuer /projects/queue-status: welche Projekte arbeiten gerade,
|
||||||
|
wieviele wait-in-queue haben, welche sind idle."""
|
||||||
|
out = {}
|
||||||
|
# Zeige nur Kontexte mit Aktivitaet — locked oder pending
|
||||||
|
seen: set = set()
|
||||||
|
for pid, lock in _project_locks.items():
|
||||||
|
pending = len(_project_pending.get(pid, []))
|
||||||
|
is_busy = lock.locked()
|
||||||
|
# busy: gerade in Verarbeitung. queue: N weitere warten dahinter.
|
||||||
|
# Der Busy-Request zaehlt NICHT in queue (er ist ja aus pending schon "raus").
|
||||||
|
out[pid or "__main__"] = {
|
||||||
|
"busy": is_busy,
|
||||||
|
"queue_size": max(0, pending - (1 if is_busy else 0)),
|
||||||
|
}
|
||||||
|
seen.add(pid)
|
||||||
|
for pid, pend in _project_pending.items():
|
||||||
|
if pid in seen:
|
||||||
|
continue
|
||||||
|
out[pid or "__main__"] = {"busy": False, "queue_size": len(pend)}
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
@app.post("/chat", response_model=ChatOut)
|
@app.post("/chat", response_model=ChatOut)
|
||||||
def chat(body: ChatIn, background: BackgroundTasks):
|
async def chat(body: ChatIn, background: BackgroundTasks):
|
||||||
"""Hauptpfad. Antwort kommt synchron. Memory-Destillat laeuft
|
"""Hauptpfad. Antwort kommt synchron. Memory-Destillat laeuft
|
||||||
im Hintergrund nachdem die Response rausging."""
|
im Hintergrund nachdem die Response rausging.
|
||||||
a = agent()
|
|
||||||
try:
|
|
||||||
reply = a.chat(body.message, source=body.source)
|
|
||||||
except ValueError as exc:
|
|
||||||
raise HTTPException(400, str(exc))
|
|
||||||
except RuntimeError as exc:
|
|
||||||
logger.error("chat fehlgeschlagen: %s", exc)
|
|
||||||
raise HTTPException(502, str(exc))
|
|
||||||
|
|
||||||
needs_distill = a.conversation.needs_distill()
|
Multi-Threading: Requests fuers gleiche Projekt (project_id gleich)
|
||||||
if needs_distill:
|
laufen serialisiert durch den per-Projekt-Lock — Queue-Behavior.
|
||||||
background.add_task(a.distill_old_turns)
|
Verschiedene Projekte laufen parallel."""
|
||||||
return ChatOut(
|
pid = (body.project_id or "").strip()
|
||||||
reply=reply,
|
lock = await _get_project_lock(pid)
|
||||||
turns=len(a.conversation.turns),
|
# Vor dem Lock in die Pending-Liste, damit die verlaufende Task sehen kann
|
||||||
distilling=needs_distill,
|
# was NACH ihr in der Warteschlange steht (Queue-Aware Prompting).
|
||||||
events=a.pop_events(),
|
import uuid as _uuid
|
||||||
)
|
req_id = _uuid.uuid4().hex
|
||||||
|
_project_pending.setdefault(pid, []).append({
|
||||||
|
"id": req_id, "message": body.message, "source": body.source,
|
||||||
|
})
|
||||||
|
try:
|
||||||
|
async with lock:
|
||||||
|
# Snapshot: was liegt NACH mir in der Queue?
|
||||||
|
after_me = [
|
||||||
|
e["message"] for e in _project_pending.get(pid, [])
|
||||||
|
if e["id"] != req_id
|
||||||
|
]
|
||||||
|
a = agent()
|
||||||
|
try:
|
||||||
|
# Sync-Aufruf im Executor damit wir den Event-Loop nicht blocken —
|
||||||
|
# chat() macht HTTP-Calls (Proxy) die 30-60s dauern koennen.
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
reply = await loop.run_in_executor(
|
||||||
|
None,
|
||||||
|
lambda: a.chat(
|
||||||
|
body.message, source=body.source, project_id=pid,
|
||||||
|
pending_queue=after_me,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise HTTPException(400, str(exc))
|
||||||
|
except RuntimeError as exc:
|
||||||
|
logger.error("chat fehlgeschlagen: %s", exc)
|
||||||
|
raise HTTPException(502, str(exc))
|
||||||
|
|
||||||
|
needs_distill = a.conversation.needs_distill()
|
||||||
|
if needs_distill:
|
||||||
|
background.add_task(a.distill_old_turns)
|
||||||
|
return ChatOut(
|
||||||
|
reply=reply,
|
||||||
|
turns=len(a.conversation.turns),
|
||||||
|
distilling=needs_distill,
|
||||||
|
events=a.pop_events(),
|
||||||
|
project_id=pid,
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
_project_pending[pid] = [
|
||||||
|
e for e in _project_pending.get(pid, []) if e["id"] != req_id
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/projects/queue-status")
|
||||||
|
def projects_queue_status():
|
||||||
|
"""Snapshot: fuer jeden Projekt-Kontext (inkl. Hauptchat unter __main__)
|
||||||
|
- busy: True wenn gerade ein Request in Verarbeitung
|
||||||
|
- queue_size: wieviele weitere warten dahinter"""
|
||||||
|
return {"contexts": _project_queue_snapshot()}
|
||||||
|
|
||||||
|
|
||||||
# ── Projekte ────────────────────────────────────────────────────────
|
# ── Projekte ────────────────────────────────────────────────────────
|
||||||
|
|||||||
+200
-7
@@ -611,6 +611,13 @@ class ARIABridge:
|
|||||||
self._last_chat_final_at: float = 0.0
|
self._last_chat_final_at: float = 0.0
|
||||||
# requestId → messageId Map fuer XTTS-Audio-Cache (App-seitige Zuordnung)
|
# requestId → messageId Map fuer XTTS-Audio-Cache (App-seitige Zuordnung)
|
||||||
self._xtts_request_to_message: dict[str, str] = {}
|
self._xtts_request_to_message: dict[str, str] = {}
|
||||||
|
# Voice-Router (Multi-Threading, 06/2026): sticky Projekt-Kontext fuer
|
||||||
|
# STT-Voice-Nachrichten. Wechselt via „fuer <name>:"-Prefix, faellt nach
|
||||||
|
# STICKY_TIMEOUT_SEC ohne neue Voice-Message zurueck auf Hauptchat.
|
||||||
|
# Meta-Kommandos („zurueck zum hauptchat") werden client-seitig
|
||||||
|
# interceptiert und aendern hier den Sticky OHNE Brain-Roundtrip.
|
||||||
|
self._voice_sticky_project_id: str = ""
|
||||||
|
self._voice_sticky_expires_at: float = 0.0
|
||||||
# Voice-Override aus letzter Chat-Nachricht einer App.
|
# Voice-Override aus letzter Chat-Nachricht einer App.
|
||||||
# Wird fuer die direkt folgende ARIA-Antwort genutzt und dann zurueckgesetzt.
|
# Wird fuer die direkt folgende ARIA-Antwort genutzt und dann zurueckgesetzt.
|
||||||
# So kann jedes Geraet seine bevorzugte Stimme bekommen (pro Request).
|
# So kann jedes Geraet seine bevorzugte Stimme bekommen (pro Request).
|
||||||
@@ -1005,6 +1012,50 @@ class ARIABridge:
|
|||||||
cleaned = re.sub(r"\n{3,}", "\n\n", cleaned)
|
cleaned = re.sub(r"\n{3,}", "\n\n", cleaned)
|
||||||
return cleaned, files, missing
|
return cleaned, files, missing
|
||||||
|
|
||||||
|
def _tag_file_to_project(self, file_path: str, project_id: str) -> None:
|
||||||
|
"""Schreibt file_path → project_id in /shared/config/file_projects.json.
|
||||||
|
Best-effort, fail-silent. project_id leer = Eintrag entfernen (Hauptchat)."""
|
||||||
|
try:
|
||||||
|
manifest_path = "/shared/config/file_projects.json"
|
||||||
|
os.makedirs("/shared/config", exist_ok=True)
|
||||||
|
try:
|
||||||
|
with open(manifest_path) as f:
|
||||||
|
manifest = json.load(f)
|
||||||
|
if not isinstance(manifest, dict):
|
||||||
|
manifest = {}
|
||||||
|
except FileNotFoundError:
|
||||||
|
manifest = {}
|
||||||
|
except Exception:
|
||||||
|
manifest = {}
|
||||||
|
if project_id:
|
||||||
|
manifest[file_path] = project_id
|
||||||
|
else:
|
||||||
|
manifest.pop(file_path, None)
|
||||||
|
tmp = manifest_path + ".tmp"
|
||||||
|
with open(tmp, "w") as f:
|
||||||
|
json.dump(manifest, f, indent=2, ensure_ascii=False)
|
||||||
|
os.replace(tmp, manifest_path)
|
||||||
|
logger.info("[file-project] %s → %s", file_path, project_id or "(main)")
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning("[file-project] tag failed (%s): %s", file_path, exc)
|
||||||
|
|
||||||
|
def _tag_file_to_active_project(self, file_path: str) -> None:
|
||||||
|
"""Convenience: Brain nach aktivem Projekt fragen + taggen.
|
||||||
|
Wird vom App-Upload-Handler genutzt (dort wissen wir die Projekt-ID
|
||||||
|
noch nicht aus dem Payload — Stefan kann ja zwischen App-Upload und
|
||||||
|
Chat-Send das Projekt gewechselt haben). ARIA-eigene Dateien gehen
|
||||||
|
ueber _tag_file_to_project mit turn_project_id direkt."""
|
||||||
|
try:
|
||||||
|
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
||||||
|
with urllib.request.urlopen(f"{brain_url}/projects/status", timeout=5) as r:
|
||||||
|
data = json.loads(r.read())
|
||||||
|
active_id = (data.get("active_id") or "").strip()
|
||||||
|
if not active_id:
|
||||||
|
return
|
||||||
|
self._tag_file_to_project(file_path, active_id)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning("[file-project] active-query failed (%s): %s", file_path, exc)
|
||||||
|
|
||||||
async def _broadcast_aria_file(self, file_info: dict) -> None:
|
async def _broadcast_aria_file(self, file_info: dict) -> None:
|
||||||
"""ARIA hat eine Datei fuer den User erstellt — App+Diagnostic informieren."""
|
"""ARIA hat eine Datei fuer den User erstellt — App+Diagnostic informieren."""
|
||||||
logger.info("[rvs] ARIA-Datei rausgeben: %s (%s, %dKB)",
|
logger.info("[rvs] ARIA-Datei rausgeben: %s (%s, %dKB)",
|
||||||
@@ -1163,7 +1214,15 @@ class ARIABridge:
|
|||||||
# Der Marker wird aus dem Antworttext entfernt (TTS soll ihn nicht
|
# Der Marker wird aus dem Antworttext entfernt (TTS soll ihn nicht
|
||||||
# vorlesen) und parallel als file_from_aria-Event geschickt.
|
# vorlesen) und parallel als file_from_aria-Event geschickt.
|
||||||
text, aria_files, missing_files = self._extract_file_markers(text)
|
text, aria_files, missing_files = self._extract_file_markers(text)
|
||||||
|
# ARIA-Dateien dem aktiven Projekt zuordnen (falls eines aktiv war).
|
||||||
|
# turn_project_id kommt vom Brain mit dem /chat-Response und reflektiert
|
||||||
|
# den Stand NACH dem Turn — passt fuer Dateien die ARIA waehrend des
|
||||||
|
# Turns geschrieben hat (sie sind „im selben Projekt entstanden").
|
||||||
|
turn_pid = (payload.get("projectId") or "").strip() if isinstance(payload, dict) else ""
|
||||||
for f in aria_files:
|
for f in aria_files:
|
||||||
|
server_path = f.get("serverPath")
|
||||||
|
if turn_pid and server_path:
|
||||||
|
self._tag_file_to_project(server_path, turn_pid)
|
||||||
await self._broadcast_aria_file(f)
|
await self._broadcast_aria_file(f)
|
||||||
# Bei fehlenden Files: User informieren (sonst sieht er nur stille
|
# Bei fehlenden Files: User informieren (sonst sieht er nur stille
|
||||||
# Verluste — ARIA hat den Marker hingeschrieben aber das File nicht
|
# Verluste — ARIA hat den Marker hingeschrieben aber das File nicht
|
||||||
@@ -1185,6 +1244,7 @@ class ARIABridge:
|
|||||||
"text": display_text,
|
"text": display_text,
|
||||||
"files": [{"serverPath": f["serverPath"], "name": f["name"],
|
"files": [{"serverPath": f["serverPath"], "name": f["name"],
|
||||||
"mimeType": f["mimeType"], "size": f["size"]} for f in aria_files],
|
"mimeType": f["mimeType"], "size": f["size"]} for f in aria_files],
|
||||||
|
"project_id": turn_pid,
|
||||||
})
|
})
|
||||||
|
|
||||||
metadata = payload.get("metadata", {})
|
metadata = payload.get("metadata", {})
|
||||||
@@ -1224,6 +1284,9 @@ class ARIABridge:
|
|||||||
"backupTs": assistant_backup_ts,
|
"backupTs": assistant_backup_ts,
|
||||||
# Debug: aufbereiteter Text fuer TTS (App ignoriert, Diagnostic zeigt optional)
|
# Debug: aufbereiteter Text fuer TTS (App ignoriert, Diagnostic zeigt optional)
|
||||||
"ttsText": tts_text_preview if tts_text_preview != text else "",
|
"ttsText": tts_text_preview if tts_text_preview != text else "",
|
||||||
|
# Projekt-Zuordnung — App + Diagnostic sortieren die Bubble in
|
||||||
|
# den passenden Projekt-Block. Leer = Hauptchat.
|
||||||
|
"projectId": (payload.get("projectId") or "") if isinstance(payload, dict) else "",
|
||||||
},
|
},
|
||||||
"timestamp": int(asyncio.get_event_loop().time() * 1000),
|
"timestamp": int(asyncio.get_event_loop().time() * 1000),
|
||||||
})
|
})
|
||||||
@@ -1454,7 +1517,9 @@ class ARIABridge:
|
|||||||
asyncio.create_task(self.send_to_core(text, source="app-file+chat"))
|
asyncio.create_task(self.send_to_core(text, source="app-file+chat"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def send_to_core(self, text: str, source: str = "bridge", client_msg_id: Optional[str] = None) -> None:
|
async def send_to_core(self, text: str, source: str = "bridge",
|
||||||
|
client_msg_id: Optional[str] = None,
|
||||||
|
project_id: str = "") -> None:
|
||||||
"""Sendet Text an aria-brain (HTTP /chat) und broadcastet die Antwort.
|
"""Sendet Text an aria-brain (HTTP /chat) und broadcastet die Antwort.
|
||||||
|
|
||||||
Nicht-Streaming: wir warten bis Brain fertig ist, dann pushen wir
|
Nicht-Streaming: wir warten bis Brain fertig ist, dann pushen wir
|
||||||
@@ -1464,8 +1529,13 @@ class ARIABridge:
|
|||||||
"""
|
"""
|
||||||
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
||||||
url = f"{brain_url}/chat"
|
url = f"{brain_url}/chat"
|
||||||
payload = json.dumps({"message": text, "source": source}).encode("utf-8")
|
# project_id kommt jetzt IM /chat-Body an das Brain (Multi-Threading:
|
||||||
logger.info("[brain] chat ← %s '%s'", source, text[:80])
|
# per-Request-Routing statt globaler active_project-State).
|
||||||
|
payload = json.dumps({
|
||||||
|
"message": text, "source": source,
|
||||||
|
"project_id": project_id or "",
|
||||||
|
}).encode("utf-8")
|
||||||
|
logger.info("[brain] chat ← %s '%s' project=%s", source, text[:80], project_id or "(main)")
|
||||||
|
|
||||||
# User-Nachricht in chat_backup.jsonl loggen — wird beim App-Reconnect
|
# User-Nachricht in chat_backup.jsonl loggen — wird beim App-Reconnect
|
||||||
# / Diagnostic-Reload als History-Quelle gelesen. clientMsgId speichern
|
# / Diagnostic-Reload als History-Quelle gelesen. clientMsgId speichern
|
||||||
@@ -1474,6 +1544,8 @@ class ARIABridge:
|
|||||||
entry: dict = {"role": "user", "text": text, "source": source}
|
entry: dict = {"role": "user", "text": text, "source": source}
|
||||||
if client_msg_id:
|
if client_msg_id:
|
||||||
entry["clientMsgId"] = client_msg_id
|
entry["clientMsgId"] = client_msg_id
|
||||||
|
if project_id:
|
||||||
|
entry["project_id"] = project_id
|
||||||
self._append_chat_backup(entry)
|
self._append_chat_backup(entry)
|
||||||
|
|
||||||
# agent_activity → thinking. _emit_activity statt direktem _send_to_rvs
|
# agent_activity → thinking. _emit_activity statt direktem _send_to_rvs
|
||||||
@@ -1521,6 +1593,11 @@ class ARIABridge:
|
|||||||
await self._emit_activity("idle", "")
|
await self._emit_activity("idle", "")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Projekt-Kontext des Turns — wird an _process_core_response weiter-
|
||||||
|
# gegeben damit der chat-Broadcast die Bubble dem richtigen Projekt-
|
||||||
|
# Block in App + Diagnostic zuordnen kann.
|
||||||
|
turn_project_id = (data.get("project_id") or "").strip()
|
||||||
|
|
||||||
# Side-Channel-Events VOR der Chat-Bubble broadcasten (z.B. skill_created)
|
# Side-Channel-Events VOR der Chat-Bubble broadcasten (z.B. skill_created)
|
||||||
# damit sie in der UI vor der Reply auftauchen
|
# damit sie in der UI vor der Reply auftauchen
|
||||||
for event in data.get("events", []) or []:
|
for event in data.get("events", []) or []:
|
||||||
@@ -1586,7 +1663,7 @@ class ARIABridge:
|
|||||||
# passend behandelt wird (hier minimal, weil Brain noch keine
|
# passend behandelt wird (hier minimal, weil Brain noch keine
|
||||||
# metadata mitschickt).
|
# metadata mitschickt).
|
||||||
try:
|
try:
|
||||||
await self._process_core_response(reply, {})
|
await self._process_core_response(reply, {"projectId": turn_project_id})
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("[brain] _process_core_response Fehler")
|
logger.exception("[brain] _process_core_response Fehler")
|
||||||
await self._emit_activity("idle", "")
|
await self._emit_activity("idle", "")
|
||||||
@@ -1897,6 +1974,7 @@ class ARIABridge:
|
|||||||
core_text,
|
core_text,
|
||||||
source="app" + (" [barge-in]" if interrupted else ""),
|
source="app" + (" [barge-in]" if interrupted else ""),
|
||||||
client_msg_id=client_msg_id,
|
client_msg_id=client_msg_id,
|
||||||
|
project_id=str(payload.get("projectId") or ""),
|
||||||
))
|
))
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -2125,6 +2203,10 @@ class ARIABridge:
|
|||||||
f.write(base64.b64decode(file_b64))
|
f.write(base64.b64decode(file_b64))
|
||||||
size_kb = len(file_b64) // 1365
|
size_kb = len(file_b64) // 1365
|
||||||
logger.info("[rvs] Datei gespeichert: %s (%dKB)", file_path, size_kb)
|
logger.info("[rvs] Datei gespeichert: %s (%dKB)", file_path, size_kb)
|
||||||
|
# Datei dem aktuellen Projekt zuordnen (falls Stefan in einem ist).
|
||||||
|
# Manifest in /shared/config/file_projects.json — File-Manager
|
||||||
|
# in App + Diagnostic filtert danach.
|
||||||
|
self._tag_file_to_active_project(file_path)
|
||||||
|
|
||||||
# Pixel-Bilder fuer Claude-Vision shrinken wenn > 2 MB. SVG/PDF/ZIP
|
# Pixel-Bilder fuer Claude-Vision shrinken wenn > 2 MB. SVG/PDF/ZIP
|
||||||
# bleiben unangetastet (Vision laeuft eh nur auf Raster-Formaten).
|
# bleiben unangetastet (Vision laeuft eh nur auf Raster-Formaten).
|
||||||
@@ -2901,6 +2983,81 @@ class ARIABridge:
|
|||||||
else:
|
else:
|
||||||
logger.info("[rvs] Keine Sprache erkannt — ignoriert")
|
logger.info("[rvs] Keine Sprache erkannt — ignoriert")
|
||||||
|
|
||||||
|
# Voice-Router-Konstanten
|
||||||
|
_VOICE_STICKY_TIMEOUT_SEC = 30.0
|
||||||
|
_VOICE_META_BACK_TO_MAIN = re.compile(
|
||||||
|
r"^\s*(?:aria[,.]?\s+)?(?:zur(?:ü|ue)ck\s+zum\s+hauptchat|hauptchat\s+bitte|aria\s+hauptchat)\s*[.!?]?\s*$",
|
||||||
|
re.IGNORECASE,
|
||||||
|
)
|
||||||
|
_VOICE_META_PROJECT_PREFIX = re.compile(
|
||||||
|
r"^\s*(?:aria[,.]?\s+)?(?:f(?:ü|ue)r|ins?)\s+([\w\-äöüßÄÖÜ]{2,40})[:\-,]\s*(.+?)\s*$",
|
||||||
|
re.IGNORECASE | re.DOTALL,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _apply_voice_router(self, text: str) -> tuple[bool, str, str, str]:
|
||||||
|
"""Voice-Router: entscheidet ob ein STT-Text ans Brain geht und wenn ja
|
||||||
|
an welchen Projekt-Kontext.
|
||||||
|
|
||||||
|
Returns (should_forward, cleaned_text, project_id, meta_action):
|
||||||
|
- should_forward=False: reines Meta-Kommando, kein Brain-Call.
|
||||||
|
meta_action beschreibt was passiert ist (broadcastet an UI).
|
||||||
|
- should_forward=True: cleaned_text ans Brain, project_id ist Focus.
|
||||||
|
Bei Prefix wird der Prefix aus dem Text entfernt.
|
||||||
|
|
||||||
|
Sticky-Logik: nach einem projekt-getaggten Voice-Turn wird der Sticky
|
||||||
|
30s lang gehalten. Innerhalb dieses Fensters gehen weitere Voice-Msgs
|
||||||
|
OHNE Prefix in dasselbe Projekt. Nach Ablauf: Default Hauptchat.
|
||||||
|
"""
|
||||||
|
import time as _time
|
||||||
|
now = _time.time()
|
||||||
|
stripped = text.strip()
|
||||||
|
|
||||||
|
# 1) Meta: zurueck zum Hauptchat
|
||||||
|
if self._VOICE_META_BACK_TO_MAIN.match(stripped):
|
||||||
|
self._voice_sticky_project_id = ""
|
||||||
|
self._voice_sticky_expires_at = 0.0
|
||||||
|
return (False, "", "", "back_to_main")
|
||||||
|
|
||||||
|
# 2) Prefix: "fuer <name>: <text>"
|
||||||
|
m = self._VOICE_META_PROJECT_PREFIX.match(stripped)
|
||||||
|
if m:
|
||||||
|
name = m.group(1)
|
||||||
|
remainder = m.group(2).strip()
|
||||||
|
# Fuzzy-Match auf Projekt via Brain-API
|
||||||
|
try:
|
||||||
|
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
||||||
|
with urllib.request.urlopen(f"{brain_url}/projects/list", timeout=3) as r:
|
||||||
|
projects = json.loads(r.read()).get("projects", [])
|
||||||
|
from difflib import SequenceMatcher
|
||||||
|
best, best_score = None, 0.0
|
||||||
|
q = name.lower()
|
||||||
|
for p in projects:
|
||||||
|
pname = p.get("name", "").lower()
|
||||||
|
if q == pname or q == p.get("id", ""):
|
||||||
|
best, best_score = p, 1.0
|
||||||
|
break
|
||||||
|
s = SequenceMatcher(None, q, pname).ratio()
|
||||||
|
if s > best_score:
|
||||||
|
best, best_score = p, s
|
||||||
|
if best and best_score >= 0.6:
|
||||||
|
pid = best["id"]
|
||||||
|
self._voice_sticky_project_id = pid
|
||||||
|
self._voice_sticky_expires_at = now + self._VOICE_STICKY_TIMEOUT_SEC
|
||||||
|
logger.info("[voice-router] Prefix → Projekt '%s' (id=%s, score=%.2f)",
|
||||||
|
best.get("name"), pid, best_score)
|
||||||
|
return (True, remainder or stripped, pid, "project_prefix")
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning("[voice-router] Prefix-Match fehlgeschlagen: %s", exc)
|
||||||
|
# Kein Match → als normale Nachricht weiter (Sticky wenn aktiv)
|
||||||
|
# 3) Kein Meta / Prefix → Sticky oder Default
|
||||||
|
if self._voice_sticky_project_id and now < self._voice_sticky_expires_at:
|
||||||
|
# Sticky refreshen
|
||||||
|
self._voice_sticky_expires_at = now + self._VOICE_STICKY_TIMEOUT_SEC
|
||||||
|
return (True, stripped, self._voice_sticky_project_id, "sticky")
|
||||||
|
# Sticky abgelaufen — zurücksetzen
|
||||||
|
self._voice_sticky_project_id = ""
|
||||||
|
return (True, stripped, "", "default")
|
||||||
|
|
||||||
async def _process_endpoint_text(self, text: str,
|
async def _process_endpoint_text(self, text: str,
|
||||||
interrupted: bool = False,
|
interrupted: bool = False,
|
||||||
audio_request_id: str = "",
|
audio_request_id: str = "",
|
||||||
@@ -2912,16 +3069,51 @@ class ARIABridge:
|
|||||||
Spiegel-Methode zu _process_app_audio NACH dem STT-Schritt. Bewusst
|
Spiegel-Methode zu _process_app_audio NACH dem STT-Schritt. Bewusst
|
||||||
eigene Methode statt Code-Pfade in _process_app_audio aufdroeseln,
|
eigene Methode statt Code-Pfade in _process_app_audio aufdroeseln,
|
||||||
damit der Legacy-Pfad (App schickt 'audio') unangetastet bleibt.
|
damit der Legacy-Pfad (App schickt 'audio') unangetastet bleibt.
|
||||||
|
|
||||||
|
Voice-Router: interceptiert Meta-Kommandos (zurueck zum Hauptchat)
|
||||||
|
+ Prefix-Adressierung („fuer Frankreich: ...") + 30s-Sticky. Meta
|
||||||
|
selbst geht NICHT ans Brain, sondern broadcastet als project_changed-
|
||||||
|
Event → App+Diagnostic wechseln den Focus.
|
||||||
"""
|
"""
|
||||||
|
should_forward, cleaned, project_id, meta_action = self._apply_voice_router(text)
|
||||||
|
|
||||||
|
if meta_action in ("back_to_main", "project_prefix"):
|
||||||
|
# UI-Focus-Update broadcasten
|
||||||
|
payload = {"action": "entered" if meta_action == "project_prefix" else "exited"}
|
||||||
|
if meta_action == "project_prefix" and project_id:
|
||||||
|
# Namen aus dem Cache holen — best effort
|
||||||
|
try:
|
||||||
|
brain_url = os.environ.get("BRAIN_URL", "http://aria-brain:8080")
|
||||||
|
with urllib.request.urlopen(f"{brain_url}/projects/list", timeout=2) as r:
|
||||||
|
for p in json.loads(r.read()).get("projects", []):
|
||||||
|
if p.get("id") == project_id:
|
||||||
|
payload["id"] = project_id
|
||||||
|
payload["name"] = p.get("name", "")
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
payload["id"] = project_id
|
||||||
|
await self._send_to_rvs({
|
||||||
|
"type": "project_changed",
|
||||||
|
"payload": payload,
|
||||||
|
"timestamp": int(asyncio.get_event_loop().time() * 1000),
|
||||||
|
})
|
||||||
|
|
||||||
|
if not should_forward:
|
||||||
|
logger.info("[voice-router] Meta-Kommando '%s' intercepted, kein Brain-Call",
|
||||||
|
meta_action)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stt_payload = {
|
stt_payload = {
|
||||||
"text": text,
|
"text": cleaned,
|
||||||
"sender": "stt",
|
"sender": "stt",
|
||||||
}
|
}
|
||||||
if audio_request_id:
|
if audio_request_id:
|
||||||
stt_payload["audioRequestId"] = audio_request_id
|
stt_payload["audioRequestId"] = audio_request_id
|
||||||
if location:
|
if location:
|
||||||
stt_payload["location"] = location
|
stt_payload["location"] = location
|
||||||
|
if project_id:
|
||||||
|
stt_payload["projectId"] = project_id
|
||||||
ok = await self._send_to_rvs({
|
ok = await self._send_to_rvs({
|
||||||
"type": "chat",
|
"type": "chat",
|
||||||
"payload": stt_payload,
|
"payload": stt_payload,
|
||||||
@@ -2934,10 +3126,11 @@ class ARIABridge:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("[rvs] STT-Text (endpoint) konnte nicht broadcastet werden: %s", e)
|
logger.warning("[rvs] STT-Text (endpoint) konnte nicht broadcastet werden: %s", e)
|
||||||
|
|
||||||
core_text = self._build_core_text(text, interrupted, location)
|
core_text = self._build_core_text(cleaned, interrupted, location)
|
||||||
await self.send_to_core(core_text,
|
await self.send_to_core(core_text,
|
||||||
source="app-voice-stream" + (" [barge-in]" if interrupted else ""),
|
source="app-voice-stream" + (" [barge-in]" if interrupted else ""),
|
||||||
client_msg_id=client_msg_id)
|
client_msg_id=client_msg_id,
|
||||||
|
project_id=project_id)
|
||||||
|
|
||||||
async def _stt_remote(self, audio_b64: str, mime_type: str) -> Optional[str]:
|
async def _stt_remote(self, audio_b64: str, mime_type: str) -> Optional[str]:
|
||||||
"""Schickt Audio an die whisper-bridge und wartet auf stt_response.
|
"""Schickt Audio an die whisper-bridge und wartet auf stt_response.
|
||||||
|
|||||||
+143
-2
@@ -305,6 +305,12 @@
|
|||||||
<button class="btn secondary" onclick="toggleChatFullscreen()" id="btn-chat-fs" style="padding:4px 10px;font-size:11px;">Vollbild</button>
|
<button class="btn secondary" onclick="toggleChatFullscreen()" id="btn-chat-fs" style="padding:4px 10px;font-size:11px;">Vollbild</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Multi-Threading: Kontext-Strip ueber dem Chat. Jeder Kontext
|
||||||
|
(Hauptchat + aktive Projekte) als kompakte Karte mit Status-Dot.
|
||||||
|
Tap wechselt den Focus — Chat-Box filtert dann auf diesen Kontext. -->
|
||||||
|
<div id="chat-context-strip" style="display:flex;gap:6px;overflow-x:auto;padding:6px 4px;margin-bottom:6px;border-bottom:1px solid #1E1E2E;">
|
||||||
|
<!-- wird von renderContextStrip() befuellt -->
|
||||||
|
</div>
|
||||||
<div class="chat-box" id="chat-box"></div>
|
<div class="chat-box" id="chat-box"></div>
|
||||||
<div id="thinking-indicator" style="display:none;padding:6px 10px;font-size:12px;color:#FFD60A;background:#1E1E2E;border-radius:0 0 6px 6px;margin-top:-8px;margin-bottom:8px;align-items:center;justify-content:space-between;">
|
<div id="thinking-indicator" style="display:none;padding:6px 10px;font-size:12px;color:#FFD60A;background:#1E1E2E;border-radius:0 0 6px 6px;margin-top:-8px;margin-bottom:8px;align-items:center;justify-content:space-between;">
|
||||||
<span><span style="animation:pulse 1s infinite;">💭</span> <span id="thinking-text">ARIA denkt...</span></span>
|
<span><span style="animation:pulse 1s infinite;">💭</span> <span id="thinking-text">ARIA denkt...</span></span>
|
||||||
@@ -1109,6 +1115,11 @@
|
|||||||
<option value="aria">Von ARIA (aria_*)</option>
|
<option value="aria">Von ARIA (aria_*)</option>
|
||||||
<option value="user">Vom Benutzer</option>
|
<option value="user">Vom Benutzer</option>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="files-filter-project" onchange="renderFilesList()" style="background:#080810;color:#E0E0F0;border:1px solid #1E1E2E;padding:6px;border-radius:4px;font-family:inherit;font-size:11px;">
|
||||||
|
<option value="__all__">Alle Projekte</option>
|
||||||
|
<option value="">💬 Hauptchat</option>
|
||||||
|
<!-- Project options werden dynamisch via loadFiles() befuellt -->
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="files-info" style="margin-top:6px;font-size:10px;color:#8888AA;"></div>
|
<div id="files-info" style="margin-top:6px;font-size:10px;color:#8888AA;"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1312,6 +1323,94 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
const chatBox = document.getElementById('chat-box');
|
const chatBox = document.getElementById('chat-box');
|
||||||
|
|
||||||
|
// ── Multi-Threading: Kontext-Focus fuer Diagnostic-Chat ─────
|
||||||
|
// focusedContextId: leerer String = Hauptchat, sonst project_id.
|
||||||
|
// Gefiltert werden Bubbles per data-project-id-Match (siehe addChat).
|
||||||
|
// Send-Input uebergibt die Focus-ID ans Brain (via bridge → /chat).
|
||||||
|
let focusedContextId = localStorage.getItem('diag_focused_context_id') || '';
|
||||||
|
let diagQueueStatus = {};
|
||||||
|
let diagProjectsCache = [];
|
||||||
|
|
||||||
|
function updateChatVisibilityByFocus() {
|
||||||
|
for (const box of [chatBox, document.getElementById('chat-box-fs')]) {
|
||||||
|
if (!box) continue;
|
||||||
|
for (const el of box.querySelectorAll('.chat-msg')) {
|
||||||
|
const pid = el.dataset.projectId || '';
|
||||||
|
el.style.display = (pid === focusedContextId) ? '' : 'none';
|
||||||
|
}
|
||||||
|
box.scrollTop = box.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchDiagFocus(id) {
|
||||||
|
focusedContextId = id || '';
|
||||||
|
localStorage.setItem('diag_focused_context_id', focusedContextId);
|
||||||
|
updateChatVisibilityByFocus();
|
||||||
|
renderContextStrip();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderContextStrip() {
|
||||||
|
const strip = document.getElementById('chat-context-strip');
|
||||||
|
if (!strip) return;
|
||||||
|
const chip = (id, name, isFocus, dotColor, subline) => {
|
||||||
|
const bg = isFocus ? 'rgba(52,199,89,0.15)' : '#1E1E2E';
|
||||||
|
const border = isFocus ? '#34C759' : '#2A2A3E';
|
||||||
|
return `<div onclick="switchDiagFocus('${id}')" style="cursor:pointer;flex:0 0 auto;padding:6px 10px;background:${bg};border:1px solid ${border};border-radius:6px;display:flex;align-items:center;gap:6px;min-width:120px;">
|
||||||
|
<div style="width:8px;height:8px;border-radius:4px;background:${dotColor};"></div>
|
||||||
|
<div style="display:flex;flex-direction:column;min-width:0;">
|
||||||
|
<div style="color:${isFocus?'#34C759':'#E0E0F0'};font-size:12px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:200px;">${escapeHtml(name)}</div>
|
||||||
|
<div style="color:#8888AA;font-size:10px;">${subline}</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
};
|
||||||
|
const dotFor = (key) => {
|
||||||
|
const s = diagQueueStatus[key];
|
||||||
|
if (!s) return { color: '#555570', label: '' };
|
||||||
|
if (s.busy) return { color: '#FF6E6E', label: 'arbeitet' };
|
||||||
|
if (s.queue_size > 0) return { color: '#FFD60A', label: `Queue: ${s.queue_size}` };
|
||||||
|
return { color: '#34C759', label: 'idle' };
|
||||||
|
};
|
||||||
|
const cards = [];
|
||||||
|
// Hauptchat
|
||||||
|
const mainDot = dotFor('__main__');
|
||||||
|
cards.push(chip('', '💬 Hauptchat', focusedContextId === '', mainDot.color, mainDot.label || 'idle'));
|
||||||
|
// Projekte — nur active/ended, sortiert nach letzter Aktivitaet
|
||||||
|
for (const p of diagProjectsCache) {
|
||||||
|
if (p.status === 'archived') continue;
|
||||||
|
const d = dotFor(p.id);
|
||||||
|
const sub = d.label || `${p.turn_count} Turns`;
|
||||||
|
cards.push(chip(p.id, `📁 ${p.name}`, focusedContextId === p.id, d.color, sub));
|
||||||
|
}
|
||||||
|
strip.innerHTML = cards.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshDiagQueueStatus() {
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/brain/projects/queue-status');
|
||||||
|
const d = await r.json();
|
||||||
|
diagQueueStatus = d?.contexts || {};
|
||||||
|
renderContextStrip();
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshDiagProjectsCache() {
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/brain/projects/list?include_archived=false');
|
||||||
|
const d = await r.json();
|
||||||
|
diagProjectsCache = d?.projects || [];
|
||||||
|
renderContextStrip();
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Beim Load: Projekte laden + Polling starten
|
||||||
|
setTimeout(() => {
|
||||||
|
refreshDiagProjectsCache();
|
||||||
|
refreshDiagQueueStatus();
|
||||||
|
setInterval(refreshDiagQueueStatus, 2000);
|
||||||
|
// Projekt-Liste alle 15s neu holen (neue Anlagen, umbenennen)
|
||||||
|
setInterval(refreshDiagProjectsCache, 15000);
|
||||||
|
}, 500);
|
||||||
const pauseHint = document.getElementById('pause-hint');
|
const pauseHint = document.getElementById('pause-hint');
|
||||||
const btnScroll = document.getElementById('btn-scroll');
|
const btnScroll = document.getElementById('btn-scroll');
|
||||||
let ws;
|
let ws;
|
||||||
@@ -1718,6 +1817,7 @@
|
|||||||
location: p.location,
|
location: p.location,
|
||||||
ttsText: p.ttsText,
|
ttsText: p.ttsText,
|
||||||
backupTs: p.backupTs,
|
backupTs: p.backupTs,
|
||||||
|
projectId: p.projectId || '',
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1906,8 +2006,10 @@
|
|||||||
if (!text && diagPendingFiles.length === 0) return;
|
if (!text && diagPendingFiles.length === 0) return;
|
||||||
if (diagPendingFiles.length > 0) sendDiagAttachments();
|
if (diagPendingFiles.length > 0) sendDiagAttachments();
|
||||||
if (text) {
|
if (text) {
|
||||||
addChat('sent', text, 'via RVS');
|
// Multi-Threading: mit fokussierter Kontext-ID senden.
|
||||||
send({ action: 'test_rvs', text });
|
// Bridge routet an /chat body.project_id — Brain queued per Kontext.
|
||||||
|
addChat('sent', text, 'via RVS', { projectId: focusedContextId });
|
||||||
|
send({ action: 'test_rvs', text, projectId: focusedContextId });
|
||||||
}
|
}
|
||||||
input.value = '';
|
input.value = '';
|
||||||
}
|
}
|
||||||
@@ -2173,12 +2275,18 @@
|
|||||||
// Thinking-Indikator ausblenden bei neuer Nachricht
|
// Thinking-Indikator ausblenden bei neuer Nachricht
|
||||||
updateThinkingIndicator({ activity: 'idle' });
|
updateThinkingIndicator({ activity: 'idle' });
|
||||||
|
|
||||||
|
// Projekt-Tag fuer Focus-Filter (Multi-Threading, 06/2026)
|
||||||
|
const projectId = (options && options.projectId) || '';
|
||||||
|
const hiddenByFocus = (typeof focusedContextId === 'string' && projectId !== focusedContextId);
|
||||||
|
|
||||||
// In beide Chat-Boxen schreiben (normal + Vollbild)
|
// In beide Chat-Boxen schreiben (normal + Vollbild)
|
||||||
for (const box of [chatBox, document.getElementById('chat-box-fs')]) {
|
for (const box of [chatBox, document.getElementById('chat-box-fs')]) {
|
||||||
if (!box) continue;
|
if (!box) continue;
|
||||||
const el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
el.className = `chat-msg ${type}`;
|
el.className = `chat-msg ${type}`;
|
||||||
if (backupTs) el.dataset.ts = String(backupTs);
|
if (backupTs) el.dataset.ts = String(backupTs);
|
||||||
|
el.dataset.projectId = projectId;
|
||||||
|
if (hiddenByFocus) el.style.display = 'none';
|
||||||
el.innerHTML = html;
|
el.innerHTML = html;
|
||||||
box.appendChild(el);
|
box.appendChild(el);
|
||||||
box.scrollTop = box.scrollHeight;
|
box.scrollTop = box.scrollHeight;
|
||||||
@@ -4209,6 +4317,37 @@
|
|||||||
const d = await r.json();
|
const d = await r.json();
|
||||||
if (!d.ok) throw new Error(d.error || 'Unbekannter Fehler');
|
if (!d.ok) throw new Error(d.error || 'Unbekannter Fehler');
|
||||||
filesCache = d.files || [];
|
filesCache = d.files || [];
|
||||||
|
// Projekt-Filter-Optionen aktualisieren — Liste aller bekannten projectIds
|
||||||
|
// aus den Dateien + Namen via brain api.
|
||||||
|
const pidsInFiles = new Set(filesCache.map(f => f.projectId).filter(Boolean));
|
||||||
|
try {
|
||||||
|
const pr = await fetch('/api/brain/projects/list?include_archived=true');
|
||||||
|
const pdata = await pr.json();
|
||||||
|
const projects = pdata?.projects || [];
|
||||||
|
const sel = document.getElementById('files-filter-project');
|
||||||
|
if (sel) {
|
||||||
|
const current = sel.value;
|
||||||
|
// Bestehende Options ab Index 2 (nach __all__ und Hauptchat) entfernen
|
||||||
|
while (sel.options.length > 2) sel.remove(2);
|
||||||
|
for (const p of projects) {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = p.id;
|
||||||
|
opt.textContent = `📁 ${p.name}`;
|
||||||
|
sel.appendChild(opt);
|
||||||
|
}
|
||||||
|
// Auch IDs aus Files die nicht in projects sind (gelöschte Projekte)
|
||||||
|
const knownIds = new Set(projects.map(p => p.id));
|
||||||
|
for (const pid of pidsInFiles) {
|
||||||
|
if (!knownIds.has(pid)) {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = pid;
|
||||||
|
opt.textContent = `📁 ${pid} (gelöscht?)`;
|
||||||
|
sel.appendChild(opt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sel.value = current || '__all__';
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
// Selection bereinigen — nicht mehr existierende Pfade raus
|
// Selection bereinigen — nicht mehr existierende Pfade raus
|
||||||
const existing = new Set(filesCache.map(f => f.path));
|
const existing = new Set(filesCache.map(f => f.path));
|
||||||
for (const p of [...filesSelected]) if (!existing.has(p)) filesSelected.delete(p);
|
for (const p of [...filesSelected]) if (!existing.has(p)) filesSelected.delete(p);
|
||||||
@@ -4221,9 +4360,11 @@
|
|||||||
function getVisibleFiles() {
|
function getVisibleFiles() {
|
||||||
const q = (document.getElementById('files-search').value || '').toLowerCase();
|
const q = (document.getElementById('files-search').value || '').toLowerCase();
|
||||||
const filter = document.getElementById('files-filter').value;
|
const filter = document.getElementById('files-filter').value;
|
||||||
|
const pidFilter = document.getElementById('files-filter-project')?.value || '__all__';
|
||||||
let files = filesCache.slice();
|
let files = filesCache.slice();
|
||||||
if (filter === 'aria') files = files.filter(f => f.fromAria);
|
if (filter === 'aria') files = files.filter(f => f.fromAria);
|
||||||
else if (filter === 'user') files = files.filter(f => !f.fromAria);
|
else if (filter === 'user') files = files.filter(f => !f.fromAria);
|
||||||
|
if (pidFilter !== '__all__') files = files.filter(f => (f.projectId || '') === pidFilter);
|
||||||
if (q) files = files.filter(f => f.name.toLowerCase().includes(q));
|
if (q) files = files.filter(f => f.name.toLowerCase().includes(q));
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|||||||
+64
-3
@@ -297,6 +297,32 @@ function writeRuntimeConfig(patch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Atomic write: temp-file + rename, laute Logs bei Fehler.
|
// Atomic write: temp-file + rename, laute Logs bei Fehler.
|
||||||
|
// ── File-Project-Manifest ───────────────────────────────────────────
|
||||||
|
// Jeder Eintrag map[absoluter_pfad] = project_id (leer = Hauptchat).
|
||||||
|
// Wird vom files-list-Endpoint + files-set-project gepflegt.
|
||||||
|
const FILE_PROJECTS_FILE = "/shared/config/file_projects.json";
|
||||||
|
|
||||||
|
function loadFileProjects() {
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(FILE_PROJECTS_FILE)) return {};
|
||||||
|
const data = JSON.parse(fs.readFileSync(FILE_PROJECTS_FILE, "utf-8"));
|
||||||
|
return (data && typeof data === "object") ? data : {};
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveFileProjects(manifest) {
|
||||||
|
try {
|
||||||
|
fs.mkdirSync("/shared/config", { recursive: true });
|
||||||
|
const tmp = FILE_PROJECTS_FILE + ".tmp";
|
||||||
|
fs.writeFileSync(tmp, JSON.stringify(manifest, null, 2));
|
||||||
|
fs.renameSync(tmp, FILE_PROJECTS_FILE);
|
||||||
|
} catch (err) {
|
||||||
|
log("warn", "files", `file-projects-Manifest schreiben fehlgeschlagen: ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function persistActiveSession(key) {
|
function persistActiveSession(key) {
|
||||||
try {
|
try {
|
||||||
const tmp = SESSION_KEY_FILE + ".tmp";
|
const tmp = SESSION_KEY_FILE + ".tmp";
|
||||||
@@ -975,18 +1001,26 @@ function sendToRVS_raw(msgObj) {
|
|||||||
freshWs.on("error", () => {});
|
freshWs.on("error", () => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendToRVS(text, isTrace) {
|
function sendToRVS(text, isTrace, projectId) {
|
||||||
// Brain-Pipeline: Diagnostic → RVS → Bridge → Brain (HTTP). OpenClaw-
|
// Brain-Pipeline: Diagnostic → RVS → Bridge → Brain (HTTP). OpenClaw-
|
||||||
// Gateway-Pfad ist abgeschaltet. Sender 'diagnostic' damit die Bridge
|
// Gateway-Pfad ist abgeschaltet. Sender 'diagnostic' damit die Bridge
|
||||||
// den Text als User-Nachricht ans Brain weiterleitet und die App +
|
// den Text als User-Nachricht ans Brain weiterleitet und die App +
|
||||||
// Diagnostic die Bubble live spiegeln koennen.
|
// Diagnostic die Bubble live spiegeln koennen.
|
||||||
|
//
|
||||||
|
// projectId (Multi-Threading 06/2026): optional — leerer/undefined String
|
||||||
|
// = Hauptchat, sonst project_id. Bridge liest payload.projectId und routet
|
||||||
|
// an /chat body.project_id — Brain queued per Kontext.
|
||||||
if (!rvsWs || rvsWs.readyState !== WebSocket.OPEN) {
|
if (!rvsWs || rvsWs.readyState !== WebSocket.OPEN) {
|
||||||
if (isTrace) traceEnd(false, "RVS nicht verbunden");
|
if (isTrace) traceEnd(false, "RVS nicht verbunden");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sendToRVS_raw({
|
sendToRVS_raw({
|
||||||
type: "chat",
|
type: "chat",
|
||||||
payload: { text, sender: "diagnostic" },
|
payload: {
|
||||||
|
text,
|
||||||
|
sender: "diagnostic",
|
||||||
|
projectId: projectId || "",
|
||||||
|
},
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
@@ -1598,6 +1632,7 @@ const server = http.createServer((req, res) => {
|
|||||||
const dir = "/shared/uploads";
|
const dir = "/shared/uploads";
|
||||||
let entries = [];
|
let entries = [];
|
||||||
try { entries = fs.readdirSync(dir); } catch { entries = []; }
|
try { entries = fs.readdirSync(dir); } catch { entries = []; }
|
||||||
|
const manifest = loadFileProjects();
|
||||||
const files = entries
|
const files = entries
|
||||||
.map(name => {
|
.map(name => {
|
||||||
try {
|
try {
|
||||||
@@ -1610,6 +1645,7 @@ const server = http.createServer((req, res) => {
|
|||||||
size: st.size,
|
size: st.size,
|
||||||
mtime: Math.floor(st.mtimeMs),
|
mtime: Math.floor(st.mtimeMs),
|
||||||
fromAria: name.startsWith("aria_"),
|
fromAria: name.startsWith("aria_"),
|
||||||
|
projectId: manifest[full] || '',
|
||||||
};
|
};
|
||||||
} catch { return null; }
|
} catch { return null; }
|
||||||
})
|
})
|
||||||
@@ -1622,6 +1658,31 @@ const server = http.createServer((req, res) => {
|
|||||||
res.end(JSON.stringify({ ok: false, error: err.message }));
|
res.end(JSON.stringify({ ok: false, error: err.message }));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
} else if (req.url === "/api/files-set-project" && req.method === "POST") {
|
||||||
|
// Body: { path, projectId } — projectId leer = Hauptchat (= Eintrag entfernen)
|
||||||
|
let body = "";
|
||||||
|
req.on("data", c => { body += c; if (body.length > 8192) req.destroy(); });
|
||||||
|
req.on("end", () => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(body || "{}");
|
||||||
|
const fpath = String(data.path || "");
|
||||||
|
const pid = String(data.projectId || "");
|
||||||
|
if (!fpath.startsWith("/shared/uploads/") || !fs.existsSync(fpath)) {
|
||||||
|
res.writeHead(404, { "Content-Type": "application/json" });
|
||||||
|
return res.end(JSON.stringify({ ok: false, error: "Datei nicht gefunden" }));
|
||||||
|
}
|
||||||
|
const manifest = loadFileProjects();
|
||||||
|
if (pid) manifest[fpath] = pid;
|
||||||
|
else delete manifest[fpath];
|
||||||
|
saveFileProjects(manifest);
|
||||||
|
res.writeHead(200, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ ok: true, path: fpath, projectId: pid }));
|
||||||
|
} catch (err) {
|
||||||
|
res.writeHead(500, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ ok: false, error: err.message }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
} else if ((req.url.startsWith("/api/files-download?") || req.url.startsWith("/api/files-view?")) && req.method === "GET") {
|
} else if ((req.url.startsWith("/api/files-download?") || req.url.startsWith("/api/files-view?")) && req.method === "GET") {
|
||||||
// /api/files-download → mit Content-Disposition:attachment (Browser downloaded)
|
// /api/files-download → mit Content-Disposition:attachment (Browser downloaded)
|
||||||
// /api/files-view → mit Disposition:inline (Browser zeigt PDF/Bilder im Tab)
|
// /api/files-view → mit Disposition:inline (Browser zeigt PDF/Bilder im Tab)
|
||||||
@@ -2232,7 +2293,7 @@ wss.on("connection", (ws) => {
|
|||||||
sendToRVS(msg.text || "aria lebst du noch?", true);
|
sendToRVS(msg.text || "aria lebst du noch?", true);
|
||||||
} else if (msg.action === "test_rvs") {
|
} else if (msg.action === "test_rvs") {
|
||||||
traceStart("RVS", msg.text || "aria lebst du noch?");
|
traceStart("RVS", msg.text || "aria lebst du noch?");
|
||||||
sendToRVS(msg.text || "aria lebst du noch?", true);
|
sendToRVS(msg.text || "aria lebst du noch?", true, msg.projectId || "");
|
||||||
} else if (msg.action === "reconnect_gateway") {
|
} else if (msg.action === "reconnect_gateway") {
|
||||||
connectGateway();
|
connectGateway();
|
||||||
} else if (msg.action === "reconnect_rvs") {
|
} else if (msg.action === "reconnect_rvs") {
|
||||||
|
|||||||
Reference in New Issue
Block a user