From fc95cc6595bd27ef097bac414fcd5625bcb48ac0 Mon Sep 17 00:00:00 2001 From: 666ghj <670939375@qq.com> Date: Thu, 11 Dec 2025 15:09:24 +0800 Subject: [PATCH] Add simulation API and environment setup components - Introduced simulation.js API for creating and managing simulations, including methods for creating, preparing, and retrieving simulation statuses. - Added Step1GraphBuild.vue and Step2EnvSetup.vue components to facilitate the graph building and environment setup processes, enhancing user interaction and workflow. - Updated MainView.vue to integrate new components and manage the simulation workflow, including step indicators and navigation between steps. - Created SimulationView.vue for displaying simulation details and managing the simulation environment, improving overall user experience and functionality. --- frontend/src/api/simulation.js | 100 ++ ...WorkbenchPanel.vue => Step1GraphBuild.vue} | 47 +- frontend/src/components/Step2EnvSetup.vue | 1042 +++++++++++++++++ frontend/src/router/index.js | 7 + frontend/src/views/MainView.vue | 39 +- frontend/src/views/SimulationView.vue | 338 ++++++ 6 files changed, 1564 insertions(+), 9 deletions(-) create mode 100644 frontend/src/api/simulation.js rename frontend/src/components/{WorkbenchPanel.vue => Step1GraphBuild.vue} (91%) create mode 100644 frontend/src/components/Step2EnvSetup.vue create mode 100644 frontend/src/views/SimulationView.vue diff --git a/frontend/src/api/simulation.js b/frontend/src/api/simulation.js new file mode 100644 index 0000000..2b32fa8 --- /dev/null +++ b/frontend/src/api/simulation.js @@ -0,0 +1,100 @@ +import service, { requestWithRetry } from './index' + +/** + * 创建模拟 + * @param {Object} data - { project_id, graph_id?, enable_twitter?, enable_reddit? } + */ +export const createSimulation = (data) => { + return requestWithRetry(() => service.post('/api/simulation/create', data), 3, 1000) +} + +/** + * 准备模拟环境(异步任务) + * @param {Object} data - { simulation_id, entity_types?, use_llm_for_profiles?, parallel_profile_count?, force_regenerate? } + */ +export const prepareSimulation = (data) => { + return requestWithRetry(() => service.post('/api/simulation/prepare', data), 3, 1000) +} + +/** + * 查询准备任务进度 + * @param {Object} data - { task_id?, simulation_id? } + */ +export const getPrepareStatus = (data) => { + return service.post('/api/simulation/prepare/status', data) +} + +/** + * 获取模拟状态 + * @param {string} simulationId + */ +export const getSimulation = (simulationId) => { + return service.get(`/api/simulation/${simulationId}`) +} + +/** + * 获取模拟的 Agent Profiles + * @param {string} simulationId + * @param {string} platform - 'reddit' | 'twitter' + */ +export const getSimulationProfiles = (simulationId, platform = 'reddit') => { + return service.get(`/api/simulation/${simulationId}/profiles`, { params: { platform } }) +} + +/** + * 实时获取生成中的 Agent Profiles + * @param {string} simulationId + * @param {string} platform - 'reddit' | 'twitter' + */ +export const getSimulationProfilesRealtime = (simulationId, platform = 'reddit') => { + return service.get(`/api/simulation/${simulationId}/profiles/realtime`, { params: { platform } }) +} + +/** + * 获取模拟配置 + * @param {string} simulationId + */ +export const getSimulationConfig = (simulationId) => { + return service.get(`/api/simulation/${simulationId}/config`) +} + +/** + * 列出所有模拟 + * @param {string} projectId - 可选,按项目ID过滤 + */ +export const listSimulations = (projectId) => { + const params = projectId ? { project_id: projectId } : {} + return service.get('/api/simulation/list', { params }) +} + +/** + * 启动模拟 + * @param {Object} data - { simulation_id, platform?, max_rounds?, enable_graph_memory_update? } + */ +export const startSimulation = (data) => { + return requestWithRetry(() => service.post('/api/simulation/start', data), 3, 1000) +} + +/** + * 停止模拟 + * @param {Object} data - { simulation_id } + */ +export const stopSimulation = (data) => { + return service.post('/api/simulation/stop', data) +} + +/** + * 获取模拟运行实时状态 + * @param {string} simulationId + */ +export const getRunStatus = (simulationId) => { + return service.get(`/api/simulation/${simulationId}/run-status`) +} + +/** + * 获取模拟运行详细状态(包含最近动作) + * @param {string} simulationId + */ +export const getRunStatusDetail = (simulationId) => { + return service.get(`/api/simulation/${simulationId}/run-status/detail`) +} diff --git a/frontend/src/components/WorkbenchPanel.vue b/frontend/src/components/Step1GraphBuild.vue similarity index 91% rename from frontend/src/components/WorkbenchPanel.vue rename to frontend/src/components/Step1GraphBuild.vue index a316140..9629410 100644 --- a/frontend/src/components/WorkbenchPanel.vue +++ b/frontend/src/components/Step1GraphBuild.vue @@ -159,10 +159,11 @@

图谱构建已完成,请进入下一步进行模拟环境搭建

@@ -186,6 +187,10 @@ + + diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index 4bae635..f8a7a02 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -1,6 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import Home from '../views/Home.vue' import Process from '../views/MainView.vue' +import SimulationView from '../views/SimulationView.vue' const routes = [ { @@ -13,6 +14,12 @@ const routes = [ name: 'Process', component: Process, props: true + }, + { + path: '/simulation/:simulationId', + name: 'Simulation', + component: SimulationView, + props: true } ] diff --git a/frontend/src/views/MainView.vue b/frontend/src/views/MainView.vue index 7aef973..333efe9 100644 --- a/frontend/src/views/MainView.vue +++ b/frontend/src/views/MainView.vue @@ -22,8 +22,8 @@
- Step 1/5 - 图谱构建 + Step {{ currentStep }}/5 + {{ stepNames[currentStep - 1] }}
@@ -46,9 +46,11 @@ />
- +
- + + +
@@ -66,7 +78,8 @@ import { ref, computed, onMounted, onUnmounted, nextTick } from 'vue' import { useRoute, useRouter } from 'vue-router' import GraphPanel from '../components/GraphPanel.vue' -import WorkbenchPanel from '../components/WorkbenchPanel.vue' +import Step1GraphBuild from '../components/Step1GraphBuild.vue' +import Step2EnvSetup from '../components/Step2EnvSetup.vue' import { generateOntology, getProject, buildGraph, getTaskStatus, getGraphData } from '../api/graph' import { getPendingUpload, clearPendingUpload } from '../store/pendingUpload' @@ -76,6 +89,10 @@ const router = useRouter() // Layout State const viewMode = ref('split') // graph | split | workbench +// Step State +const currentStep = ref(1) // 1: 图谱构建, 2: 环境搭建, 3: 开始模拟, 4: 报告生成, 5: 深度互动 +const stepNames = ['图谱构建', '环境搭建', '开始模拟', '报告生成', '深度互动'] + // Data State const currentProjectId = ref(route.params.projectId) const loading = ref(false) @@ -140,7 +157,17 @@ const toggleMaximize = (target) => { } const handleNextStep = () => { - alert('Environment Setup coming soon...') + if (currentStep.value < 5) { + currentStep.value++ + addLog(`进入 Step ${currentStep.value}: ${stepNames[currentStep.value - 1]}`) + } +} + +const handleGoBack = () => { + if (currentStep.value > 1) { + currentStep.value-- + addLog(`返回 Step ${currentStep.value}: ${stepNames[currentStep.value - 1]}`) + } } // --- Data Logic --- diff --git a/frontend/src/views/SimulationView.vue b/frontend/src/views/SimulationView.vue new file mode 100644 index 0000000..9c3e2bf --- /dev/null +++ b/frontend/src/views/SimulationView.vue @@ -0,0 +1,338 @@ + + + + +