Spaces:
Build error
Build error
Mehdi commited on
Upload components/AgentWorkflow.jsx with huggingface_hub
Browse files- components/AgentWorkflow.jsx +131 -0
components/AgentWorkflow.jsx
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from 'react'
|
| 2 |
+
import VoiceControl from './VoiceControl'
|
| 3 |
+
|
| 4 |
+
const AgentWorkflow = ({ language }) => {
|
| 5 |
+
const [tasks, setTasks] = useState([])
|
| 6 |
+
const [activeTask, setActiveTask] = useState(null)
|
| 7 |
+
const [output, setOutput] = useState('')
|
| 8 |
+
|
| 9 |
+
const handleCommand = (command) => {
|
| 10 |
+
const newTask = {
|
| 11 |
+
id: tasks.length + 1,
|
| 12 |
+
command,
|
| 13 |
+
status: 'pending',
|
| 14 |
+
steps: []
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
setTasks([...tasks, newTask])
|
| 18 |
+
setActiveTask(newTask.id)
|
| 19 |
+
|
| 20 |
+
// Simulate task execution
|
| 21 |
+
setTimeout(() => {
|
| 22 |
+
setTasks(prev => prev.map(task =>
|
| 23 |
+
task.id === newTask.id
|
| 24 |
+
? { ...task, status: 'completed', steps: [
|
| 25 |
+
{ id: 1, action: 'parse', result: 'success' },
|
| 26 |
+
{ id: 2, action: 'plan', result: 'success' },
|
| 27 |
+
{ id: 3, action: 'execute', result: 'success' }
|
| 28 |
+
]}
|
| 29 |
+
: task
|
| 30 |
+
))
|
| 31 |
+
|
| 32 |
+
setOutput(language === 'fa'
|
| 33 |
+
? `وظیفه "${command}" با موفقیت انجام شد.\n\nفایلهای تولید شده:\n- پروژه جدید React\n- تنظیمات اولیه\n- مثال کامپوننت\n\nدستور بعدی را بگویید یا بنویسید.`
|
| 34 |
+
: `Task "${command}" completed successfully.\n\nGenerated files:\n- New React project\n- Initial setup\n- Example component\n\nSay or type your next command.`)
|
| 35 |
+
}, 2000)
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return (
|
| 39 |
+
<div className="bg-white rounded-lg shadow-md p-4">
|
| 40 |
+
<h2 className="text-xl font-bold mb-4">
|
| 41 |
+
{language === 'fa' ? 'عامل هوشمند برنامهنویسی' : 'AI Programming Agent'}
|
| 42 |
+
</h2>
|
| 43 |
+
|
| 44 |
+
<VoiceControl language={language} onCommand={handleCommand} />
|
| 45 |
+
|
| 46 |
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-6">
|
| 47 |
+
<div className="md:col-span-1">
|
| 48 |
+
<h3 className="font-bold mb-2">
|
| 49 |
+
{language === 'fa' ? 'وظایف اخیر' : 'Recent Tasks'}
|
| 50 |
+
</h3>
|
| 51 |
+
<div className="border rounded-lg p-2 h-64 overflow-y-auto">
|
| 52 |
+
{tasks.length === 0 ? (
|
| 53 |
+
<p className="text-gray-500 text-center py-8">
|
| 54 |
+
{language === 'fa' ? 'هیچ وظیفهای ثبت نشده است' : 'No tasks recorded'}
|
| 55 |
+
</p>
|
| 56 |
+
) : (
|
| 57 |
+
<ul className="space-y-2">
|
| 58 |
+
{tasks.map(task => (
|
| 59 |
+
<li
|
| 60 |
+
key={task.id}
|
| 61 |
+
className={`p-2 rounded cursor-pointer ${activeTask === task.id ? 'bg-blue-100' : 'hover:bg-gray-100'}`}
|
| 62 |
+
onClick={() => setActiveTask(task.id)}
|
| 63 |
+
>
|
| 64 |
+
<div className="flex justify-between">
|
| 65 |
+
<span className="truncate">{task.command}</span>
|
| 66 |
+
<span className={`px-2 py-1 text-xs rounded-full ${
|
| 67 |
+
task.status === 'completed' ? 'bg-green-100 text-green-800' :
|
| 68 |
+
task.status === 'failed' ? 'bg-red-100 text-red-800' :
|
| 69 |
+
'bg-yellow-100 text-yellow-800'
|
| 70 |
+
}`}>
|
| 71 |
+
{task.status}
|
| 72 |
+
</span>
|
| 73 |
+
</div>
|
| 74 |
+
</li>
|
| 75 |
+
))}
|
| 76 |
+
</ul>
|
| 77 |
+
)}
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<div className="md:col-span-2">
|
| 82 |
+
<h3 className="font-bold mb-2">
|
| 83 |
+
{language === 'fa' ? 'جزئیات وظیفه' : 'Task Details'}
|
| 84 |
+
</h3>
|
| 85 |
+
<div className="border rounded-lg p-4 h-64 overflow-y-auto">
|
| 86 |
+
{activeTask ? (
|
| 87 |
+
<>
|
| 88 |
+
<h4 className="font-semibold mb-2">
|
| 89 |
+
{language === 'fa' ? 'دستور:' : 'Command:'} {tasks.find(t => t.id === activeTask)?.command}
|
| 90 |
+
</h4>
|
| 91 |
+
<div className="mb-4">
|
| 92 |
+
<h5 className="font-medium mb-1">
|
| 93 |
+
{language === 'fa' ? 'مراحل اجرا:' : 'Execution Steps:'}
|
| 94 |
+
</h5>
|
| 95 |
+
<ul className="space-y-1">
|
| 96 |
+
{tasks.find(t => t.id === activeTask)?.steps.map(step => (
|
| 97 |
+
<li key={step.id} className="flex items-center">
|
| 98 |
+
<span className={`inline-block w-2 h-2 rounded-full mr-2 ${
|
| 99 |
+
step.result === 'success' ? 'bg-green-500' : 'bg-red-500'
|
| 100 |
+
}`}></span>
|
| 101 |
+
{step.action} - {step.result}
|
| 102 |
+
</li>
|
| 103 |
+
))}
|
| 104 |
+
</ul>
|
| 105 |
+
</div>
|
| 106 |
+
<div>
|
| 107 |
+
<h5 className="font-medium mb-1">
|
| 108 |
+
{language === 'fa' ? 'خروجی:' : 'Output:'}
|
| 109 |
+
</h5>
|
| 110 |
+
<pre className="bg-gray-100 p-2 rounded text-sm whitespace-pre-wrap">
|
| 111 |
+
{output || (language === 'fa'
|
| 112 |
+
? 'هیچ خروجیای نمایش داده نشده است'
|
| 113 |
+
: 'No output displayed')}
|
| 114 |
+
</pre>
|
| 115 |
+
</div>
|
| 116 |
+
</>
|
| 117 |
+
) : (
|
| 118 |
+
<p className="text-gray-500 text-center py-8">
|
| 119 |
+
{language === 'fa'
|
| 120 |
+
? 'لطفاً یک وظیفه را انتخاب کنید'
|
| 121 |
+
: 'Please select a task'}
|
| 122 |
+
</p>
|
| 123 |
+
)}
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
)
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
export default AgentWorkflow
|