Refactor Workflow and Chat Architecture (#68)

* refactor: overhaul workflow and chat architecture

- Separate Chat and Workflow API endpoints and database models
- Use JSONB to store workflow execution context in Postgres
- Convert workflow engine to use pydantic-ai execution graphs inside a Ray task
- Update frontend React components to support standalone workflow creation
- Remove obsolete and broken workflow runner tests

Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com>

* refactor: overhaul workflow and chat architecture

- Separate Chat and Workflow API endpoints and database models
- Use JSONB to store workflow execution context in Postgres
- Convert workflow engine to use pydantic-ai execution graphs inside a Ray task
- Update frontend React components to support standalone workflow creation
- Remove obsolete and broken workflow runner tests

Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com>

* refactor: overhaul workflow and chat architecture

- Separate Chat and Workflow API endpoints and database models
- Use JSONB to store workflow execution context in Postgres
- Convert workflow engine to use pydantic-ai execution graphs inside a Ray task
- Update frontend React components to support standalone workflow creation
- Move workflow_engine inside workflow package to keep core root clean
- Remove obsolete and broken workflow runner tests

Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com>
This commit is contained in:
2026-05-12 15:47:17 +08:00
committed by GitHub
parent ee9bbbf676
commit ff1ede47a0
33 changed files with 995 additions and 412 deletions
+14 -10
View File
@@ -98,15 +98,19 @@ export function LeftPanel({
<span className="text-sm font-semibold text-slate-600 uppercase tracking-wider">
{activeTab === 'chats' ? 'Chat History' : 'Workflows'}
</span>
{activeTab === 'chats' && (
<button
onClick={handleNewChat}
className="p-1.5 bg-blue-100 text-blue-600 rounded hover:bg-blue-200 transition-colors"
title="New Chat"
>
<Plus size={16} />
</button>
)}
<button
onClick={() => {
if (activeTab === 'chats') {
handleNewChat();
} else {
setSelectedWorkflow('new'); // 设置为一个特殊值,表示进入新建工作流向导
}
}}
className="p-1.5 bg-blue-100 text-blue-600 rounded hover:bg-blue-200 transition-colors"
title={activeTab === 'chats' ? 'New Chat' : 'New Workflow'}
>
<Plus size={16} />
</button>
</div>
<div className="flex-1 p-3 overflow-y-auto">
@@ -115,7 +119,7 @@ export function LeftPanel({
{loadingWorkflows ? (
<div className="text-center text-slate-400 text-sm py-4">Loading workflows...</div>
) : workflows.length === 0 ? (
<div className="text-center text-slate-400 text-sm py-4"></div>
<div className="text-center text-slate-400 text-sm py-4"><br/> + </div>
) : (
workflows.map((wf) => (
<div
@@ -0,0 +1,104 @@
import { useState } from 'react';
import { Terminal, X, ArrowRight } from 'lucide-react';
import apiClient from '../../api/client';
interface NewWorkflowDialogProps {
onClose: () => void;
onSuccess: (traceId: string) => void;
}
export function NewWorkflowDialog({ onClose, onSuccess }: NewWorkflowDialogProps) {
const [command, setCommand] = useState('');
const [title, setTitle] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!command.trim() || !title.trim()) {
setError('标题和需求描述不能为空');
return;
}
setLoading(true);
setError('');
try {
const response = await apiClient.post('/api/v1/workflow', {
title: title,
command: command
});
if (response.data && response.data.trace_id) {
onSuccess(response.data.trace_id);
}
} catch (err: any) {
setError(err.response?.data?.message || '创建工作流失败,请重试');
} finally {
setLoading(false);
}
};
return (
<div className="absolute inset-0 bg-white/80 backdrop-blur-sm z-50 flex items-center justify-center p-4">
<div className="bg-white rounded-2xl shadow-xl border border-slate-200 w-full max-w-md overflow-hidden">
<div className="flex items-center justify-between px-6 py-4 border-b border-slate-100 bg-slate-50">
<div className="flex items-center gap-2">
<Terminal size={20} className="text-blue-600" />
<h2 className="font-semibold text-slate-800"></h2>
</div>
<button onClick={onClose} className="p-1 text-slate-400 hover:bg-slate-200 rounded-lg transition-colors">
<X size={18} />
</button>
</div>
<form onSubmit={handleSubmit} className="p-6 space-y-4">
{error && (
<div className="p-3 text-sm text-red-600 bg-red-50 border border-red-100 rounded-lg">
{error}
</div>
)}
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="例如:爬取最新的技术新闻"
className="w-full px-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500"
autoFocus
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<textarea
value={command}
onChange={(e) => setCommand(e.target.value)}
placeholder="详细描述您希望工作流完成的任务..."
className="w-full px-3 py-2 border border-slate-200 rounded-lg h-32 resize-none focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500"
/>
</div>
<div className="pt-2 flex justify-end gap-2">
<button
type="button"
onClick={onClose}
className="px-4 py-2 text-sm font-medium text-slate-600 bg-slate-100 hover:bg-slate-200 rounded-lg transition-colors"
>
</button>
<button
type="submit"
disabled={loading}
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg transition-colors disabled:opacity-50"
>
{loading ? '创建中...' : '开始创建'}
{!loading && <ArrowRight size={16} />}
</button>
</div>
</form>
</div>
</div>
);
}
@@ -68,9 +68,17 @@ export function WorkflowListView({ onSelectWorkflow }: WorkflowListViewProps) {
return (
<div className="flex-1 flex flex-col p-8 bg-slate-50 overflow-auto">
<div className="mb-8">
<h1 className="text-2xl font-bold text-slate-800">Workflows</h1>
<p className="text-slate-500 mt-1">Manage and monitor your automated processes.</p>
<div className="mb-8 flex justify-between items-center">
<div>
<h1 className="text-2xl font-bold text-slate-800">Workflows</h1>
<p className="text-slate-500 mt-1">Manage and monitor your automated processes.</p>
</div>
<button
onClick={() => onSelectWorkflow('new')}
className="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-colors shadow-sm"
>
<span className="text-xl leading-none">+</span>
</button>
</div>
{workflows.length === 0 ? (
@@ -103,7 +111,13 @@ export function WorkflowListView({ onSelectWorkflow }: WorkflowListViewProps) {
</h3>
<div className="mt-auto">
{wf.message && (
{(wf as any).command && (
<div className="text-sm text-slate-500 line-clamp-2 mt-4 bg-slate-50 p-3 rounded-lg border border-slate-100">
<span className="font-medium text-slate-600 block mb-1">Command:</span>
"{(wf as any).command}"
</div>
)}
{wf.message && !(wf as any).command && (
<div className="text-sm text-slate-500 line-clamp-2 mt-4 bg-slate-50 p-3 rounded-lg border border-slate-100">
<span className="font-medium text-slate-600 block mb-1">Command:</span>
"{wf.message}"
@@ -111,12 +125,15 @@ export function WorkflowListView({ onSelectWorkflow }: WorkflowListViewProps) {
)}
<div className="flex justify-between items-center mt-5 text-xs text-slate-400">
<span className="font-mono bg-slate-100 px-2 py-1 rounded truncate max-w-[140px]" title={wf.event_id}>
{wf.event_id}
<span className="font-mono bg-slate-100 px-2 py-1 rounded truncate max-w-[140px]" title={wf.event_id || (wf as any).trace_id}>
{wf.event_id || (wf as any).trace_id}
</span>
{wf.create_time && (
<span>{new Date(wf.create_time).toLocaleDateString()}</span>
)}
{(wf as any).created_at && !wf.create_time && (
<span>{new Date((wf as any).created_at).toLocaleDateString()}</span>
)}
</div>
</div>
</div>