// Claude Desktop — App-State import { writable, derived } from 'svelte/store'; // Typen export interface Agent { id: string; type: 'main' | 'explore' | 'plan' | 'bash'; status: 'active' | 'waiting' | 'idle' | 'stopped'; task: string; startedAt: Date; toolCalls: ToolCall[]; } export interface ToolCall { id: string; agentId: string; tool: string; args: Record; status: 'running' | 'completed' | 'failed'; startedAt: Date; completedAt?: Date; result?: unknown; } export interface Message { id: string; role: 'user' | 'assistant' | 'system'; content: string; timestamp: Date; agentId?: string; model?: string; } export interface Permission { id: string; pattern: string; type: 'session' | 'permanent'; action: 'allow' | 'deny'; createdAt: Date; } // Stores export const agents = writable([]); export const toolCalls = writable([]); export const messages = writable([]); export const permissions = writable([]); // UI-State export const isProcessing = writable(false); export const currentInput = writable(''); export const selectedAgentId = writable(null); // Abgeleitete Stores export const activeAgents = derived(agents, ($agents) => $agents.filter((a) => a.status === 'active') ); export const recentToolCalls = derived(toolCalls, ($toolCalls) => $toolCalls.slice(-50).reverse() ); export const agentCount = derived(agents, ($agents) => ({ total: $agents.length, active: $agents.filter((a) => a.status === 'active').length, waiting: $agents.filter((a) => a.status === 'waiting').length, idle: $agents.filter((a) => a.status === 'idle').length })); // Aktionen export function addMessage(role: Message['role'], content: string, agentId?: string) { messages.update((msgs) => [ ...msgs, { id: crypto.randomUUID(), role, content, timestamp: new Date(), agentId } ]); } export function addAgent(type: Agent['type'], task: string): string { const id = crypto.randomUUID(); agents.update((ags) => [ ...ags, { id, type, status: 'active', task, startedAt: new Date(), toolCalls: [] } ]); return id; } export function updateAgentStatus(id: string, status: Agent['status']) { agents.update((ags) => ags.map((a) => (a.id === id ? { ...a, status } : a)) ); } export function addToolCall(agentId: string, tool: string, args: Record): string { const id = crypto.randomUUID(); const call: ToolCall = { id, agentId, tool, args, status: 'running', startedAt: new Date() }; toolCalls.update((calls) => [...calls, call]); // Auch im Agent speichern agents.update((ags) => ags.map((a) => a.id === agentId ? { ...a, toolCalls: [...a.toolCalls, call] } : a ) ); return id; } export function completeToolCall(id: string, result: unknown, failed = false) { toolCalls.update((calls) => calls.map((c) => c.id === id ? { ...c, status: failed ? 'failed' : 'completed', completedAt: new Date(), result } : c ) ); } export function clearAll() { agents.set([]); toolCalls.set([]); messages.set([]); isProcessing.set(false); }