// Helper fuer Inline-Tool-Karten in Assistant-Messages (Phase 8) // // Mapping Tool-Name -> Icon, Akzentfarbe, Default-Collapse-Verhalten, // Subtitel-Generierung. Die eigentliche Card-Komponente wird in // ToolCallCard.svelte gewaehlt; hier sind nur statische Metadaten. export type ToolKind = | 'read' // Read, Glob, NotebookRead | 'edit' // Edit, Write, NotebookEdit, MultiEdit | 'bash' // Bash, BashOutput, KillShell | 'search' // Grep, Glob (alternativ) | 'web' // WebFetch, WebSearch | 'task' // Task (Subagent) | 'mcp' // mcp__* | 'todo' // TodoWrite | 'generic'; export interface ToolMeta { kind: ToolKind; icon: string; // Emoji-Icon (matcht VS-Code-Extension-Konvention) label: string; // Lesbarer Tool-Name (Original beibehalten wenn moeglich) collapseWhenDone: boolean; // VS-Code: Read collapsed nach Erfolg, Edit aufgeklappt } export function getToolMeta(toolName: string): ToolMeta { const t = (toolName || '').toLowerCase(); // MCP-Tools (mcp__server__name) if (t.startsWith('mcp__')) { return { kind: 'mcp', icon: '🛠️', label: toolName, collapseWhenDone: true }; } // Edit/Write-Familie if (t === 'edit' || t === 'write' || t === 'multiedit' || t === 'notebookedit') { return { kind: 'edit', icon: '✏️', label: toolName, collapseWhenDone: false }; } // Read-Familie if (t === 'read' || t === 'notebookread') { return { kind: 'read', icon: '📖', label: toolName, collapseWhenDone: true }; } // Bash-Familie if (t === 'bash' || t === 'bashoutput' || t === 'killshell') { return { kind: 'bash', icon: '🖥️', label: toolName, collapseWhenDone: true }; } // Such-Tools if (t === 'grep') return { kind: 'search', icon: '🔍', label: toolName, collapseWhenDone: true }; if (t === 'glob') return { kind: 'search', icon: '📁', label: toolName, collapseWhenDone: true }; // Web-Tools if (t === 'webfetch') return { kind: 'web', icon: '🌐', label: toolName, collapseWhenDone: true }; if (t === 'websearch') return { kind: 'web', icon: '🔎', label: toolName, collapseWhenDone: true }; // Subagent-Spawn if (t === 'task') return { kind: 'task', icon: '👥', label: toolName, collapseWhenDone: false }; // Todo if (t === 'todowrite') return { kind: 'todo', icon: '📋', label: toolName, collapseWhenDone: true }; // Fallback return { kind: 'generic', icon: '⚙️', label: toolName || 'Tool', collapseWhenDone: true }; } // Erzeugt einen kompakten Untertitel fuer den Karten-Header. // Bsp: { file_path: "src/app.ts", offset: 45, limit: 35 } -> "src/app.ts:45-79" export function getToolSubtitle(tool: string, input: Record = {}): string { const t = (tool || '').toLowerCase(); const path = (input.file_path || input.path || input.notebook_path) as string | undefined; if (path) { // Pfad kuerzen: "/mnt/17 - Entwicklungen/.../foo/bar.ts" -> "bar.ts" const short = path.split('/').slice(-2).join('/'); if (t === 'read' || t === 'notebookread') { const offset = input.offset as number | undefined; const limit = input.limit as number | undefined; if (typeof offset === 'number' && typeof limit === 'number') { return `${short}:${offset}-${offset + limit - 1}`; } return short; } return short; } if (t === 'bash' || t === 'bashoutput') { const cmd = (input.command as string) || (input.bash_id as string) || ''; return cmd.length > 60 ? cmd.slice(0, 57) + '…' : cmd; } if (t === 'grep') { const pattern = (input.pattern as string) || ''; const where = (input.path as string) || (input.glob as string) || ''; return where ? `"${pattern}" in ${where}` : `"${pattern}"`; } if (t === 'glob') { return (input.pattern as string) || ''; } if (t === 'webfetch') return (input.url as string) || ''; if (t === 'websearch') return (input.query as string) || ''; if (t === 'task') { const desc = (input.description as string) || (input.subagent_type as string) || ''; return desc; } if (t.startsWith('mcp__')) { // Tool-Name selbst ist informativ genug return ''; } if (t === 'todowrite') { const todos = input.todos as Array<{ status?: string }> | undefined; if (Array.isArray(todos)) { const total = todos.length; const done = todos.filter(x => x.status === 'completed').length; return `${done}/${total} erledigt`; } return ''; } return ''; }