|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | +import { Icon } from '@iconify/react' |
| 5 | +import { |
| 6 | + type AgentActivity, |
| 7 | + summarizeActivities, |
| 8 | + activityIcon, |
| 9 | + activityColor, |
| 10 | +} from '@/lib/agent-activity' |
| 11 | + |
| 12 | +interface Props { |
| 13 | + activities: AgentActivity[] |
| 14 | + isRunning: boolean |
| 15 | +} |
| 16 | + |
| 17 | +export function AgentActivityFeed({ activities, isRunning }: Props) { |
| 18 | + const [expanded, setExpanded] = useState(false) |
| 19 | + const summary = summarizeActivities(activities) |
| 20 | + |
| 21 | + if (activities.length === 0) return null |
| 22 | + |
| 23 | + const lastActivity = activities[activities.length - 1] |
| 24 | + |
| 25 | + return ( |
| 26 | + <div className="rounded-xl border border-[var(--border)] bg-[var(--bg-subtle)] overflow-hidden my-1.5"> |
| 27 | + {/* Compact summary bar */} |
| 28 | + <button |
| 29 | + onClick={() => setExpanded(v => !v)} |
| 30 | + className="w-full flex items-center gap-2 px-3 py-2 text-left cursor-pointer hover:bg-[color-mix(in_srgb,var(--text-primary)_3%,transparent)] transition-colors" |
| 31 | + > |
| 32 | + {isRunning && ( |
| 33 | + <span className="relative flex h-2 w-2 shrink-0"> |
| 34 | + <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-[var(--brand)] opacity-50" /> |
| 35 | + <span className="relative inline-flex rounded-full h-2 w-2 bg-[var(--brand)]" /> |
| 36 | + </span> |
| 37 | + )} |
| 38 | + {!isRunning && ( |
| 39 | + <Icon icon="lucide:check-circle" width={12} className="text-[var(--color-additions)] shrink-0" /> |
| 40 | + )} |
| 41 | + |
| 42 | + {/* Current action or summary */} |
| 43 | + <span className="text-[11px] text-[var(--text-secondary)] flex-1 truncate"> |
| 44 | + {isRunning |
| 45 | + ? lastActivity.label |
| 46 | + : `${summary.totalActions} actions`} |
| 47 | + </span> |
| 48 | + |
| 49 | + {/* File change badges */} |
| 50 | + <div className="flex items-center gap-1.5"> |
| 51 | + {summary.filesEdited.length > 0 && ( |
| 52 | + <span className="inline-flex items-center gap-0.5 text-[9px] font-medium text-amber-400"> |
| 53 | + <Icon icon="lucide:file-pen-line" width={10} /> |
| 54 | + {summary.filesEdited.length} |
| 55 | + </span> |
| 56 | + )} |
| 57 | + {summary.filesCreated.length > 0 && ( |
| 58 | + <span className="inline-flex items-center gap-0.5 text-[9px] font-medium text-green-400"> |
| 59 | + <Icon icon="lucide:file-plus" width={10} /> |
| 60 | + {summary.filesCreated.length} |
| 61 | + </span> |
| 62 | + )} |
| 63 | + {summary.filesRead.length > 0 && ( |
| 64 | + <span className="inline-flex items-center gap-0.5 text-[9px] font-medium text-blue-400"> |
| 65 | + <Icon icon="lucide:file-search" width={10} /> |
| 66 | + {summary.filesRead.length} |
| 67 | + </span> |
| 68 | + )} |
| 69 | + {summary.commandsRun > 0 && ( |
| 70 | + <span className="inline-flex items-center gap-0.5 text-[9px] font-medium text-cyan-400"> |
| 71 | + <Icon icon="lucide:terminal" width={10} /> |
| 72 | + {summary.commandsRun} |
| 73 | + </span> |
| 74 | + )} |
| 75 | + </div> |
| 76 | + |
| 77 | + <Icon |
| 78 | + icon={expanded ? 'lucide:chevron-up' : 'lucide:chevron-down'} |
| 79 | + width={11} |
| 80 | + className="text-[var(--text-disabled)] shrink-0" |
| 81 | + /> |
| 82 | + </button> |
| 83 | + |
| 84 | + {/* Expanded timeline */} |
| 85 | + {expanded && ( |
| 86 | + <div className="border-t border-[var(--border)] px-3 py-2 max-h-[240px] overflow-y-auto"> |
| 87 | + <div className="relative flex flex-col gap-0"> |
| 88 | + {/* Timeline line */} |
| 89 | + <div className="absolute left-[5px] top-2 bottom-2 w-px bg-[color-mix(in_srgb,var(--brand)_15%,var(--border))]" /> |
| 90 | + |
| 91 | + {activities.map((act, i) => { |
| 92 | + const isLast = i === activities.length - 1 |
| 93 | + return ( |
| 94 | + <div |
| 95 | + key={act.id} |
| 96 | + className="flex items-start gap-2.5 py-1 relative" |
| 97 | + > |
| 98 | + {/* Timeline dot */} |
| 99 | + <div className="relative z-[1] shrink-0 mt-0.5"> |
| 100 | + {isLast && isRunning ? ( |
| 101 | + <span className="relative flex h-[9px] w-[9px]"> |
| 102 | + <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-[var(--brand)] opacity-50" /> |
| 103 | + <span className="relative inline-flex rounded-full h-[9px] w-[9px] bg-[var(--brand)]" /> |
| 104 | + </span> |
| 105 | + ) : ( |
| 106 | + <span className={`block w-[9px] h-[9px] rounded-full border-2 ${ |
| 107 | + act.status === 'error' |
| 108 | + ? 'border-[var(--color-deletions)] bg-[var(--color-deletions)]' |
| 109 | + : 'border-[color-mix(in_srgb,var(--brand)_40%,var(--border))] bg-[var(--bg-subtle)]' |
| 110 | + }`} /> |
| 111 | + )} |
| 112 | + </div> |
| 113 | + |
| 114 | + {/* Activity content */} |
| 115 | + <div className="flex items-center gap-1.5 min-w-0 flex-1"> |
| 116 | + <Icon |
| 117 | + icon={activityIcon(act.type)} |
| 118 | + width={11} |
| 119 | + className={`shrink-0 ${activityColor(act.type)}`} |
| 120 | + /> |
| 121 | + <span className={`text-[10px] truncate ${ |
| 122 | + isLast && isRunning ? 'text-[var(--text-primary)] font-medium' : 'text-[var(--text-disabled)]' |
| 123 | + }`}> |
| 124 | + {act.label} |
| 125 | + </span> |
| 126 | + </div> |
| 127 | + |
| 128 | + {/* File chip */} |
| 129 | + {act.file && ( |
| 130 | + <span className="text-[8px] font-mono text-[var(--text-disabled)] truncate max-w-[100px]"> |
| 131 | + {act.file.split('/').pop()} |
| 132 | + </span> |
| 133 | + )} |
| 134 | + </div> |
| 135 | + ) |
| 136 | + })} |
| 137 | + </div> |
| 138 | + |
| 139 | + {/* Changed files summary */} |
| 140 | + {!isRunning && summary.filesEdited.length > 0 && ( |
| 141 | + <div className="mt-2 pt-2 border-t border-[var(--border)]"> |
| 142 | + <p className="text-[9px] uppercase tracking-wider text-[var(--text-disabled)] font-medium mb-1">Changed Files</p> |
| 143 | + <div className="flex flex-wrap gap-1"> |
| 144 | + {[...summary.filesEdited, ...summary.filesCreated].map(f => ( |
| 145 | + <span |
| 146 | + key={f} |
| 147 | + className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-mono bg-[color-mix(in_srgb,var(--brand)_6%,transparent)] border border-[color-mix(in_srgb,var(--brand)_20%,var(--border))] text-[var(--text-secondary)]" |
| 148 | + > |
| 149 | + <Icon icon={summary.filesCreated.includes(f) ? 'lucide:file-plus' : 'lucide:file-pen-line'} width={9} /> |
| 150 | + {f.split('/').pop()} |
| 151 | + </span> |
| 152 | + ))} |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + )} |
| 156 | + </div> |
| 157 | + )} |
| 158 | + </div> |
| 159 | + ) |
| 160 | +} |
0 commit comments