- ChatPanel: Zeigt Modellname statt "Claude" (z.B. "opus-4", "haiku-4-5") - Modell-Info kommt aus dem result-Event der Bridge - Korrekter Modell-ID: claude-opus-4-20250514 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
149 lines
3.1 KiB
TypeScript
149 lines
3.1 KiB
TypeScript
// 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<string, unknown>;
|
|
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<Agent[]>([]);
|
|
export const toolCalls = writable<ToolCall[]>([]);
|
|
export const messages = writable<Message[]>([]);
|
|
export const permissions = writable<Permission[]>([]);
|
|
|
|
// UI-State
|
|
export const isProcessing = writable(false);
|
|
export const currentInput = writable('');
|
|
export const selectedAgentId = writable<string | null>(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, unknown>): 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);
|
|
}
|