侧边栏添加 进行中任务 组件,显示所有当前正在生成的任务,点击后可跳转到对应页面,切换页面后状态不会丢失
| | |
| | | |
| | | SANDBOX_DIR = os.path.join(settings.CODE_DIR, "result", "sandbox") |
| | | SANDBOX_HISTORY_FILE = os.path.join(SANDBOX_DIR, "history.json") |
| | | SANDBOX_ACTIVE_TASKS: dict[str, dict] = {} |
| | | |
| | | # 确保目录存在 |
| | | os.makedirs(SANDBOX_DIR, exist_ok=True) |
| | |
| | | return converted |
| | | |
| | | |
| | | def _add_record(tool: str, model: str, input_data: dict, output_data: dict, files: List[str] = None) -> str: |
| | | def _add_record(tool: str, model: str, input_data: dict, output_data: dict, files: List[str] = None, record_id: str | None = None) -> str: |
| | | """添加历史记录""" |
| | | record_id = str(uuid.uuid4().hex[:8]) |
| | | record_id = record_id or str(uuid.uuid4().hex[:8]) |
| | | # 转换路径为相对路径格式 |
| | | output_data = _convert_output_paths(output_data) |
| | | record = { |
| | |
| | | history.insert(0, record) # 最新记录放在最前面 |
| | | _save_history(history) |
| | | return record_id |
| | | |
| | | |
| | | def _start_active_task(tool: str, model: str, input_data: dict) -> str: |
| | | task_id = str(uuid.uuid4().hex[:8]) |
| | | SANDBOX_ACTIVE_TASKS[task_id] = { |
| | | "id": task_id, |
| | | "tool": tool, |
| | | "model": model, |
| | | "input": input_data, |
| | | "status": "running", |
| | | "progress": 1, |
| | | "created_at": datetime.now().isoformat(), |
| | | } |
| | | return task_id |
| | | |
| | | |
| | | def _finish_active_task(task_id: str) -> None: |
| | | SANDBOX_ACTIVE_TASKS.pop(task_id, None) |
| | | |
| | | |
| | | def _delete_record_files(files: List[str]): |
| | |
| | | for r in history |
| | | ] |
| | | } |
| | | |
| | | |
| | | @router.get("/api/sandbox/tasks") |
| | | async def sandbox_get_active_tasks(): |
| | | """获取临时工作台正在执行的任务""" |
| | | return {"success": True, "tasks": list(SANDBOX_ACTIVE_TASKS.values())} |
| | | |
| | | |
| | | @router.get("/api/sandbox/history/{record_id}") |
| | |
| | | """临时工作台 - LLM 文字生成""" |
| | | from models.llm_client import LLM |
| | | client = LLM() |
| | | input_data = {"prompt": req.prompt, "web_search": req.web_search} |
| | | task_id = _start_active_task("llm", req.model, input_data) |
| | | try: |
| | | logger.info("Sandbox LLM started: model=%s web_search=%s", req.model, req.web_search) |
| | | result = await run_in_threadpool( |
| | |
| | | record_id = _add_record( |
| | | tool="llm", |
| | | model=req.model, |
| | | input_data={"prompt": req.prompt, "web_search": req.web_search}, |
| | | output_data={"response": result} |
| | | input_data=input_data, |
| | | output_data={"response": result}, |
| | | record_id=task_id, |
| | | ) |
| | | logger.info("Sandbox LLM completed: model=%s record_id=%s", req.model, record_id) |
| | | return {"success": True, "result": result, "record_id": record_id} |
| | | except Exception as e: |
| | | logger.exception("Sandbox LLM failed: model=%s", req.model) |
| | | return {"success": False, "error": str(e)} |
| | | finally: |
| | | _finish_active_task(task_id) |
| | | |
| | | |
| | | @router.post("/api/sandbox/vlm") |
| | |
| | | """临时工作台 - VLM 图片理解""" |
| | | from models.vlm_client import VLM |
| | | client = VLM() |
| | | input_data = {"prompt": req.prompt, "images": req.images} |
| | | task_id = _start_active_task("vlm", req.model, input_data) |
| | | try: |
| | | logger.info("Sandbox VLM started: model=%s images=%d", req.model, len(req.images or [])) |
| | | result = await run_in_threadpool( |
| | |
| | | record_id = _add_record( |
| | | tool="vlm", |
| | | model=req.model, |
| | | input_data={"prompt": req.prompt, "images": req.images}, |
| | | output_data={"response": result} |
| | | input_data=input_data, |
| | | output_data={"response": result}, |
| | | record_id=task_id, |
| | | ) |
| | | logger.info("Sandbox VLM completed: model=%s record_id=%s", req.model, record_id) |
| | | return {"success": True, "result": result, "record_id": record_id} |
| | | except Exception as e: |
| | | logger.exception("Sandbox VLM failed: model=%s", req.model) |
| | | return {"success": False, "error": str(e)} |
| | | finally: |
| | | _finish_active_task(task_id) |
| | | |
| | | |
| | | @router.post("/api/sandbox/t2i") |
| | |
| | | """临时工作台 - 文生图""" |
| | | from models.image_client import ImageClient |
| | | client = ImageClient() |
| | | input_data = {"prompt": req.prompt, "style": req.style, "ratio": req.ratio} |
| | | task_id = _start_active_task("t2i", req.model, input_data) |
| | | try: |
| | | logger.info("Sandbox T2I started: model=%s ratio=%s", req.model, req.ratio) |
| | | result = await run_in_threadpool( |
| | |
| | | record_id = _add_record( |
| | | tool="t2i", |
| | | model=req.model, |
| | | input_data={"prompt": req.prompt, "style": req.style, "ratio": req.ratio}, |
| | | input_data=input_data, |
| | | output_data={"images": result}, |
| | | files=result if isinstance(result, list) else [] |
| | | files=result if isinstance(result, list) else [], |
| | | record_id=task_id, |
| | | ) |
| | | logger.info( |
| | | "Sandbox T2I completed: model=%s record_id=%s images=%d", |
| | |
| | | except Exception as e: |
| | | logger.exception("Sandbox T2I failed: model=%s", req.model) |
| | | return {"success": False, "error": str(e)} |
| | | finally: |
| | | _finish_active_task(task_id) |
| | | |
| | | |
| | | @router.post("/api/sandbox/i2i") |
| | |
| | | """临时工作台 - 图生图""" |
| | | from models.image_client import ImageClient |
| | | client = ImageClient() |
| | | input_data = {"prompt": req.prompt, "reference_image": req.image} |
| | | task_id = _start_active_task("i2i", req.model, input_data) |
| | | try: |
| | | logger.info("Sandbox I2I started: model=%s ratio=%s", req.model, req.ratio) |
| | | result = await run_in_threadpool( |
| | |
| | | record_id = _add_record( |
| | | tool="i2i", |
| | | model=req.model, |
| | | input_data={"prompt": req.prompt, "reference_image": req.image}, |
| | | input_data=input_data, |
| | | output_data={"images": result}, |
| | | files=result if isinstance(result, list) else [] |
| | | files=result if isinstance(result, list) else [], |
| | | record_id=task_id, |
| | | ) |
| | | logger.info( |
| | | "Sandbox I2I completed: model=%s record_id=%s images=%d", |
| | |
| | | except Exception as e: |
| | | logger.exception("Sandbox I2I failed: model=%s", req.model) |
| | | return {"success": False, "error": str(e)} |
| | | finally: |
| | | _finish_active_task(task_id) |
| | | |
| | | |
| | | @router.post("/api/sandbox/video") |
| | |
| | | """临时工作台 - 视频生成""" |
| | | from models.video_client import VideoClient |
| | | client = VideoClient() |
| | | input_data = {"prompt": req.prompt, "reference_image": req.image} |
| | | task_id = _start_active_task("video", req.model, input_data) |
| | | try: |
| | | # 生成唯一的保存路径 |
| | | save_dir = os.path.join(SANDBOX_DIR, "videos") |
| | |
| | | record_id = _add_record( |
| | | tool="video", |
| | | model=req.model, |
| | | input_data={"prompt": req.prompt, "reference_image": req.image}, |
| | | input_data=input_data, |
| | | output_data={"video": result, "video_path": save_path}, |
| | | files=[save_path] |
| | | files=[save_path], |
| | | record_id=task_id, |
| | | ) |
| | | logger.info("Sandbox video completed: model=%s record_id=%s video=%s", req.model, record_id, save_path) |
| | | return {"success": True, "result": result, "video_path": save_path, "record_id": record_id} |
| | | except Exception as e: |
| | | logger.exception("Sandbox video failed: model=%s", req.model) |
| | | return {"success": False, "error": str(e)} |
| | | finally: |
| | | _finish_active_task(task_id) |
| | |
| | | import { Suspense } from 'react'; |
| | | import PipelinePage from '@/components/pipelines/PipelinePage'; |
| | | |
| | | export default function ActionTransferPipelinePage() { |
| | | return ( |
| | | <PipelinePage |
| | | pipeline="action_transfer" |
| | | title="动作迁移" |
| | | subtitle="用参考图片和动作视频生成角色动作迁移结果" |
| | | /> |
| | | <Suspense fallback={null}> |
| | | <PipelinePage |
| | | pipeline="action_transfer" |
| | | title="动作迁移" |
| | | subtitle="用参考图片和动作视频生成角色动作迁移结果" |
| | | /> |
| | | </Suspense> |
| | | ); |
| | | } |
| | |
| | | import { Suspense } from 'react'; |
| | | import PipelinePage from '@/components/pipelines/PipelinePage'; |
| | | |
| | | export default function DigitalHumanPipelinePage() { |
| | | return ( |
| | | <PipelinePage |
| | | pipeline="digital_human" |
| | | title="数字人口播" |
| | | subtitle="基于人物图片和文案生成数字人口播视频" |
| | | /> |
| | | <Suspense fallback={null}> |
| | | <PipelinePage |
| | | pipeline="digital_human" |
| | | title="数字人口播" |
| | | subtitle="基于人物图片和文案生成数字人口播视频" |
| | | /> |
| | | </Suspense> |
| | | ); |
| | | } |
| | |
| | | import { Suspense } from 'react'; |
| | | import PipelinePage from '@/components/pipelines/PipelinePage'; |
| | | |
| | | export default function StandardPipelinePage() { |
| | | return ( |
| | | <PipelinePage |
| | | pipeline="standard" |
| | | title="文艺短视频" |
| | | subtitle="输入创作灵感或完整文案,生成图片拼接或动态视频短片" |
| | | /> |
| | | <Suspense fallback={null}> |
| | | <PipelinePage |
| | | pipeline="standard" |
| | | title="文艺短视频" |
| | | subtitle="输入创作灵感或完整文案,生成图片拼接或动态视频短片" |
| | | /> |
| | | </Suspense> |
| | | ); |
| | | } |
| | |
| | | 'use client'; |
| | | |
| | | import Link from 'next/link'; |
| | | import { usePathname } from 'next/navigation'; |
| | | import { ChevronLeft, ChevronRight, Clapperboard, Hexagon, Home, PanelLeftOpen, Repeat2, Settings, UserRound } from 'lucide-react'; |
| | | import { usePathname, useRouter } from 'next/navigation'; |
| | | import { ChevronLeft, ChevronRight, Clapperboard, Clock, Hexagon, Home, Loader2, PanelLeftOpen, Repeat2, Settings, UserRound } from 'lucide-react'; |
| | | import clsx from 'clsx'; |
| | | import { useState } from 'react'; |
| | | import { useEffect, useState } from 'react'; |
| | | import { fetchPipelineTasks, fetchSandboxTasks, fetchSessions, type PipelineTask, type SandboxTask } from '@/lib/workflowApi'; |
| | | |
| | | const NAV_ITEMS = [ |
| | | { href: '/', label: 'AIGC-Claw', icon: Home }, |
| | |
| | | ]; |
| | | |
| | | const SETTINGS_ITEM = { href: '/settings', label: '设置', icon: Settings }; |
| | | |
| | | const PIPELINE_ROUTES: Record<string, { href: string; label: string }> = { |
| | | standard: { href: '/pipelines/standard', label: '文艺短视频' }, |
| | | action_transfer: { href: '/pipelines/action-transfer', label: '动作迁移' }, |
| | | digital_human: { href: '/pipelines/digital-human', label: '数字人口播' }, |
| | | }; |
| | | |
| | | const TASK_STATUS_STYLE: Record<string, string> = { |
| | | pending: 'bg-gray-100 text-gray-500', |
| | | running: 'bg-blue-50 text-blue-600', |
| | | completed: 'bg-green-50 text-green-600', |
| | | failed: 'bg-red-50 text-red-600', |
| | | }; |
| | | |
| | | function statusText(status?: string) { |
| | | if (status === 'pending') return '等待中'; |
| | | if (status === 'running') return '生成中'; |
| | | if (status === 'completed') return '已完成'; |
| | | if (status === 'failed') return '失败'; |
| | | return status || '未知'; |
| | | } |
| | | |
| | | function taskTitle(task: PipelineTask) { |
| | | const input = task.input || {}; |
| | | return input.title || input.goods_title || input.text || input.prompt_text || input.goods_text || task.task_id; |
| | | } |
| | | |
| | | type RunningTaskItem = { |
| | | id: string; |
| | | href: string; |
| | | title: string; |
| | | scope: string; |
| | | status: string; |
| | | progress: number; |
| | | }; |
| | | |
| | | const WORKFLOW_STAGE_COUNT = 7; |
| | | |
| | | function projectTaskFromSession(session: any): RunningTaskItem | null { |
| | | const statusMap = session.status || {}; |
| | | const values = Object.values(statusMap); |
| | | if (!values.includes('running')) return null; |
| | | const completed = values.filter(value => ['completed', 'session_completed'].includes(String(value))).length; |
| | | const runningStage = Object.keys(statusMap).find(key => statusMap[key] === 'running'); |
| | | return { |
| | | id: `project-${session.id}`, |
| | | href: `/?session=${encodeURIComponent(session.id)}`, |
| | | title: session.idea || session.id, |
| | | scope: runningStage ? `主流程 · ${runningStage}` : '主流程', |
| | | status: 'running', |
| | | progress: Math.round((completed / WORKFLOW_STAGE_COUNT) * 100), |
| | | }; |
| | | } |
| | | |
| | | function pipelineTaskItem(task: PipelineTask): RunningTaskItem | null { |
| | | const route = PIPELINE_ROUTES[task.pipeline]; |
| | | if (!route || !['pending', 'running'].includes(task.status)) return null; |
| | | return { |
| | | id: `pipeline-${task.task_id}`, |
| | | href: `${route.href}?task=${encodeURIComponent(task.task_id)}`, |
| | | title: String(taskTitle(task)), |
| | | scope: route.label, |
| | | status: task.status, |
| | | progress: task.progress || 0, |
| | | }; |
| | | } |
| | | |
| | | const SANDBOX_TOOL_LABELS: Record<string, string> = { |
| | | llm: 'LLM', |
| | | vlm: 'VLM', |
| | | t2i: '文生图', |
| | | i2i: '图生图', |
| | | video: '视频生成', |
| | | }; |
| | | |
| | | function sandboxTaskItem(task: SandboxTask): RunningTaskItem { |
| | | const input = task.input || {}; |
| | | return { |
| | | id: `sandbox-${task.id}`, |
| | | href: `/sandbox?task=${encodeURIComponent(task.id)}`, |
| | | title: input.prompt || input.reference_image || task.id, |
| | | scope: `临时工作台 · ${SANDBOX_TOOL_LABELS[task.tool] || task.tool}`, |
| | | status: task.status || 'running', |
| | | progress: task.progress || 1, |
| | | }; |
| | | } |
| | | |
| | | function RunningTaskList({ currentPath }: { currentPath: string }) { |
| | | const router = useRouter(); |
| | | const [tasks, setTasks] = useState<RunningTaskItem[]>([]); |
| | | const [loading, setLoading] = useState(false); |
| | | |
| | | const load = async () => { |
| | | setLoading(true); |
| | | try { |
| | | const [pipelineRecords, sessions, sandboxRecords] = await Promise.all([ |
| | | fetchPipelineTasks(100).catch(() => []), |
| | | fetchSessions().catch(() => []), |
| | | fetchSandboxTasks().catch(() => []), |
| | | ]); |
| | | setTasks([ |
| | | ...sandboxRecords.map(sandboxTaskItem), |
| | | ...pipelineRecords.map(pipelineTaskItem).filter((task): task is RunningTaskItem => Boolean(task)), |
| | | ...sessions.map(projectTaskFromSession).filter((task): task is RunningTaskItem => Boolean(task)), |
| | | ]); |
| | | } finally { |
| | | setLoading(false); |
| | | } |
| | | }; |
| | | |
| | | useEffect(() => { |
| | | load().catch(() => {}); |
| | | const timer = window.setInterval(() => load().catch(() => {}), 3000); |
| | | return () => window.clearInterval(timer); |
| | | }, []); |
| | | |
| | | return ( |
| | | <section className="h-[30vh] min-h-44 border-t border-gray-100 p-3"> |
| | | <div className="mb-2 flex items-center gap-2 px-1"> |
| | | <Clock className="h-3.5 w-3.5 text-gray-400" /> |
| | | <span className="text-xs font-medium text-gray-500">进行中任务</span> |
| | | {loading && <Loader2 className="ml-auto h-3 w-3 animate-spin text-gray-300" />} |
| | | </div> |
| | | <div className="h-[calc(100%-26px)] overflow-y-auto pr-1"> |
| | | {tasks.length ? ( |
| | | <div className="space-y-1.5"> |
| | | {tasks.map(task => { |
| | | const active = currentPath === task.href.split('?')[0]; |
| | | return ( |
| | | <button |
| | | key={task.id} |
| | | type="button" |
| | | onClick={() => router.push(task.href)} |
| | | className={clsx( |
| | | 'w-full rounded-lg border px-2.5 py-2 text-left transition-colors', |
| | | active ? 'border-blue-100 bg-blue-50/60' : 'border-gray-100 bg-white hover:border-blue-200 hover:bg-blue-50/40' |
| | | )} |
| | | > |
| | | <div className="flex items-center gap-2"> |
| | | <span className="min-w-0 flex-1 truncate text-xs font-medium text-gray-700"> |
| | | {task.title.slice(0, 36)} |
| | | </span> |
| | | <span className={clsx('flex-shrink-0 rounded px-1.5 py-0.5 text-[10px]', TASK_STATUS_STYLE[task.status] || TASK_STATUS_STYLE.pending)}> |
| | | {statusText(task.status)} |
| | | </span> |
| | | </div> |
| | | <div className="mt-1 flex items-center gap-2"> |
| | | <span className="truncate text-[10px] text-gray-400">{task.scope}</span> |
| | | <div className="h-1 min-w-10 flex-1 overflow-hidden rounded-full bg-gray-100"> |
| | | <div className="h-full rounded-full bg-blue-500" style={{ width: `${task.progress || 0}%` }} /> |
| | | </div> |
| | | </div> |
| | | </button> |
| | | ); |
| | | })} |
| | | </div> |
| | | ) : ( |
| | | <div className="flex h-full items-center justify-center rounded-lg border border-dashed border-gray-100 text-xs text-gray-300"> |
| | | 暂无进行中任务 |
| | | </div> |
| | | )} |
| | | </div> |
| | | </section> |
| | | ); |
| | | } |
| | | |
| | | export default function AppShell({ children }: { children: React.ReactNode }) { |
| | | const pathname = usePathname(); |
| | |
| | | open ? 'w-60' : 'w-0 border-r-0' |
| | | )} |
| | | > |
| | | <div className={clsx('h-full overflow-hidden transition-opacity duration-200', open ? 'opacity-100' : 'opacity-0')}> |
| | | <div className={clsx('flex h-full flex-col overflow-hidden transition-opacity duration-200', open ? 'opacity-100' : 'opacity-0')}> |
| | | <div className="flex h-16 items-center px-4 border-b border-gray-100"> |
| | | <div className="flex items-center gap-2 min-w-0"> |
| | | <PanelLeftOpen className="w-4 h-4 text-blue-500 flex-shrink-0" /> |
| | | <span className="text-sm font-semibold text-gray-800 truncate">AIGC-Claw</span> |
| | | </div> |
| | | </div> |
| | | <nav className="p-3 pb-20 space-y-1"> |
| | | <nav className="min-h-0 flex-1 overflow-y-auto p-3 space-y-1"> |
| | | {NAV_ITEMS.map(item => { |
| | | const Icon = item.icon; |
| | | const active = item.href === '/' ? pathname === '/' : pathname.startsWith(item.href); |
| | |
| | | ); |
| | | })} |
| | | </nav> |
| | | <div className="absolute bottom-0 left-0 right-0 border-t border-gray-100 p-3"> |
| | | <RunningTaskList currentPath={pathname} /> |
| | | <div className="border-t border-gray-100 p-3"> |
| | | {(() => { |
| | | const Icon = SETTINGS_ITEM.icon; |
| | | const active = pathname.startsWith(SETTINGS_ITEM.href); |
| | |
| | | import { useSearchParams } from 'next/navigation'; |
| | | import { LLM_MODELS, T2I_MODELS, I2I_MODELS, VIDEO_MODELS, VLM_MODELS } from '@/config/models'; |
| | | import BrandHeader from '@/components/BrandHeader'; |
| | | import { uploadMedia } from '@/lib/workflowApi'; |
| | | import { fetchSandboxTasks, uploadMedia } from '@/lib/workflowApi'; |
| | | |
| | | // 辅助函数:将相对路径转换为完整 URL |
| | | const toMediaUrl = (path: string) => { |
| | |
| | | fetchHistory(); |
| | | }, []); |
| | | |
| | | const applyRecord = (record: HistoryRecord) => { |
| | | setSelectedRecord(record); |
| | | setActiveTool(record.tool as ToolType); |
| | | setSelectedModel(record.model); |
| | | setPrompt(record.input.prompt || ''); |
| | | setImageUrl(record.input.reference_image || record.input.images?.[0] || ''); |
| | | if (record.output?.response) { |
| | | setResult(record.output.response); |
| | | } else { |
| | | setResult(null); |
| | | } |
| | | setCurrentOutput(record.output || null); |
| | | setLoading(false); |
| | | setError(null); |
| | | }; |
| | | |
| | | // 检查 URL 参数,自动加载历史记录 |
| | | useEffect(() => { |
| | | const recordId = searchParams.get('record'); |
| | | if (recordId && history.length > 0) { |
| | | const record = history.find(r => r.id === recordId); |
| | | if (record) { |
| | | setSelectedRecord(record); |
| | | // 填充输入框 |
| | | setActiveTool(record.tool as ToolType); |
| | | setPrompt(record.input.prompt || ''); |
| | | setImageUrl(record.input.reference_image || record.input.images?.[0] || ''); |
| | | // 显示结果 |
| | | if (record.output?.response) { |
| | | setResult(record.output.response); |
| | | } else if (record.output?.images?.length) { |
| | | setResult(null); |
| | | } else if (record.output?.video_path) { |
| | | setResult(null); |
| | | } |
| | | setCurrentOutput(record.output || null); |
| | | applyRecord(record); |
| | | } |
| | | } |
| | | }, [searchParams, history]); |
| | | |
| | | useEffect(() => { |
| | | const taskId = searchParams.get('task'); |
| | | if (!taskId) return; |
| | | let cancelled = false; |
| | | |
| | | const loadTask = async () => { |
| | | const historyRecord = history.find(r => r.id === taskId); |
| | | if (historyRecord) { |
| | | applyRecord(historyRecord); |
| | | return; |
| | | } |
| | | |
| | | const activeTasks = await fetchSandboxTasks(); |
| | | const activeTask = activeTasks.find(item => item.id === taskId); |
| | | if (!activeTask || cancelled) return; |
| | | setActiveTool(activeTask.tool as ToolType); |
| | | setSelectedModel(activeTask.model); |
| | | setPrompt(activeTask.input?.prompt || ''); |
| | | setImageUrl(activeTask.input?.reference_image || activeTask.input?.images?.[0] || ''); |
| | | setCurrentOutput(null); |
| | | setResult(null); |
| | | setError(null); |
| | | setLoading(true); |
| | | }; |
| | | |
| | | loadTask().catch(() => {}); |
| | | const timer = window.setInterval(() => { |
| | | fetchHistory().then(() => loadTask()).catch(() => {}); |
| | | }, 3000); |
| | | return () => { |
| | | cancelled = true; |
| | | window.clearInterval(timer); |
| | | }; |
| | | }, [searchParams, history]); |
| | | |
| | | // 删除历史记录 |
| | | const deleteRecord = async (id: string) => { |
| | | setDeleting(id); |
| | |
| | | 'use client'; |
| | | |
| | | import { useEffect, useMemo, useState } from 'react'; |
| | | import { useSearchParams } from 'next/navigation'; |
| | | import { |
| | | ArrowRight, |
| | | CheckCircle, |
| | |
| | | } |
| | | |
| | | export default function PipelinePage({ pipeline, title, subtitle }: PipelinePageProps) { |
| | | const searchParams = useSearchParams(); |
| | | const TitleIcon = PIPELINE_TITLE_ICONS[pipeline]; |
| | | const [showSettings, setShowSettings] = useState(false); |
| | | const [running, setRunning] = useState(false); |
| | |
| | | ); |
| | | }, [task?.task_id, task?.status]); |
| | | |
| | | useEffect(() => { |
| | | const taskId = searchParams.get('task'); |
| | | if (!taskId || task?.task_id === taskId) return; |
| | | fetchPipelineTask(taskId) |
| | | .then(fresh => { |
| | | if (fresh.pipeline === pipeline) { |
| | | setTask(fresh); |
| | | setRunning(['pending', 'running'].includes(fresh.status)); |
| | | } |
| | | }) |
| | | .catch(() => {}); |
| | | }, [pipeline, searchParams, task?.task_id]); |
| | | |
| | | const submit = async () => { |
| | | if (!canSubmit || running) return; |
| | | setRunning(true); |
| | |
| | | output_dir?: string; |
| | | } |
| | | |
| | | export interface SandboxTask { |
| | | id: string; |
| | | tool: string; |
| | | model: string; |
| | | input?: Record<string, any>; |
| | | status: string; |
| | | progress?: number; |
| | | created_at?: string; |
| | | } |
| | | |
| | | export interface PipelineStartResponse { |
| | | task_id: string; |
| | | pipeline: string; |
| | |
| | | return resp.json(); |
| | | } |
| | | |
| | | export async function fetchSandboxTasks(): Promise<SandboxTask[]> { |
| | | const resp = await fetch('/api/sandbox/tasks'); |
| | | if (!resp.ok) return []; |
| | | const data = await resp.json(); |
| | | return data.tasks || []; |
| | | } |
| | | |
| | | export async function deletePipelineTask(taskId: string): Promise<void> { |
| | | const resp = await fetch(`/api/tasks/${taskId}`, { method: 'DELETE' }); |
| | | if (!resp.ok) throw new Error('删除任务失败'); |