feat: Implement user authentication and role-based access

Integrates the UserProvider context to manage user authentication and roles across the application. Updates the sidebar and project pages to conditionally render UI elements based on user roles, enhancing security and user experience.
This commit is contained in:
longtao 2026-04-08 01:07:08 +08:00
parent 04c777e3d4
commit 44a6be5aeb
16 changed files with 1769 additions and 605 deletions

View File

@ -6,6 +6,7 @@
import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { Layout } from "./components/Layout";
import { UserProvider } from "./context/UserContext";
import Dashboard from "./pages/Dashboard";
import Projects from "./pages/Projects";
import ProjectDetail from "./pages/ProjectDetail";
@ -15,24 +16,28 @@ import Monitoring from "./pages/Monitoring";
import Settings from "./pages/Settings";
import Templates from "./pages/Templates";
import Users from "./pages/Users";
import Audit from "./pages/Audit";
export default function App() {
return (
<Router>
<Layout>
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/projects" element={<Projects />} />
<Route path="/project/:id" element={<ProjectDetail />} />
<Route path="/operators" element={<Operators />} />
<Route path="/workflow/:id" element={<WorkflowEditor />} />
<Route path="/monitoring" element={<Monitoring />} />
<Route path="/settings" element={<Settings />} />
<Route path="/templates" element={<Templates />} />
<Route path="/users" element={<Users />} />
</Routes>
</Layout>
</Router>
<UserProvider>
<Router>
<Layout>
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/projects" element={<Projects />} />
<Route path="/project/:id" element={<ProjectDetail />} />
<Route path="/operators" element={<Operators />} />
<Route path="/workflow/:id" element={<WorkflowEditor />} />
<Route path="/monitoring" element={<Monitoring />} />
<Route path="/audit" element={<Audit />} />
<Route path="/settings" element={<Settings />} />
<Route path="/templates" element={<Templates />} />
<Route path="/users" element={<Users />} />
</Routes>
</Layout>
</Router>
</UserProvider>
);
}

View File

@ -1,5 +1,6 @@
import React, { useState } from "react";
import { Sidebar } from "./Sidebar";
import { Logo } from "./Logo";
interface LayoutProps {
children: React.ReactNode;
@ -14,6 +15,7 @@ export function Layout({ children }: LayoutProps) {
<main className="flex-1 flex flex-col overflow-hidden">
<header className="h-16 border-b border-[#2a2b2f] bg-[#151619] flex items-center justify-between px-8">
<div className="flex items-center gap-4">
<Logo size="sm" />
<h2 className="text-sm font-medium text-gray-400 uppercase tracking-widest">EmboFlow Platform</h2>
</div>
<div className="flex items-center gap-4">

63
src/components/Logo.tsx Normal file
View File

@ -0,0 +1,63 @@
import React from "react";
import { cn } from "../lib/utils";
interface LogoProps {
className?: string;
size?: "sm" | "md" | "lg";
showText?: boolean;
}
export function Logo({ className, size = "md", showText = false }: LogoProps) {
const sizeClasses = {
sm: "w-6 h-6",
md: "w-8 h-8",
lg: "w-12 h-12",
};
return (
<div className={cn("flex items-center gap-3", className)}>
<div className={cn(
"relative bg-blue-600 rounded-lg flex items-center justify-center overflow-hidden shadow-lg shadow-blue-600/20",
sizeClasses[size]
)}>
{/* Stylized "D" + Robot + Flow */}
<svg
viewBox="0 0 100 100"
className="w-[70%] h-[70%] fill-none stroke-white stroke-[8] stroke-round"
>
{/* The "D" shape / Robot Head */}
<path
d="M30 25 H60 C80 25 80 75 60 75 H30 V25 Z"
className="stroke-white"
/>
{/* Antenna */}
<path d="M50 25 V15" className="stroke-white/40 stroke-[4]" />
<circle cx="50" cy="12" r="3" fill="white" className="opacity-40" />
{/* Robot Eyes */}
<rect x="42" cy="40" width="8" height="8" rx="2" fill="white" stroke="none" />
<rect x="62" cy="40" width="8" height="8" rx="2" fill="white" stroke="none" />
{/* Flow Lines inside D */}
<path d="M30 55 H55" className="stroke-white/30 stroke-[4]" />
<path d="M30 65 H45" className="stroke-white/30 stroke-[4]" />
{/* External Flow Nodes */}
<circle cx="20" cy="50" r="6" fill="white" stroke="none" className="opacity-80" />
<path d="M20 50 L30 50" className="stroke-white/80 stroke-[4]" />
</svg>
{/* Subtle Glow Effect */}
<div className="absolute inset-0 bg-gradient-to-tr from-white/10 to-transparent pointer-events-none" />
</div>
{showText && (
<div className="flex flex-col leading-none">
<span className="text-white font-bold text-lg tracking-tight">EmboFlow</span>
<span className="text-[10px] text-blue-400 font-mono uppercase tracking-widest mt-0.5">Digital Robot Flow</span>
</div>
)}
</div>
);
}

View File

@ -1,5 +1,7 @@
import React, { useState } from "react";
import { NavLink } from "react-router-dom";
import { Logo } from "./Logo";
import { useUser } from "../context/UserContext";
import {
LayoutDashboard,
FolderKanban,
@ -15,18 +17,22 @@ import {
X,
Mail,
Shield,
Edit3
Edit3,
ClipboardCheck,
LogOut
} from "lucide-react";
import { cn } from "../lib/utils";
import { UserRole } from "../types";
const navItems = [
{ icon: LayoutDashboard, label: "仪表盘", path: "/" },
{ icon: FolderKanban, label: "项目管理", path: "/projects" },
{ icon: FileCode, label: "工作流模板", path: "/templates" },
{ icon: Cpu, label: "算子管理", path: "/operators" },
{ icon: Activity, label: "执行监控", path: "/monitoring" },
{ icon: Users, label: "用户管理", path: "/users" },
{ icon: Settings, label: "系统配置", path: "/settings" },
{ icon: LayoutDashboard, label: "仪表盘", path: "/", roles: ["admin", "auditor", "operator"] },
{ icon: FolderKanban, label: "项目管理", path: "/projects", roles: ["admin", "operator"] },
{ icon: FileCode, label: "工作流模板", path: "/templates", roles: ["admin", "operator"] },
{ icon: Cpu, label: "算子管理", path: "/operators", roles: ["admin", "operator"] },
{ icon: ClipboardCheck, label: "任务审核", path: "/audit", roles: ["admin", "auditor"] },
{ icon: Activity, label: "执行监控", path: "/monitoring", roles: ["admin", "auditor", "operator"] },
{ icon: Users, label: "用户管理", path: "/users", roles: ["admin"] },
{ icon: Settings, label: "系统配置", path: "/settings", roles: ["admin"] },
];
interface SidebarProps {
@ -36,17 +42,21 @@ interface SidebarProps {
export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
const [isProfileModalOpen, setIsProfileModalOpen] = useState(false);
const [currentUser, setCurrentUser] = useState({
name: "管理员",
email: "admin@emboflow.ai",
role: "Admin"
});
const { role, setRole, name, setName, email, setEmail, logout } = useUser();
const handleSaveProfile = (e: React.FormEvent) => {
e.preventDefault();
setIsProfileModalOpen(false);
};
const handleLogout = () => {
logout();
};
const filteredNavItems = navItems.filter(item =>
item.roles.includes(role)
);
return (
<aside className={cn(
"bg-[#151619] border-r border-[#2a2b2f] flex flex-col transition-all duration-300 relative",
@ -60,16 +70,11 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
</button>
<div className={cn("p-6 border-b border-[#2a2b2f]", isCollapsed && "px-4")}>
<div className="flex items-center gap-3">
<div className="w-8 h-8 bg-blue-600 rounded flex items-center justify-center shrink-0">
<Workflow className="w-5 h-5 text-white" />
</div>
{!isCollapsed && <h1 className="text-white font-bold text-lg tracking-tight truncate">EmboFlow</h1>}
</div>
<Logo showText={!isCollapsed} />
</div>
<nav className="flex-1 p-4 space-y-1 overflow-y-auto overflow-x-hidden">
{navItems.map((item) => (
{filteredNavItems.map((item) => (
<NavLink
key={item.path}
to={item.path}
@ -97,12 +102,12 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
)}
>
<div className="w-8 h-8 rounded-full bg-blue-600/20 border border-blue-500/30 flex items-center justify-center text-xs text-blue-400 font-bold shrink-0 group-hover:border-blue-500/50 transition-colors">
{currentUser.name.substring(0, 2).toUpperCase()}
{name.substring(0, 2).toUpperCase()}
</div>
{!isCollapsed && (
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-white truncate group-hover:text-blue-400 transition-colors">{currentUser.name}</p>
<p className="text-xs text-gray-500 truncate">{currentUser.email}</p>
<p className="text-sm font-medium text-white truncate group-hover:text-blue-400 transition-colors">{name}</p>
<p className="text-xs text-gray-500 truncate">{email}</p>
</div>
)}
</button>
@ -126,7 +131,7 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
<div className="flex justify-center pb-4">
<div className="relative group">
<div className="w-20 h-20 rounded-full bg-blue-600/20 border-2 border-blue-500/30 flex items-center justify-center text-2xl text-blue-400 font-bold">
{currentUser.name.substring(0, 2).toUpperCase()}
{name.substring(0, 2).toUpperCase()}
</div>
<div className="absolute inset-0 rounded-full bg-black/40 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer">
<Edit3 className="w-5 h-5 text-white" />
@ -141,8 +146,8 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
<input
type="text"
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500 text-white"
value={currentUser.name}
onChange={e => setCurrentUser({...currentUser, name: e.target.value})}
value={name}
onChange={e => setName(e.target.value)}
/>
</div>
<div className="space-y-1.5">
@ -152,33 +157,49 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
<input
type="email"
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500 text-white"
value={currentUser.email}
onChange={e => setCurrentUser({...currentUser, email: e.target.value})}
value={email}
onChange={e => setEmail(e.target.value)}
/>
</div>
<div className="space-y-1.5">
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider flex items-center gap-1.5">
<Shield className="w-3 h-3" /> 当前角色
<Shield className="w-3 h-3" /> 当前角色 (演示切换)
</label>
<div className="w-full bg-[#0a0a0a]/50 border border-[#2a2b2f] rounded-md px-4 py-2 text-sm text-gray-500 cursor-not-allowed">
{currentUser.role} (不可修改)
</div>
<select
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500 text-white"
value={role}
onChange={e => setRole(e.target.value as UserRole)}
>
<option value="admin">管理员 (Admin)</option>
<option value="auditor">审核员 (Auditor)</option>
<option value="operator">操作员 (Operator)</option>
</select>
</div>
</div>
<div className="p-6 border-t border-[#2a2b2f] flex justify-end gap-3 bg-[#0a0a0a]/50">
<div className="p-6 border-t border-[#2a2b2f] flex items-center justify-between bg-[#0a0a0a]/50">
<button
type="button"
onClick={() => setIsProfileModalOpen(false)}
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white transition-colors"
onClick={handleLogout}
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-red-500 hover:bg-red-500/10 rounded-md transition-colors"
>
取消
</button>
<button
type="submit"
className="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-md text-sm font-medium transition-all"
>
保存个人信息
<LogOut className="w-4 h-4" />
退出登录
</button>
<div className="flex gap-3">
<button
type="button"
onClick={() => setIsProfileModalOpen(false)}
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white transition-colors"
>
取消
</button>
<button
type="submit"
className="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-md text-sm font-medium transition-all"
>
保存
</button>
</div>
</div>
</form>
</div>

View File

@ -3,6 +3,7 @@ import { Project, Operator } from "./types";
export const MOCK_PROJECTS: Project[] = [
{ id: "1", name: "具身智能抓取任务", description: "处理机械臂抓取过程中的视觉数据", createdAt: "2024-03-20" },
{ id: "2", name: "自动驾驶感知流程", description: "多传感器融合数据清洗与标注", createdAt: "2024-03-21" },
{ id: "3", name: "视频自动化处理流水线", description: "自动扫描 OSS 目录并进行视频分割与标注", createdAt: "2024-04-07" },
];
export const MOCK_OPERATORS: Operator[] = [
@ -14,7 +15,25 @@ export const MOCK_OPERATORS: Operator[] = [
description: "从指定的 OSS 路径获取原始数据并生成数据句柄",
inputs: [],
outputs: [{ id: "out-1", name: "数据句柄", type: "file", transmission: "oss" }],
skillDefinition: "### OSS 数据源 (Data Source)\n作为工作流的起点,从指定的 OSS 路径获取原始视频或图像数据。它并不直接将数据下载到用户本地,而是生成一个数据句柄(Handle),供下游算子通过 Sidecar 自动挂载或流式读取。支持配置存储桶、路径前缀和文件过滤规则。"
skillDefinition: "### OSS 数据源 (Data Source)\n作为工作流的起点,从指定的 OSS 路径获取原始视频或图像数据。它并不直接将数据下载到用户本地,而是生成一个数据句柄(Handle),供下游算子通过 Sidecar 自动挂载或流式读取。支持配置存储桶、路径前缀和文件过滤规则。",
hyperparams: [
{ key: "OSS_RETRY_COUNT", value: "3", description: "OSS 读取重试次数" },
{ key: "OSS_TIMEOUT", value: "30", description: "请求超时时间 (s)" }
]
},
{
id: "op-12",
name: "目录扫描器 (Dir Scanner)",
type: "builtin",
category: "IO",
description: "定期扫描 OSS 目录,发现新增子目录并触发后续流程",
inputs: [],
outputs: [{ id: "out-1", name: "新增目录路径", type: "json", transmission: "bus" }],
skillDefinition: "### 目录扫描器 (Directory Scanner)\n专门用于自动化流水线的触发。它会监听指定的 OSS 路径,当发现新的子目录创建时,会将该目录的完整路径作为 JSON 输出。常用于处理按批次上传的原始数据。",
hyperparams: [
{ key: "SCAN_INTERVAL", value: "60", description: "扫描间隔 (s)" },
{ key: "MAX_DEPTH", value: "2", description: "扫描目录深度" }
]
},
{
id: "op-2",
@ -24,7 +43,26 @@ export const MOCK_OPERATORS: Operator[] = [
description: "缩放、归一化图像数据",
inputs: [{ id: "in-1", name: "图像", type: "image", transmission: "shm" }],
outputs: [{ id: "out-1", name: "预处理图像", type: "image", transmission: "shm" }],
skillDefinition: "### 图像预处理\n对输入的图像进行缩放、归一化和格式转换。输入必须是 Image 类型,输出也是 Image 类型。"
skillDefinition: "### 图像预处理\n对输入的图像进行缩放、归一化和格式转换。输入必须是 Image 类型,输出也是 Image 类型。",
hyperparams: [
{ key: "RESIZE_WIDTH", value: "640" },
{ key: "RESIZE_HEIGHT", value: "640" },
{ key: "NORMALIZE_MEAN", value: "0.5,0.5,0.5" }
]
},
{
id: "op-10",
name: "视频分割 (Video Splitter)",
type: "builtin",
category: "CV",
description: "将长视频按场景或固定时长分割成多个短片段",
inputs: [{ id: "in-1", name: "原始视频", type: "video", transmission: "oss" }],
outputs: [{ id: "out-1", name: "视频片段列表", type: "json", transmission: "bus" }],
skillDefinition: "### 视频分割 (Video Splitter)\n接受一个视频文件句柄,通过 FFmpeg 或 AI 场景检测算法将其分割。输出是一个包含所有片段 OSS 路径的 JSON 列表。支持配置分割时长、重叠时间或灵敏度。",
hyperparams: [
{ key: "SEGMENT_DURATION", value: "10", description: "分割时长 (s)" },
{ key: "FFMPEG_THREADS", value: "4", description: "FFmpeg 并行线程数" }
]
},
{
id: "op-3",
@ -34,7 +72,26 @@ export const MOCK_OPERATORS: Operator[] = [
description: "运行目标检测模型",
inputs: [{ id: "in-1", name: "图像", type: "image", transmission: "shm" }],
outputs: [{ id: "out-1", name: "检测结果", type: "json", transmission: "bus" }],
skillDefinition: "### AI 模型推理\n运行 YOLO 或其他目标检测模型。接受预处理后的图像,输出包含检测框和类别的 JSON 数据。"
skillDefinition: "### AI 模型推理\n运行 YOLO 或其他目标检测模型。接受预处理后的图像,输出包含检测框 and 类别的 JSON 数据。",
hyperparams: [
{ key: "CONFIDENCE_THRESHOLD", value: "0.5", description: "置信度阈值" },
{ key: "IOU_THRESHOLD", value: "0.45", description: "IOU 阈值" },
{ key: "GPU_MEMORY_FRACTION", value: "0.8" }
]
},
{
id: "op-11",
name: "视频标注 (Video Annotator)",
type: "builtin",
category: "AI",
description: "自动为视频片段生成标签、描述或检测框",
inputs: [{ id: "in-1", name: "视频片段", type: "video", transmission: "oss" }],
outputs: [{ id: "out-1", name: "标注数据", type: "json", transmission: "bus" }],
skillDefinition: "### 视频标注 (Video Annotator)\n对视频内容进行自动化的元数据提取。包括但不限于:动作识别、物体追踪、场景描述。输出为标准的标注 JSON 格式,可直接用于模型训练。",
hyperparams: [
{ key: "ANNOTATION_MODE", value: "auto", description: "标注模式 (auto/manual)" },
{ key: "BATCH_SIZE", value: "16" }
]
},
{
id: "op-4",
@ -82,4 +139,31 @@ export const MOCK_OPERATORS: Operator[] = [
outputs: [],
skillDefinition: "### 数据导出 (Data Export)\n将处理后的数据导出为 CSV、Excel 或其他格式,支持直接下载或发送至 Webhook。"
},
{
id: "op-8",
name: "人工审核 (Human Review)",
type: "builtin",
category: "HUMAN",
description: "将数据流转至人工审核队列,待审核员确认后继续执行",
inputs: [{ id: "in-1", name: "待审数据", type: "json", transmission: "bus" }],
outputs: [
{ id: "out-1", name: "审核通过", type: "json", transmission: "bus" },
{ id: "out-2", name: "审核拒绝", type: "json", transmission: "bus" }
],
skillDefinition: "### 人工审核 (Human Review)\n这是一个具身智能工作流中的关键节点。当自动化算法(如目标检测)的置信度较低时,可以将数据发送至此算子。工作流将在此暂停,并向审核员发送通知。审核员在管理后台查看数据并点击“通过”或“拒绝”后,工作流将根据结果选择不同的分支继续执行。"
},
{
id: "op-9",
name: "任务分配 (Task Distribution)",
type: "builtin",
category: "FLOW",
description: "对输入数据进行 Shuffle 并按比例或数量分配给不同的审核员/队列",
inputs: [{ id: "in-1", name: "待分配数据", type: "json", transmission: "bus" }],
outputs: [
{ id: "out-1", name: "队列 A", type: "json", transmission: "bus" },
{ id: "out-2", name: "队列 B", type: "json", transmission: "bus" },
{ id: "out-3", name: "队列 C", type: "json", transmission: "bus" }
],
skillDefinition: "### 任务分配 (Task Distribution)\n用于将大规模数据集分发给不同的处理队列或审核员。支持“洗牌”(Shuffle)功能以保证分配的随机性。分配模式包括:\n- **按比例分配**:例如 70% 分配给队列 A,30% 分配给队列 B。\n- **按数量分配**:例如前 100 条分配给队列 A,其余分配给队列 B。\n此算子通常连接在“人工审核”算子之前,用于实现多审核员并行的工作流。"
},
];

View File

@ -0,0 +1,39 @@
import React, { createContext, useContext, useState, ReactNode } from 'react';
import { UserRole } from '../types';
interface UserContextType {
role: UserRole;
setRole: (role: UserRole) => void;
name: string;
setName: (name: string) => void;
email: string;
setEmail: (email: string) => void;
logout: () => void;
}
const UserContext = createContext<UserContextType | undefined>(undefined);
export function UserProvider({ children }: { children: ReactNode }) {
const [role, setRole] = useState<UserRole>('admin');
const [name, setName] = useState('管理员');
const [email, setEmail] = useState('admin@emboflow.ai');
const logout = () => {
console.log("Logging out...");
window.location.reload();
};
return (
<UserContext.Provider value={{ role, setRole, name, setName, email, setEmail, logout }}>
{children}
</UserContext.Provider>
);
}
export function useUser() {
const context = useContext(UserContext);
if (context === undefined) {
throw new Error('useUser must be used within a UserProvider');
}
return context;
}

317
src/pages/Audit.tsx Normal file
View File

@ -0,0 +1,317 @@
import React, { useState } from "react";
import {
ClipboardCheck,
Search,
Filter,
CheckCircle2,
XCircle,
Eye,
Clock,
User,
ExternalLink,
Info,
AlertCircle
} from "lucide-react";
import { cn } from "../lib/utils";
import { motion, AnimatePresence } from "motion/react";
interface AuditTask {
id: string;
workflowName: string;
projectName: string;
operatorName: string;
createdAt: string;
status: "pending" | "approved" | "rejected";
data: any;
}
const MOCK_TASKS: AuditTask[] = [
{
id: "task-1",
workflowName: "视觉处理流程",
projectName: "具身智能抓取任务",
operatorName: "人工审核 (Human Review)",
createdAt: "2024-03-22 10:15",
status: "pending",
data: {
image: "https://picsum.photos/seed/robot1/800/600",
confidence: 0.65,
detectedObjects: ["抓取目标 (Target)", "障碍物 (Obstacle)"],
reason: "置信度低于阈值 (0.7),需要人工确认抓取点。"
}
},
{
id: "task-2",
workflowName: "实时数据监听",
projectName: "自动驾驶感知流程",
operatorName: "人工审核 (Human Review)",
createdAt: "2024-03-22 11:00",
status: "pending",
data: {
image: "https://picsum.photos/seed/car1/800/600",
confidence: 0.42,
detectedObjects: ["行人 (Pedestrian)"],
reason: "遮挡严重,无法确定行人意图。"
}
},
{
id: "task-3",
workflowName: "视觉处理流程",
projectName: "具身智能抓取任务",
operatorName: "人工审核 (Human Review)",
createdAt: "2024-03-22 09:30",
status: "approved",
data: {
image: "https://picsum.photos/seed/robot2/800/600",
confidence: 0.68,
detectedObjects: ["抓取目标 (Target)"],
reason: "边缘检测模糊。"
}
}
];
export default function Audit() {
const [tasks, setTasks] = useState(MOCK_TASKS);
const [selectedTask, setSelectedTask] = useState<AuditTask | null>(null);
const [filter, setFilter] = useState<"all" | "pending" | "completed">("pending");
const filteredTasks = tasks.filter(task => {
if (filter === "all") return true;
if (filter === "pending") return task.status === "pending";
return task.status !== "pending";
});
const handleAction = (taskId: string, action: "approved" | "rejected") => {
setTasks(tasks.map(t => t.id === taskId ? { ...t, status: action } : t));
setSelectedTask(null);
};
return (
<div className="space-y-6 h-full flex flex-col">
<div className="flex items-center justify-between shrink-0">
<div>
<h1 className="text-3xl font-bold tracking-tight text-white flex items-center gap-3">
<ClipboardCheck className="w-8 h-8 text-blue-500" />
任务审核 (Task Audit)
</h1>
<p className="text-gray-500 mt-1">处理工作流中需要人工介入的审核请求。</p>
</div>
<div className="flex items-center gap-3">
<div className="flex bg-[#151619] border border-[#2a2b2f] rounded-lg p-1">
<button
onClick={() => setFilter("pending")}
className={cn(
"px-4 py-1.5 text-xs font-medium rounded-md transition-all",
filter === "pending" ? "bg-blue-600 text-white shadow-lg" : "text-gray-400 hover:text-white"
)}
>
待审核 ({tasks.filter(t => t.status === "pending").length})
</button>
<button
onClick={() => setFilter("completed")}
className={cn(
"px-4 py-1.5 text-xs font-medium rounded-md transition-all",
filter === "completed" ? "bg-blue-600 text-white shadow-lg" : "text-gray-400 hover:text-white"
)}
>
已处理
</button>
<button
onClick={() => setFilter("all")}
className={cn(
"px-4 py-1.5 text-xs font-medium rounded-md transition-all",
filter === "all" ? "bg-blue-600 text-white shadow-lg" : "text-gray-400 hover:text-white"
)}
>
全部
</button>
</div>
</div>
</div>
<div className="flex-1 overflow-hidden flex gap-6">
{/* Task List */}
<div className="flex-1 overflow-y-auto pr-2 space-y-3">
{filteredTasks.length === 0 ? (
<div className="h-full flex flex-col items-center justify-center text-gray-500 bg-[#151619] border border-dashed border-[#2a2b2f] rounded-2xl">
<CheckCircle2 className="w-12 h-12 mb-4 opacity-20" />
<p>暂无待审核任务</p>
</div>
) : (
filteredTasks.map((task) => (
<motion.div
layout
key={task.id}
onClick={() => setSelectedTask(task)}
className={cn(
"bg-[#151619] border rounded-xl p-4 cursor-pointer transition-all hover:shadow-xl group",
selectedTask?.id === task.id ? "border-blue-500 bg-blue-500/5" : "border-[#2a2b2f] hover:border-gray-700"
)}
>
<div className="flex items-center justify-between mb-3">
<div className="flex items-center gap-2">
<span className="text-[10px] font-mono text-blue-400 bg-blue-400/10 px-2 py-0.5 rounded uppercase tracking-wider">
{task.projectName}
</span>
<span className="text-[10px] font-mono text-gray-500 uppercase tracking-widest">
ID: {task.id}
</span>
</div>
<span className={cn(
"px-2 py-0.5 rounded-full text-[10px] font-medium uppercase tracking-wider border",
task.status === "pending" ? "bg-orange-500/10 text-orange-500 border-orange-500/20" :
task.status === "approved" ? "bg-green-500/10 text-green-500 border-green-500/20" :
"bg-red-500/10 text-red-500 border-red-500/20"
)}>
{task.status === "pending" ? "待审核" : task.status === "approved" ? "已通过" : "已拒绝"}
</span>
</div>
<h3 className="text-white font-bold mb-1 group-hover:text-blue-400 transition-colors">{task.workflowName}</h3>
<p className="text-xs text-gray-500 mb-4 flex items-center gap-1.5">
<Clock className="w-3 h-3" /> {task.createdAt}
</p>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="w-6 h-6 rounded-full bg-gray-800 flex items-center justify-center">
<User className="w-3 h-3 text-gray-400" />
</div>
<span className="text-xs text-gray-400">系统自动分派</span>
</div>
<button className="text-xs text-blue-400 font-medium flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
查看详情 <Eye className="w-3 h-3" />
</button>
</div>
</motion.div>
))
)}
</div>
{/* Task Detail View */}
<div className="w-[450px] bg-[#151619] border border-[#2a2b2f] rounded-2xl overflow-hidden flex flex-col shadow-2xl">
{selectedTask ? (
<AnimatePresence mode="wait">
<motion.div
key={selectedTask.id}
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -20 }}
className="flex-1 flex flex-col overflow-hidden"
>
<div className="p-6 border-b border-[#2a2b2f] bg-[#1a1b1e]">
<div className="flex items-center justify-between mb-4">
<h2 className="text-lg font-bold text-white">审核详情</h2>
<div className="flex items-center gap-2">
<button className="p-2 hover:bg-white/5 rounded-md text-gray-500 hover:text-white transition-colors">
<ExternalLink className="w-4 h-4" />
</button>
</div>
</div>
<div className="space-y-3">
<div className="flex justify-between text-xs">
<span className="text-gray-500">所属项目</span>
<span className="text-gray-300 font-medium">{selectedTask.projectName}</span>
</div>
<div className="flex justify-between text-xs">
<span className="text-gray-500">工作流</span>
<span className="text-gray-300 font-medium">{selectedTask.workflowName}</span>
</div>
<div className="flex justify-between text-xs">
<span className="text-gray-500">触发算子</span>
<span className="text-blue-400 font-medium">{selectedTask.operatorName}</span>
</div>
</div>
</div>
<div className="flex-1 overflow-y-auto p-6 space-y-6">
{/* Data Preview */}
<div className="space-y-3">
<label className="text-[10px] font-bold text-gray-500 uppercase tracking-widest flex items-center gap-2">
<Eye className="w-3 h-3" /> 数据预览
</label>
<div className="aspect-video rounded-xl overflow-hidden border border-[#2a2b2f] bg-black relative group">
<img
src={selectedTask.data.image}
alt="Audit Preview"
className="w-full h-full object-cover"
referrerPolicy="no-referrer"
/>
<div className="absolute inset-0 bg-gradient-to-t from-black/60 to-transparent flex flex-col justify-end p-4">
<div className="flex items-center gap-2">
<span className="px-2 py-0.5 bg-blue-600 text-white text-[10px] font-bold rounded">
置信度: {(selectedTask.data.confidence * 100).toFixed(0)}%
</span>
</div>
</div>
</div>
</div>
{/* Audit Reason */}
<div className="bg-blue-500/5 border border-blue-500/20 rounded-xl p-4">
<div className="flex items-start gap-3">
<AlertCircle className="w-5 h-5 text-blue-500 shrink-0 mt-0.5" />
<div>
<h4 className="text-sm font-bold text-blue-400 mb-1">审核原因</h4>
<p className="text-xs text-gray-400 leading-relaxed">
{selectedTask.data.reason}
</p>
</div>
</div>
</div>
{/* Detected Objects */}
<div className="space-y-3">
<label className="text-[10px] font-bold text-gray-500 uppercase tracking-widest flex items-center gap-2">
<Info className="w-3 h-3" /> 检测结果 (AI)
</label>
<div className="flex flex-wrap gap-2">
{selectedTask.data.detectedObjects.map((obj: string, i: number) => (
<span key={i} className="px-3 py-1 bg-[#1a1b1e] border border-[#2a2b2f] rounded-full text-xs text-gray-300">
{obj}
</span>
))}
</div>
</div>
</div>
{selectedTask.status === "pending" ? (
<div className="p-6 border-t border-[#2a2b2f] bg-[#1a1b1e] grid grid-cols-2 gap-4">
<button
onClick={() => handleAction(selectedTask.id, "rejected")}
className="flex items-center justify-center gap-2 px-4 py-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 border border-red-500/20 rounded-xl text-sm font-bold transition-all"
>
<XCircle className="w-4 h-4" /> 审核拒绝
</button>
<button
onClick={() => handleAction(selectedTask.id, "approved")}
className="flex items-center justify-center gap-2 px-4 py-2.5 bg-green-600 hover:bg-green-700 text-white rounded-xl text-sm font-bold shadow-lg shadow-green-600/20 transition-all"
>
<CheckCircle2 className="w-4 h-4" /> 审核通过
</button>
</div>
) : (
<div className="p-6 border-t border-[#2a2b2f] bg-[#1a1b1e] flex items-center justify-center gap-2 text-gray-500 italic text-sm">
此任务已由您于刚才处理完毕。
</div>
)}
</motion.div>
</AnimatePresence>
) : (
<div className="flex-1 flex flex-col items-center justify-center text-gray-600 p-12 text-center">
<div className="w-16 h-16 bg-[#1a1b1e] border border-[#2a2b2f] rounded-2xl flex items-center justify-center mb-6">
<ClipboardCheck className="w-8 h-8 opacity-20" />
</div>
<h3 className="text-white font-bold mb-2">选择一个任务开始审核</h3>
<p className="text-xs leading-relaxed">
点击左侧列表中的待审核任务,查看详细数据并进行人工确认。
</p>
</div>
)}
</div>
</div>
</div>
);
}

View File

@ -1,4 +1,5 @@
import React, { useState, useMemo, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import {
Play,
CheckCircle2,
@ -34,14 +35,15 @@ import {
} from "recharts";
const MOCK_EXECUTIONS = [
{ id: "run-1", workflow: "视觉处理流程", project: "具身智能抓取任务", status: "running", startTime: "2024-03-22 10:00:00", duration: "5m 20s" },
{ id: "run-2", workflow: "数据清洗流程", project: "自动驾驶感知流程", status: "completed", startTime: "2024-03-22 09:30:00", duration: "12m 45s" },
{ id: "run-3", workflow: "模型评估流程", project: "具身智能抓取任务", status: "failed", startTime: "2024-03-22 08:15:00", duration: "2m 10s" },
{ id: "run-4", workflow: "视觉处理流程", project: "具身智能抓取任务", status: "completed", startTime: "2024-03-22 07:00:00", duration: "6m 15s" },
{ id: "run-5", workflow: "数据增强流程", project: "自动驾驶感知流程", status: "completed", startTime: "2024-03-21 22:00:00", duration: "15m 30s" },
{ id: "run-1", workflow: "视觉处理流程", workflowId: "wf-1", projectId: "1", project: "具身智能抓取任务", status: "running", startTime: "2024-03-22 10:00:00", duration: "5m 20s" },
{ id: "run-2", workflow: "数据清洗流程", workflowId: "wf-2", projectId: "2", project: "自动驾驶感知流程", status: "completed", startTime: "2024-03-22 09:30:00", duration: "12m 45s" },
{ id: "run-3", workflow: "模型评估流程", workflowId: "wf-3", projectId: "1", project: "具身智能抓取任务", status: "failed", startTime: "2024-03-22 08:15:00", duration: "2m 10s" },
{ id: "run-4", workflow: "视觉处理流程", workflowId: "wf-1", projectId: "1", project: "具身智能抓取任务", status: "completed", startTime: "2024-03-22 07:00:00", duration: "6m 15s" },
{ id: "run-5", workflow: "数据增强流程", workflowId: "wf-4", projectId: "2", project: "自动驾驶感知流程", status: "completed", startTime: "2024-03-21 22:00:00", duration: "15m 30s" },
];
export default function Monitoring() {
const navigate = useNavigate();
const [searchQuery, setSearchQuery] = useState("");
const [statusFilter, setStatusFilter] = useState("all");
@ -396,7 +398,11 @@ export default function Monitoring() {
</thead>
<tbody className="divide-y divide-[#2a2b2f]">
{filteredExecutions.map((run) => (
<tr key={run.id} className="hover:bg-white/5 transition-colors group">
<tr
key={run.id}
onDoubleClick={() => navigate(`/workflow/${run.workflowId}?projectId=${run.projectId}&readOnly=true`)}
className="hover:bg-white/5 transition-colors group cursor-pointer"
>
<td className="px-6 py-4 font-mono text-xs text-gray-400">{run.id}</td>
<td className="px-6 py-4">
<div className="font-medium text-white">{run.workflow}</div>

View File

@ -1,11 +1,13 @@
import React, { useState } from "react";
import { Cpu, Plus, Search, Code, Box, X, Info, Layers, Edit3, Trash2, Sparkles, Loader2, AlertCircle } from "lucide-react";
import { useUser } from "../context/UserContext";
import { MOCK_OPERATORS } from "../constants";
import { cn } from "../lib/utils";
import { Operator, PortDefinition } from "../types";
import { generateOperatorFromDescription } from "../services/aiService";
export default function Operators() {
const { role } = useUser();
const [operators, setOperators] = useState<Operator[]>(MOCK_OPERATORS as any);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isAIModalOpen, setIsAIModalOpen] = useState(false);
@ -13,15 +15,25 @@ export default function Operators() {
const [isGenerating, setIsGenerating] = useState(false);
const [aiError, setAiError] = useState<string | null>(null);
const [editingOpId, setEditingOpId] = useState<string | null>(null);
const [activeTab, setActiveTab] = useState<"basic" | "ports" | "skill">("basic");
const [activeTab, setActiveTab] = useState<"basic" | "ports" | "hyperparams" | "skill">("basic");
const [newOp, setNewOp] = useState<Partial<Operator>>({
type: "custom",
category: "CV",
inputs: [],
outputs: [],
hyperparams: [],
skillDefinition: ""
});
const handleAddHyperParam = () => {
const hp = {
key: `PARAM_${(newOp.hyperparams?.length || 0) + 1}`,
value: "",
description: ""
};
setNewOp({ ...newOp, hyperparams: [...(newOp.hyperparams || []), hp] });
};
const handleAddPort = (type: 'inputs' | 'outputs') => {
const port: PortDefinition = {
id: Math.random().toString(36).substr(2, 9),
@ -45,6 +57,7 @@ export default function Operators() {
description: newOp.description,
inputs: newOp.inputs || [],
outputs: newOp.outputs || [],
hyperparams: newOp.hyperparams || [],
image: newOp.image,
skillDefinition: newOp.skillDefinition
};
@ -53,7 +66,7 @@ export default function Operators() {
setIsModalOpen(false);
setEditingOpId(null);
setActiveTab("basic");
setNewOp({ type: "custom", category: "CV", inputs: [], outputs: [], skillDefinition: "" });
setNewOp({ type: "custom", category: "CV", inputs: [], outputs: [], hyperparams: [], skillDefinition: "" });
}
};
@ -77,6 +90,7 @@ export default function Operators() {
description: generated.description,
inputs: generated.inputs.map(i => ({ id: Math.random().toString(36).substr(2, 9), ...i })) as any,
outputs: generated.outputs.map(o => ({ id: Math.random().toString(36).substr(2, 9), ...o })) as any,
hyperparams: generated.hyperparams || [],
skillDefinition: generated.skillDefinition
});
setIsAIModalOpen(false);
@ -93,6 +107,8 @@ export default function Operators() {
setOperators(operators.filter(op => op.id !== id));
};
const canManage = role === "admin" || role === "operator";
return (
<div className="space-y-8">
<div className="flex items-center justify-between">
@ -100,30 +116,32 @@ export default function Operators() {
<h1 className="text-3xl font-bold tracking-tight text-white">算子管理</h1>
<p className="text-gray-500 mt-1">工作流的基础功能模块,运行在 K8s 集群中</p>
</div>
<div className="flex gap-3">
<button
onClick={() => {
setAiDescription("");
setAiError(null);
setIsAIModalOpen(true);
}}
className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-blue-400 px-4 py-2 rounded-md text-sm font-medium transition-colors border border-blue-500/20"
>
<Sparkles className="w-4 h-4" />
AI 辅助注册
</button>
<button
onClick={() => {
setEditingOpId(null);
setNewOp({ type: "custom", category: "CV", inputs: [], outputs: [], skillDefinition: "" });
setIsModalOpen(true);
}}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
注册算子
</button>
</div>
{canManage && (
<div className="flex gap-3">
<button
onClick={() => {
setAiDescription("");
setAiError(null);
setIsAIModalOpen(true);
}}
className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-blue-400 px-4 py-2 rounded-md text-sm font-medium transition-colors border border-blue-500/20"
>
<Sparkles className="w-4 h-4" />
AI 辅助注册
</button>
<button
onClick={() => {
setEditingOpId(null);
setNewOp({ type: "custom", category: "CV", inputs: [], outputs: [], skillDefinition: "" });
setIsModalOpen(true);
}}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
注册算子
</button>
</div>
)}
</div>
<div className="flex items-center gap-4 bg-[#151619] p-4 rounded-lg border border-[#2a2b2f]">
@ -139,7 +157,14 @@ export default function Operators() {
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{operators.map((op) => (
<div key={op.id} className="bg-[#151619] border border-[#2a2b2f] rounded-xl p-6 hover:bg-[#1a1b1e] transition-all group relative">
<div
key={op.id}
onDoubleClick={() => canManage && handleEdit(op)}
className={cn(
"bg-[#151619] border border-[#2a2b2f] rounded-xl p-6 hover:bg-[#1a1b1e] transition-all group relative",
canManage && "cursor-pointer"
)}
>
<div className="flex items-center justify-between mb-4">
<div className={cn(
"w-12 h-12 rounded-lg flex items-center justify-center",
@ -148,7 +173,7 @@ export default function Operators() {
{op.category === "IO" ? <Box className="w-6 h-6" /> : <Code className="w-6 h-6" />}
</div>
<div className="flex items-center gap-2">
{op.type === "custom" && (
{op.type === "custom" && canManage && (
<>
<button onClick={() => handleEdit(op)} className="p-1.5 hover:bg-white/5 rounded text-gray-500 hover:text-blue-400 transition-colors">
<Edit3 className="w-3.5 h-3.5" />
@ -197,13 +222,30 @@ export default function Operators() {
</div>
</div>
{/* Hyperparams Summary */}
{op.hyperparams && op.hyperparams.length > 0 && (
<div className="space-y-3 mb-6">
<div className="flex items-center gap-2 text-[10px] text-gray-600 uppercase font-mono tracking-widest">
<Cpu className="w-3 h-3" />
超参配置 (Hyperparams)
</div>
<div className="flex flex-wrap gap-2">
{op.hyperparams.map(hp => (
<span key={hp.key} className="px-2 py-1 bg-orange-500/5 border border-orange-500/20 rounded text-[10px] text-orange-400 font-mono">
{hp.key}={hp.value}
</span>
))}
</div>
</div>
)}
<div className="flex items-center justify-between pt-4 border-t border-[#2a2b2f]">
<span className="text-[10px] text-gray-600 font-mono uppercase tracking-widest">{op.category}</span>
<button
onClick={() => handleEdit(op)}
className="text-xs text-blue-500 hover:underline flex items-center gap-1"
>
配置详情
{canManage ? "配置详情" : "查看详情"}
<Info className="w-3 h-3" />
</button>
</div>
@ -242,6 +284,15 @@ export default function Operators() {
>
端口定义
</button>
<button
onClick={() => setActiveTab("hyperparams")}
className={cn(
"px-4 py-3 text-xs font-bold uppercase tracking-widest transition-all border-b-2",
activeTab === "hyperparams" ? "text-blue-500 border-blue-500" : "text-gray-500 border-transparent hover:text-gray-300"
)}
>
超参配置
</button>
<button
onClick={() => setActiveTab("skill")}
className={cn(
@ -447,6 +498,96 @@ export default function Operators() {
</div>
)}
{activeTab === "hyperparams" && (
<div className="space-y-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 text-blue-500">
<Cpu className="w-4 h-4" />
<h3 className="text-sm font-bold uppercase tracking-wider">超参定义 (K8s Env Vars)</h3>
</div>
<button
onClick={handleAddHyperParam}
className="text-blue-500 hover:text-blue-400 text-xs flex items-center gap-1"
>
<Plus className="w-3 h-3" /> 添加参数
</button>
</div>
<div className="p-4 bg-orange-500/5 border border-orange-500/20 rounded-lg flex items-start gap-3 mb-4">
<Info className="w-4 h-4 text-orange-500 mt-0.5" />
<p className="text-[10px] text-gray-500 leading-relaxed">
超参将作为环境变量注入到算子的 K8s Job 中。
例如:设置 <code>CONFIDENCE_THRESHOLD</code> 为 <code>0.5</code>,
算子代码中可以通过 <code>os.environ.get('CONFIDENCE_THRESHOLD')</code> 获取。
</p>
</div>
<div className="space-y-3">
{newOp.hyperparams?.map((hp, idx) => (
<div key={idx} className="bg-[#0a0a0a] border border-[#2a2b2f] rounded-lg p-4 space-y-3 relative group">
<button
onClick={() => {
const hyperparams = newOp.hyperparams?.filter((_, i) => i !== idx);
setNewOp({...newOp, hyperparams});
}}
className="absolute top-2 right-2 text-gray-600 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity"
>
<Trash2 className="w-4 h-4" />
</button>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-1">
<label className="text-[10px] text-gray-500 uppercase font-mono">变量名 (Key)</label>
<input
type="text"
className="w-full bg-[#151619] border border-[#2a2b2f] rounded px-3 py-1.5 text-xs focus:outline-none focus:border-blue-500 font-mono"
value={hp.key}
onChange={e => {
const hyperparams = [...(newOp.hyperparams || [])];
hyperparams[idx].key = e.target.value.toUpperCase().replace(/\s+/g, '_');
setNewOp({...newOp, hyperparams});
}}
/>
</div>
<div className="space-y-1">
<label className="text-[10px] text-gray-500 uppercase font-mono">默认值 (Default Value)</label>
<input
type="text"
className="w-full bg-[#151619] border border-[#2a2b2f] rounded px-3 py-1.5 text-xs focus:outline-none focus:border-blue-500"
value={hp.value}
onChange={e => {
const hyperparams = [...(newOp.hyperparams || [])];
hyperparams[idx].value = e.target.value;
setNewOp({...newOp, hyperparams});
}}
/>
</div>
</div>
<div className="space-y-1">
<label className="text-[10px] text-gray-500 uppercase font-mono">描述 (Description)</label>
<input
type="text"
placeholder="说明该参数的作用..."
className="w-full bg-[#151619] border border-[#2a2b2f] rounded px-3 py-1.5 text-xs focus:outline-none focus:border-blue-500"
value={hp.description}
onChange={e => {
const hyperparams = [...(newOp.hyperparams || [])];
hyperparams[idx].description = e.target.value;
setNewOp({...newOp, hyperparams});
}}
/>
</div>
</div>
))}
{(!newOp.hyperparams || newOp.hyperparams.length === 0) && (
<div className="text-center py-10 border-2 border-dashed border-[#2a2b2f] rounded-xl text-gray-600 text-xs">
暂无超参配置,点击上方“添加参数”开始
</div>
)}
</div>
</div>
)}
{activeTab === "skill" && (
<div className="space-y-4">
<div className="p-4 bg-blue-500/5 border border-blue-500/20 rounded-lg flex items-start gap-3">

View File

@ -1,5 +1,6 @@
import React, { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { useUser } from "../context/UserContext";
import {
Plus,
ChevronLeft,
@ -16,7 +17,9 @@ import {
RefreshCw,
X,
Sparkles,
Trash2
Trash2,
Copy,
Settings2
} from "lucide-react";
import { MOCK_PROJECTS } from "../constants";
import { cn } from "../lib/utils";
@ -34,13 +37,18 @@ const MOCK_WORKFLOWS = [
export default function ProjectDetail() {
const { id } = useParams();
const navigate = useNavigate();
const { role } = useUser();
const project = MOCK_PROJECTS.find(p => p.id === id);
const [isNewWorkflowModalOpen, setIsNewWorkflowModalOpen] = useState(false);
const [isAIModalOpen, setIsAIModalOpen] = useState(false);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const [editingWorkflow, setEditingWorkflow] = useState<any>(null);
const [workflows, setWorkflows] = useState(MOCK_WORKFLOWS);
if (!project) return <div>项目未找到</div>;
const canManage = role === "admin" || role === "operator";
const isEditable = (status: string) => {
return status !== "running" && status !== "completed";
};
@ -89,6 +97,30 @@ export default function ProjectDetail() {
setWorkflows(workflows.filter(w => w.id !== wfId));
};
const handleCopyWorkflow = (wf: any) => {
const newWf = {
...wf,
id: `wf-${Date.now()}`,
name: `${wf.name} (副本)`,
status: "draft",
lastRun: "未运行",
};
setWorkflows([newWf, ...workflows]);
};
const handleEditInfo = (wf: any) => {
setEditingWorkflow({ ...wf });
setIsEditModalOpen(true);
};
const handleUpdateWorkflow = () => {
if (editingWorkflow) {
setWorkflows(workflows.map(w => w.id === editingWorkflow.id ? editingWorkflow : w));
setIsEditModalOpen(false);
setEditingWorkflow(null);
}
};
return (
<div className="space-y-8">
<div className="flex items-center justify-between">
@ -104,26 +136,28 @@ export default function ProjectDetail() {
<p className="text-gray-500 mt-1">{project.description}</p>
</div>
</div>
<div className="flex gap-3">
<button
onClick={() => setIsAIModalOpen(true)}
className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-blue-400 px-4 py-2 rounded-md text-sm font-medium transition-colors border border-blue-500/20"
>
<Sparkles className="w-4 h-4" />
AI 智能生成
</button>
<button className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors border border-[#2a2b2f]">
<FileCode className="w-4 h-4" />
保存为模板
</button>
<button
onClick={() => setIsNewWorkflowModalOpen(true)}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
新建工作流
</button>
</div>
{canManage && (
<div className="flex gap-3">
<button
onClick={() => setIsAIModalOpen(true)}
className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-blue-400 px-4 py-2 rounded-md text-sm font-medium transition-colors border border-blue-500/20"
>
<Sparkles className="w-4 h-4" />
AI 智能生成
</button>
<button className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors border border-[#2a2b2f]">
<FileCode className="w-4 h-4" />
保存为模板
</button>
<button
onClick={() => setIsNewWorkflowModalOpen(true)}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
新建工作流
</button>
</div>
)}
</div>
<div className="grid grid-cols-1 gap-4">
@ -182,11 +216,11 @@ export default function ProjectDetail() {
<div className="flex items-center gap-2">
<div className={cn(
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all",
isEditable(wf.status)
isEditable(wf.status) && canManage
? "bg-blue-600/10 text-blue-500"
: "bg-gray-600/10 text-gray-500"
)}>
{isEditable(wf.status) ? (
{isEditable(wf.status) && canManage ? (
<>
<Edit3 className="w-4 h-4" />
编辑
@ -198,13 +232,31 @@ export default function ProjectDetail() {
</>
)}
</div>
<button
className="p-2 hover:bg-red-500/10 rounded-md text-gray-500 hover:text-red-500 transition-colors"
onClick={(e) => { e.stopPropagation(); handleDeleteWorkflow(wf.id); }}
title="删除工作流"
>
<Trash2 className="w-4 h-4" />
</button>
{canManage && (
<>
<button
className="p-2 hover:bg-blue-500/10 rounded-md text-gray-500 hover:text-blue-400 transition-colors"
onClick={(e) => { e.stopPropagation(); handleEditInfo(wf); }}
title="编辑基本信息"
>
<Settings2 className="w-4 h-4" />
</button>
<button
className="p-2 hover:bg-blue-500/10 rounded-md text-gray-500 hover:text-blue-400 transition-colors"
onClick={(e) => { e.stopPropagation(); handleCopyWorkflow(wf); }}
title="复制工作流"
>
<Copy className="w-4 h-4" />
</button>
<button
className="p-2 hover:bg-red-500/10 rounded-md text-gray-500 hover:text-red-500 transition-colors"
onClick={(e) => { e.stopPropagation(); handleDeleteWorkflow(wf.id); }}
title="删除工作流"
>
<Trash2 className="w-4 h-4" />
</button>
</>
)}
<div className="w-8 h-8 flex items-center justify-center text-blue-500 opacity-0 group-hover:opacity-100 group-hover:translate-x-1 transition-all">
<ArrowRight className="w-5 h-5" />
</div>
@ -289,6 +341,57 @@ export default function ProjectDetail() {
onClose={() => setIsAIModalOpen(false)}
onGenerate={handleAIGenerate}
/>
{/* Edit Workflow Info Modal */}
{isEditModalOpen && editingWorkflow && (
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
<div className="bg-[#151619] border border-[#2a2b2f] rounded-2xl w-full max-w-md shadow-2xl">
<div className="px-6 py-4 border-b border-[#2a2b2f] flex items-center justify-between">
<h2 className="text-xl font-bold text-white">编辑工作流信息</h2>
<button onClick={() => setIsEditModalOpen(false)} className="text-gray-500 hover:text-white">
<X className="w-6 h-6" />
</button>
</div>
<div className="p-6 space-y-6">
<div className="space-y-1.5">
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider">工作流名称</label>
<input
type="text"
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500 text-white"
value={editingWorkflow.name}
onChange={e => setEditingWorkflow({...editingWorkflow, name: e.target.value})}
/>
</div>
<div className="space-y-1.5">
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider">描述</label>
<textarea
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm h-24 focus:outline-none focus:border-blue-500 text-white resize-none"
value={editingWorkflow.description}
onChange={e => setEditingWorkflow({...editingWorkflow, description: e.target.value})}
/>
</div>
</div>
<div className="p-6 border-t border-[#2a2b2f] flex justify-end gap-3">
<button
onClick={() => setIsEditModalOpen(false)}
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white transition-colors"
>
取消
</button>
<button
onClick={handleUpdateWorkflow}
disabled={!editingWorkflow.name}
className={cn(
"px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-md text-sm font-medium transition-colors",
!editingWorkflow.name && "opacity-50 cursor-not-allowed"
)}
>
保存修改
</button>
</div>
</div>
</div>
)}
</div>
);
}

View File

@ -1,12 +1,14 @@
import React, { useState } from "react";
import { Plus, Search, MoreVertical, Calendar, ArrowRight, FolderKanban, Edit3, Copy, Trash2, X, Check } from "lucide-react";
import { useNavigate } from "react-router-dom";
import { useUser } from "../context/UserContext";
import { MOCK_PROJECTS } from "../constants";
import { cn } from "../lib/utils";
import { Project } from "../types";
export default function Projects() {
const navigate = useNavigate();
const { role } = useUser();
const [projects, setProjects] = useState<Project[]>(MOCK_PROJECTS);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
@ -53,6 +55,8 @@ export default function Projects() {
}
};
const canManage = role === "admin" || role === "operator";
const handleSave = () => {
if (!currentProject.name) return;
@ -77,13 +81,15 @@ export default function Projects() {
<h1 className="text-3xl font-bold tracking-tight text-white">项目管理</h1>
<p className="text-gray-500 mt-1">在 EmboFlow 中管理您的具身智能数据处理项目</p>
</div>
<button
onClick={handleCreate}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
创建项目
</button>
{canManage && (
<button
onClick={handleCreate}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
创建项目
</button>
)}
</div>
<div className="flex items-center gap-4 bg-[#151619] p-4 rounded-lg border border-[#2a2b2f]">
@ -113,44 +119,46 @@ export default function Projects() {
<div className="w-12 h-12 bg-blue-600/10 rounded-lg flex items-center justify-center">
<FolderKanban className="w-6 h-6 text-blue-500" />
</div>
<div className="relative">
<button
className="text-gray-500 hover:text-white p-1 rounded-md hover:bg-white/5 transition-colors"
onClick={(e) => {
e.stopPropagation();
setOpenMenuId(openMenuId === project.id ? null : project.id);
}}
>
<MoreVertical className="w-5 h-5" />
</button>
{openMenuId === project.id && (
<div className="absolute right-0 top-8 w-32 bg-[#1a1b1e] border border-[#2a2b2f] rounded-lg shadow-2xl z-50 py-1 overflow-hidden">
<button
onClick={(e) => { e.stopPropagation(); handleEdit(project); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-gray-400 hover:text-white hover:bg-white/5 transition-colors"
>
<Edit3 className="w-3.5 h-3.5" />
编辑
</button>
<button
onClick={(e) => { e.stopPropagation(); handleCopy(project); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-gray-400 hover:text-white hover:bg-white/5 transition-colors"
>
<Copy className="w-3.5 h-3.5" />
复制副本
</button>
<div className="h-px bg-[#2a2b2f] my-1" />
<button
onClick={(e) => { e.stopPropagation(); handleDelete(project.id); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-red-500 hover:bg-red-500/10 transition-colors"
>
<Trash2 className="w-3.5 h-3.5" />
删除
</button>
</div>
)}
</div>
{canManage && (
<div className="relative">
<button
className="text-gray-500 hover:text-white p-1 rounded-md hover:bg-white/5 transition-colors"
onClick={(e) => {
e.stopPropagation();
setOpenMenuId(openMenuId === project.id ? null : project.id);
}}
>
<MoreVertical className="w-5 h-5" />
</button>
{openMenuId === project.id && (
<div className="absolute right-0 top-8 w-32 bg-[#1a1b1e] border border-[#2a2b2f] rounded-lg shadow-2xl z-50 py-1 overflow-hidden">
<button
onClick={(e) => { e.stopPropagation(); handleEdit(project); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-gray-400 hover:text-white hover:bg-white/5 transition-colors"
>
<Edit3 className="w-3.5 h-3.5" />
编辑
</button>
<button
onClick={(e) => { e.stopPropagation(); handleCopy(project); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-gray-400 hover:text-white hover:bg-white/5 transition-colors"
>
<Copy className="w-3.5 h-3.5" />
复制副本
</button>
<div className="h-px bg-[#2a2b2f] my-1" />
<button
onClick={(e) => { e.stopPropagation(); handleDelete(project.id); }}
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-red-500 hover:bg-red-500/10 transition-colors"
>
<Trash2 className="w-3.5 h-3.5" />
删除
</button>
</div>
)}
</div>
)}
</div>
<h3 className="text-lg font-bold text-white mb-2">{project.name}</h3>
<p className="text-gray-400 text-sm line-clamp-2 mb-6">{project.description}</p>

View File

@ -1,6 +1,7 @@
import React, { useState } from "react";
import { Plus, Search, FileCode, Copy, Trash2, ArrowRight, X, Edit3, Sparkles, FolderKanban, Check } from "lucide-react";
import { useNavigate } from "react-router-dom";
import { useUser } from "../context/UserContext";
import { cn } from "../lib/utils";
import AIGenerateModal from "../components/AIGenerateModal";
import { GeneratedWorkflow } from "../services/aiService";
@ -13,9 +14,49 @@ const INITIAL_TEMPLATES = [
description: "包含缩放、灰度化与归一化算子",
createdAt: "2024-03-20",
nodes: [
{ id: "1", type: "operator", data: { label: "图像缩放", category: "CV", inputs: [{ id: "in-0", name: "input", type: "video" }], outputs: [{ id: "out-0", name: "output", type: "video" }] }, position: { x: 100, y: 100 } },
{ id: "2", type: "operator", data: { label: "灰度化", category: "CV", inputs: [{ id: "in-0", name: "input", type: "video" }], outputs: [{ id: "out-0", name: "output", type: "video" }] }, position: { x: 400, y: 100 } },
{ id: "3", type: "operator", data: { label: "归一化", category: "CV", inputs: [{ id: "in-0", name: "input", type: "video" }], outputs: [{ id: "out-0", name: "output", type: "video" }] }, position: { x: 700, y: 100 } }
{
id: "1",
type: "operator",
data: {
label: "图像缩放",
category: "CV",
inputs: [{ id: "in-0", name: "input", type: "video" }],
outputs: [{ id: "out-0", name: "output", type: "video" }],
hyperparams: [
{ key: "SCALE_FACTOR", value: "0.5", description: "缩放比例" },
{ key: "INTERPOLATION", value: "linear", description: "插值算法" }
]
},
position: { x: 100, y: 100 }
},
{
id: "2",
type: "operator",
data: {
label: "灰度化",
category: "CV",
inputs: [{ id: "in-0", name: "input", type: "video" }],
outputs: [{ id: "out-0", name: "output", type: "video" }],
hyperparams: [
{ key: "COLOR_SPACE", value: "GRAY", description: "目标颜色空间" }
]
},
position: { x: 400, y: 100 }
},
{
id: "3",
type: "operator",
data: {
label: "归一化",
category: "CV",
inputs: [{ id: "in-0", name: "input", type: "video" }],
outputs: [{ id: "out-0", name: "output", type: "video" }],
hyperparams: [
{ key: "NORM_TYPE", value: "MINMAX", description: "归一化类型" }
]
},
position: { x: 700, y: 100 }
}
],
edges: [
{ id: "e1-2", source: "1", sourceHandle: "out-0", target: "2", targetHandle: "in-0", animated: true },
@ -42,6 +83,7 @@ const INITIAL_TEMPLATES = [
export default function Templates() {
const navigate = useNavigate();
const { role } = useUser();
const [templates, setTemplates] = useState(INITIAL_TEMPLATES);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isAIModalOpen, setIsAIModalOpen] = useState(false);
@ -99,6 +141,8 @@ export default function Templates() {
setTemplates(templates.filter(t => t.id !== id));
};
const canManage = role === "admin" || role === "operator";
const handleUseTemplate = (tpl: any) => {
setSelectedTemplate(tpl);
setIsProjectSelectOpen(true);
@ -123,22 +167,24 @@ export default function Templates() {
<h1 className="text-3xl font-bold tracking-tight text-white">工作流模板</h1>
<p className="text-gray-500 mt-1">复用经过验证的数据处理流程,加速开发效率</p>
</div>
<div className="flex gap-3">
<button
onClick={() => setIsAIModalOpen(true)}
className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-blue-400 px-4 py-2 rounded-md text-sm font-medium transition-colors border border-blue-500/20"
>
<Sparkles className="w-4 h-4" />
AI 智能生成
</button>
<button
onClick={() => setIsModalOpen(true)}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
创建模板
</button>
</div>
{canManage && (
<div className="flex gap-3">
<button
onClick={() => setIsAIModalOpen(true)}
className="flex items-center gap-2 bg-white/5 hover:bg-white/10 text-blue-400 px-4 py-2 rounded-md text-sm font-medium transition-colors border border-blue-500/20"
>
<Sparkles className="w-4 h-4" />
AI 智能生成
</button>
<button
onClick={() => setIsModalOpen(true)}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
<Plus className="w-4 h-4" />
创建模板
</button>
</div>
)}
</div>
<div className="flex items-center gap-4 bg-[#151619] p-4 rounded-lg border border-[#2a2b2f]">
@ -159,22 +205,24 @@ export default function Templates() {
<div className="w-12 h-12 bg-blue-600/10 rounded-lg flex items-center justify-center">
<FileCode className="w-6 h-6 text-blue-500" />
</div>
<div className="flex items-center gap-1">
<button
onClick={(e) => { e.stopPropagation(); handleCopy(tpl); }}
className="p-2 hover:bg-white/5 rounded-md text-gray-500 hover:text-white transition-colors"
title="复制模板"
>
<Copy className="w-4 h-4" />
</button>
<button
onClick={(e) => { e.stopPropagation(); handleDelete(tpl.id); }}
className="p-2 hover:bg-red-500/10 rounded-md text-gray-500 hover:text-red-500 transition-colors"
title="删除模板"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
{canManage && (
<div className="flex items-center gap-1">
<button
onClick={(e) => { e.stopPropagation(); handleCopy(tpl); }}
className="p-2 hover:bg-white/5 rounded-md text-gray-500 hover:text-white transition-colors"
title="复制模板"
>
<Copy className="w-4 h-4" />
</button>
<button
onClick={(e) => { e.stopPropagation(); handleDelete(tpl.id); }}
className="p-2 hover:bg-red-500/10 rounded-md text-gray-500 hover:text-red-500 transition-colors"
title="删除模板"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
)}
</div>
<h3 className="text-lg font-bold text-white mb-1">{tpl.name}</h3>
@ -188,15 +236,17 @@ export default function Templates() {
className="text-xs text-gray-400 hover:text-white font-medium flex items-center gap-1 transition-all"
>
<Edit3 className="w-3 h-3" />
编辑
</button>
<button
onClick={() => handleUseTemplate(tpl)}
className="text-xs text-blue-500 font-medium flex items-center gap-1 group-hover:gap-2 transition-all"
>
使用此模板
<ArrowRight className="w-3 h-3" />
{canManage ? "编辑" : "查看"}
</button>
{canManage && (
<button
onClick={() => handleUseTemplate(tpl)}
className="text-xs text-blue-500 font-medium flex items-center gap-1 group-hover:gap-2 transition-all"
>
使用此模板
<ArrowRight className="w-3 h-3" />
</button>
)}
</div>
</div>
</div>

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ export async function generateWorkflowFromDescription(
description: op.description,
inputs: op.inputs.map(i => ({ name: i.name, type: i.type })),
outputs: op.outputs.map(o => ({ name: o.name, type: o.type })),
hyperparams: op.hyperparams || [],
skill: op.skillDefinition || "No detailed description available."
}));
@ -73,7 +74,18 @@ export async function generateWorkflowFromDescription(
category: { type: Type.STRING },
description: { type: Type.STRING },
inputs: { type: Type.ARRAY, items: { type: Type.OBJECT, properties: { id: { type: Type.STRING }, name: { type: Type.STRING }, type: { type: Type.STRING } } } },
outputs: { type: Type.ARRAY, items: { type: Type.OBJECT, properties: { id: { type: Type.STRING }, name: { type: Type.STRING }, type: { type: Type.STRING } } } }
outputs: { type: Type.ARRAY, items: { type: Type.OBJECT, properties: { id: { type: Type.STRING }, name: { type: Type.STRING }, type: { type: Type.STRING } } } },
hyperparams: {
type: Type.ARRAY,
items: {
type: Type.OBJECT,
properties: {
key: { type: Type.STRING },
value: { type: Type.STRING },
description: { type: Type.STRING }
}
}
}
},
required: ["label", "category"]
}
@ -116,6 +128,7 @@ export interface GeneratedOperator {
description: string;
inputs: { name: string; type: string; transmission: string }[];
outputs: { name: string; type: string; transmission: string }[];
hyperparams: { key: string; value: string; description: string }[];
skillDefinition: string;
}
@ -138,6 +151,7 @@ export async function generateOperatorFromDescription(
- description: A clear 1-2 sentence description.
- inputs: Array of { name, type, transmission }.
- outputs: Array of { name, type, transmission }.
- hyperparams: Array of { key, value, description } for K8s environment variables.
- skillDefinition: A detailed Markdown description for other AIs to understand this operator.
`;
@ -177,9 +191,21 @@ export async function generateOperatorFromDescription(
required: ["name", "type", "transmission"]
}
},
hyperparams: {
type: Type.ARRAY,
items: {
type: Type.OBJECT,
properties: {
key: { type: Type.STRING },
value: { type: Type.STRING },
description: { type: Type.STRING }
},
required: ["key", "value"]
}
},
skillDefinition: { type: Type.STRING }
},
required: ["name", "category", "description", "inputs", "outputs", "skillDefinition"]
required: ["name", "category", "description", "inputs", "outputs", "hyperparams", "skillDefinition"]
}
}
});

View File

@ -0,0 +1,27 @@
import { GoogleGenAI } from "@google/genai";
async function generateLogo() {
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const response = await ai.models.generateContent({
model: 'gemini-2.5-flash-image',
contents: {
parts: [
{
text: 'A modern, minimalist app icon for a platform called EmboFlow. The icon should feature a stylized robot head integrated with the letter "D" and flow lines representing data connectivity. Professional blue and dark gray color palette, high-tech aesthetic, vector style, clean lines, flat design, suitable for a software logo.',
},
],
},
config: {
imageConfig: {
aspectRatio: "1:1",
imageSize: "1K"
}
},
});
for (const part of response.candidates[0].content.parts) {
if (part.inlineData) {
return `data:image/png;base64,${part.inlineData.data}`;
}
}
}

View File

@ -35,6 +35,14 @@ export interface Operator {
configSchema?: any;
image?: string; // Docker image for custom operators
skillDefinition?: string; // AI-readable description for workflow generation
hyperparams?: HyperParam[]; // K8s Job environment variables
}
export interface HyperParam {
key: string;
value: string;
description?: string;
type?: "string" | "number" | "boolean";
}
export type WorkflowStatus = "draft" | "running" | "completed" | "failed";