import 'content_block.dart'; import 'log_entry.dart'; import 'token_usage.dart'; class AgentInfo { final String id; final String name; final String? subagentType; final String? description; final String? prompt; final String? model; final List messages; final List toolsUsed; final TokenUsage aggregatedUsage; AgentInfo({ required this.id, required this.name, this.subagentType, this.description, this.prompt, this.model, required this.messages, required this.toolsUsed, required this.aggregatedUsage, }); Set get uniqueToolNames => toolsUsed.map((t) => t.name).toSet(); Map get toolUsageCounts { final counts = {}; for (final tool in toolsUsed) { counts[tool.name] = (counts[tool.name] ?? 0) + 1; } return counts; } int get messageCount => messages.length; int get userMessageCount => messages.where((m) => m.type == 'user').length; int get assistantMessageCount => messages.where((m) => m.type == 'assistant').length; } class SessionLog { final String? sessionId; final String? cwd; final String? version; final String? gitBranch; final List allEntries; final List mainConversation; final List agents; final AgentInfo mainAgent; final TokenUsage totalUsage; final Map> toolsByName; final DateTime? startTime; final DateTime? endTime; /// Lookup subagent by ID (matches both full id and partial) late final Map agentById = { for (final a in agents) a.id: a, }; SessionLog({ this.sessionId, this.cwd, this.version, this.gitBranch, required this.allEntries, required this.mainConversation, required this.agents, required this.mainAgent, required this.totalUsage, required this.toolsByName, this.startTime, this.endTime, }); /// Find an agent that matches a tool_use id (Agent tool calls use /// the tool_use block id, subagent files use a shortened agentId) AgentInfo? findAgentForToolUse(String toolUseId) { // Direct match if (agentById.containsKey(toolUseId)) return agentById[toolUseId]; // Partial match: subagent file ids are shortened (e.g. "a014e30b71de602bb") for (final agent in agents) { if (agent.id == 'main') continue; if (toolUseId.contains(agent.id) || agent.id.contains(toolUseId)) { return agent; } } return null; } Duration? get duration { if (startTime != null && endTime != null) { return endTime!.difference(startTime!); } return null; } }