From ff1ede47a0eb86b22c02f810043f34d38e7002fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E5=A4=95?= Date: Tue, 12 May 2026 15:47:17 +0800 Subject: [PATCH] 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> --- .python-version | 1 - frontend/src/components/Chat/LeftPanel.tsx | 24 ++- .../src/components/Chat/NewWorkflowDialog.tsx | 104 +++++++++ .../src/components/Chat/WorkflowListView.tsx | 29 ++- kilostar/api/__init__.py | 2 + kilostar/api/chat.py | 109 ++++++++++ kilostar/api/platform/event.py | 4 +- kilostar/api/workflow.py | 129 ++++++------ .../global_state_machine.py | 4 +- .../global_workflow_manager.py | 6 +- .../consciousness_node/consciousness_node.py | 112 +++++----- .../individual/consciousness_node/template.py | 8 +- .../core/individual/control_node/template.py | 7 +- .../regulatory_node/regulatory_node.py | 4 +- .../core/postgres_database/model/__init__.py | 18 +- kilostar/core/postgres_database/model/base.py | 3 +- .../postgres_database/model/chat_history.py | 56 ++++- .../postgres_database/model/individual.py | 28 +-- .../core/postgres_database/model/provider.py | 7 +- .../postgres_database/model/system_node.py | 13 +- kilostar/core/postgres_database/model/user.py | 6 +- .../core/postgres_database/model/workflow.py | 70 ++++++- .../postgres_database/module/chat_history.py | 82 ++++++++ .../core/postgres_database/module/workflow.py | 96 +++++++++ kilostar/core/postgres_database/postgres.py | 52 +++++ kilostar/core/work/workflow/model.py | 11 +- kilostar/core/work/workflow/workflow.py | 40 +++- .../core/work/workflow/workflow_engine.py | 177 ++++++++++++++++ pyproject.toml | 2 +- .../global_state_machine_test.py | 2 + tests/core/postgres_database/postgres_test.py | 2 + .../workflow_runner_test.py | 197 ------------------ tests/utils/access_test.py | 2 + 33 files changed, 995 insertions(+), 412 deletions(-) delete mode 100644 .python-version create mode 100644 frontend/src/components/Chat/NewWorkflowDialog.tsx create mode 100644 kilostar/api/chat.py create mode 100644 kilostar/core/postgres_database/module/chat_history.py create mode 100644 kilostar/core/postgres_database/module/workflow.py create mode 100644 kilostar/core/work/workflow/workflow_engine.py delete mode 100644 tests/core/workflow_running_engine/workflow_runner_test.py diff --git a/.python-version b/.python-version deleted file mode 100644 index 24ee5b1..0000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.13 diff --git a/frontend/src/components/Chat/LeftPanel.tsx b/frontend/src/components/Chat/LeftPanel.tsx index 30be8ac..d5e91a9 100644 --- a/frontend/src/components/Chat/LeftPanel.tsx +++ b/frontend/src/components/Chat/LeftPanel.tsx @@ -98,15 +98,19 @@ export function LeftPanel({ {activeTab === 'chats' ? 'Chat History' : 'Workflows'} - {activeTab === 'chats' && ( - - )} +
@@ -115,7 +119,7 @@ export function LeftPanel({ {loadingWorkflows ? (
Loading workflows...
) : workflows.length === 0 ? ( -
暂无工作流
+
暂无工作流
点击右上角 + 创建
) : ( workflows.map((wf) => (
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 ( +
+
+
+
+ +

新建工作流任务

+
+ +
+ +
+ {error && ( +
+ {error} +
+ )} + +
+ + 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 + /> +
+ +
+ +