11import React , { useState , useEffect } from 'react' ;
22import { motion , AnimatePresence } from 'framer-motion' ;
3- import { Bot , Loader2 , Play , Clock , CheckCircle , XCircle , Trash2 , Import , ChevronDown , FileJson , Globe , Download , Plus } from 'lucide-react' ;
3+ import { Bot , Loader2 , Play , Clock , CheckCircle , XCircle , Trash2 , Import , ChevronDown , ChevronRight , FileJson , Globe , Download , Plus , History } from 'lucide-react' ;
44import {
55 DropdownMenu ,
66 DropdownMenuContent ,
@@ -13,12 +13,12 @@ import { Badge } from '@/components/ui/badge';
1313import { Card } from '@/components/ui/card' ;
1414import { Toast } from '@/components/ui/toast' ;
1515import { api , type Agent , type AgentRunWithMetrics } from '@/lib/api' ;
16- import { useTabState } from '@/hooks/useTabState' ;
1716import { formatISOTimestamp } from '@/lib/date-utils' ;
1817import { open as openDialog , save } from '@tauri-apps/plugin-dialog' ;
1918import { invoke } from '@tauri-apps/api/core' ;
2019import { GitHubAgentBrowser } from '@/components/GitHubAgentBrowser' ;
2120import { CreateAgent } from '@/components/CreateAgent' ;
21+ import { useTabState } from '@/hooks/useTabState' ;
2222
2323export const Agents : React . FC = ( ) => {
2424 const [ activeTab , setActiveTab ] = useState ( 'agents' ) ;
@@ -62,7 +62,7 @@ export const Agents: React.FC = () => {
6262
6363 const loadRunningAgents = async ( ) => {
6464 try {
65- const runs = await api . listAgentRuns ( ) ;
65+ const runs = await api . listAgentRunsWithMetrics ( ) ;
6666 setRunningAgents ( runs ) ;
6767 } catch ( error ) {
6868 console . error ( 'Failed to load running agents:' , error ) ;
@@ -74,14 +74,33 @@ export const Agents: React.FC = () => {
7474 setToast ( { message : 'Agent ID is missing' , type : 'error' } ) ;
7575 return ;
7676 }
77+
78+ // Import the dialog function
79+ const { open } = await import ( '@tauri-apps/plugin-dialog' ) ;
80+
7781 try {
78- const runId = await api . executeAgent ( agent . id , '' , 'Run agent' , undefined ) ;
79- createAgentTab ( runId . toString ( ) , agent . name ) ;
80- setToast ( { message : `Started agent: ${ agent . name } ` , type : 'success' } ) ;
81- loadRunningAgents ( ) ;
82+ // Prompt user to select a project directory
83+ const projectPath = await open ( {
84+ directory : true ,
85+ multiple : false ,
86+ title : `Select project directory for ${ agent . name } `
87+ } ) ;
88+
89+ if ( ! projectPath ) {
90+ // User cancelled
91+ return ;
92+ }
93+
94+ // Dispatch event to open agent execution in a new tab
95+ const tabId = `agent-exec-${ agent . id } -${ Date . now ( ) } ` ;
96+ window . dispatchEvent ( new CustomEvent ( 'open-agent-execution' , {
97+ detail : { agent, tabId, projectPath }
98+ } ) ) ;
99+
100+ setToast ( { message : `Opening agent: ${ agent . name } ` , type : 'success' } ) ;
82101 } catch ( error ) {
83- console . error ( 'Failed to run agent:' , error ) ;
84- setToast ( { message : `Failed to run agent: ${ agent . name } ` , type : 'error' } ) ;
102+ console . error ( 'Failed to open agent:' , error ) ;
103+ setToast ( { message : `Failed to open agent: ${ agent . name } ` , type : 'error' } ) ;
85104 }
86105 } ;
87106
@@ -292,8 +311,8 @@ export const Agents: React.FC = () => {
292311 Agents ({ agents . length } )
293312 </ TabsTrigger >
294313 < TabsTrigger value = "running" className = "py-2.5 px-3" >
295- < Loader2 className = "w-4 h-4 mr-2" />
296- Running ({ runningAgents . length } )
314+ < History className = "w-4 h-4 mr-2" />
315+ History ({ runningAgents . length } )
297316 </ TabsTrigger >
298317 </ TabsList >
299318
@@ -381,8 +400,8 @@ export const Agents: React.FC = () => {
381400 { runningAgents . length === 0 ? (
382401 < Card className = "p-12" >
383402 < div className = "flex flex-col items-center justify-center text-center" >
384- < Loader2 className = "w-12 h-12 text-muted-foreground mb-4" />
385- < h3 className = "text-lg font-semibold mb-2" > No Running Agents </ h3 >
403+ < History className = "w-12 h-12 text-muted-foreground mb-4" />
404+ < h3 className = "text-lg font-semibold mb-2" > No Agent History </ h3 >
386405 < p className = "text-muted-foreground" >
387406 Run an agent to see it here
388407 </ p >
@@ -404,26 +423,27 @@ export const Agents: React.FC = () => {
404423 </ Badge >
405424 </ div >
406425 < Button
407- size = "sm "
408- variant = "outline "
426+ size = "icon "
427+ variant = "ghost "
409428 onClick = { ( ) => createAgentTab ( run . id ?. toString ( ) || '' , run . agent_name ) }
429+ className = "h-8 w-8"
410430 >
411- View
431+ < ChevronRight className = "w-4 h-4" />
412432 </ Button >
413433 </ div >
414434
415435 < div className = "grid grid-cols-3 gap-4 text-sm" >
416436 < div >
417437 < span className = "text-muted-foreground" > Started:</ span >
418- < p className = "font-medium" > { formatISOTimestamp ( run . created_at ) } </ p >
438+ < p className = "font-medium" > { new Date ( run . created_at ) . toLocaleString ( ) } </ p >
419439 </ div >
420440 < div >
421441 < span className = "text-muted-foreground" > Duration:</ span >
422- < p className = "font-medium" > { run . metrics ?. duration_ms ? `${ ( run . metrics . duration_ms / 1000 ) . toFixed ( 1 ) } s` : 'N/A '} </ p >
442+ < p className = "font-medium" > { run . metrics ?. duration_ms ? `${ ( run . metrics . duration_ms / 1000 ) . toFixed ( 1 ) } s` : run . duration_ms ? ` ${ ( run . duration_ms / 1000 ) . toFixed ( 1 ) } s` : '— '} </ p >
423443 </ div >
424444 < div >
425445 < span className = "text-muted-foreground" > Tokens:</ span >
426- < p className = "font-medium" > { run . metrics ?. total_tokens ?. toLocaleString ( ) || '0 '} </ p >
446+ < p className = "font-medium" > { run . metrics ?. total_tokens ? run . metrics . total_tokens . toLocaleString ( ) : run . total_tokens ? run . total_tokens . toLocaleString ( ) : '— '} </ p >
427447 </ div >
428448 </ div >
429449
0 commit comments