diff --git a/src/lib/components/ChatPanel.svelte b/src/lib/components/ChatPanel.svelte
index ba38fb4..fed0c48 100644
--- a/src/lib/components/ChatPanel.svelte
+++ b/src/lib/components/ChatPanel.svelte
@@ -99,16 +99,19 @@
{/if}
{#if $isProcessing}
-
-
+ {/if}
{/if}
diff --git a/src/lib/stores/events.ts b/src/lib/stores/events.ts
index df33060..1d7ffb6 100644
--- a/src/lib/stores/events.ts
+++ b/src/lib/stores/events.ts
@@ -41,20 +41,18 @@ interface ResultEvent {
input: number;
output: number;
};
+ session_id?: string;
}
// Listener-Handles
let listeners: UnlistenFn[] = [];
-// Aktuelle Nachricht (wird während Streaming aufgebaut)
-let currentResponseText = '';
-let currentResponseAgentId: string | null = null;
+// Streaming: ID der aktuellen Live-Nachricht
+let streamingMessageId: string | null = null;
// Events initialisieren
export async function initEventListeners(): Promise {
console.log('🎧 Initialisiere Event-Listener...');
-
- // Aufräumen falls bereits initialisiert
await cleanupEventListeners();
// Bridge bereit
@@ -70,10 +68,21 @@ export async function initEventListeners(): Promise {
const { id, type, task } = event.payload;
console.log('🤖 Agent gestartet:', id, type);
- const agentType = mapAgentType(type || 'main');
- addAgent(agentType, task || 'Verarbeite...');
- currentResponseAgentId = id;
+ addAgent(mapAgentType(type || 'main'), task || 'Verarbeite...');
isProcessing.set(true);
+
+ // Leere Streaming-Nachricht anlegen
+ streamingMessageId = crypto.randomUUID();
+ messages.update((msgs) => [
+ ...msgs,
+ {
+ id: streamingMessageId!,
+ role: 'assistant',
+ content: '',
+ timestamp: new Date(),
+ agentId: id
+ }
+ ]);
})
);
@@ -82,15 +91,8 @@ export async function initEventListeners(): Promise {
await listen('agent-stopped', (event) => {
const { id } = event.payload;
console.log('⏹️ Agent gestoppt:', id);
-
updateAgentStatus(id, 'stopped');
-
- // Falls das der Haupt-Agent war, Antwort finalisieren
- if (currentResponseAgentId === id && currentResponseText) {
- addMessage('assistant', currentResponseText, id);
- currentResponseText = '';
- currentResponseAgentId = null;
- }
+ streamingMessageId = null;
// Prüfen ob noch Agents aktiv
agents.update((ags) => {
@@ -109,21 +111,16 @@ export async function initEventListeners(): Promise {
console.log('⏹️ Alle Agents gestoppt');
agents.update((ags) => ags.map((a) => ({ ...a, status: 'stopped' as const })));
isProcessing.set(false);
-
- if (currentResponseText) {
- addMessage('assistant', currentResponseText);
- currentResponseText = '';
- }
+ streamingMessageId = null;
})
);
// Tool Start
listeners.push(
await listen('tool-start', (event) => {
- const { id, tool, input } = event.payload;
+ const { tool, input } = event.payload;
console.log('🔧 Tool Start:', tool);
- // Dem aktiven Haupt-Agent zuordnen
agents.update((ags) => {
const activeAgent = ags.find((a) => a.status === 'active');
if (activeAgent) {
@@ -139,34 +136,43 @@ export async function initEventListeners(): Promise {
await listen('tool-end', (event) => {
const { id, success, output } = event.payload;
console.log('✅ Tool Ende:', id, success ? 'OK' : 'FEHLER');
-
completeToolCall(id, output, !success);
})
);
- // Text-Streaming
+ // Text-Streaming — live in die aktuelle Nachricht schreiben
listeners.push(
await listen('claude-text', (event) => {
const { text } = event.payload;
- currentResponseText += text;
+ if (streamingMessageId) {
+ messages.update((msgs) =>
+ msgs.map((m) =>
+ m.id === streamingMessageId
+ ? { ...m, content: m.content + text }
+ : m
+ )
+ );
+ }
})
);
// Ergebnis (Kosten, Token)
listeners.push(
await listen('claude-result', (event) => {
- const { cost, tokens } = event.payload;
+ const { cost, tokens, session_id } = event.payload;
console.log('📊 Ergebnis:', {
cost: cost ? `$${cost.toFixed(4)}` : 'unbekannt',
- tokens
+ tokens,
+ session_id
});
})
);
- // Agents gestoppt (vom STOPP-Button)
+ // STOPP-Signal
listeners.push(
await listen('agents-stopped', () => {
console.log('🛑 STOPP-Signal empfangen');
+ streamingMessageId = null;
clearAll();
})
);
@@ -187,6 +193,7 @@ function mapAgentType(type: string): 'main' | 'explore' | 'plan' | 'bash' {
const typeMap: Record = {
main: 'main',
'Main Agent': 'main',
+ Main: 'main',
explore: 'explore',
Explore: 'explore',
plan: 'plan',