Skip to content

A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物

Add simulation API and environment setup components

666ghjfc95cc6595bd
diff --git a/frontend/src/api/simulation.js b/frontend/src/api/simulation.js
new file mode 100644
index 00000000..2b32fa84
--- /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 a316140f..96294106 100644
--- a/frontend/src/components/WorkbenchPanel.vue
+++ b/frontend/src/components/Step1GraphBuild.vue
@@ -159,10 +159,11 @@
<p class="description">图谱构建已完成,请进入下一步进行模拟环境搭建</p>
<button
class="action-btn"
- :disabled="currentPhase < 2"
- @click="$emit('next-step')"
+ :disabled="currentPhase < 2 || creatingSimulation"
+ @click="handleEnterEnvSetup"
>
- 进入环境搭建 ➝
+ <span v-if="creatingSimulation" class="spinner-sm"></span>
+ {{ creatingSimulation ? '创建中...' : '进入环境搭建 ➝' }}
</button>
</div>
</div>
@@ -186,6 +187,10 @@
<script setup>
import { computed, ref, watch, nextTick } from 'vue'
+import { useRouter } from 'vue-router'
+import { createSimulation } from '../api/simulation'
+
+const router = useRouter()
const props = defineProps({
currentPhase: { type: Number, default: 0 },
@@ -200,6 +205,42 @@ defineEmits(['next-step'])
const selectedOntologyItem = ref(null)
const logContent = ref(null)
+const creatingSimulation = ref(false)
+
+// 进入环境搭建 - 创建 simulation 并跳转
+const handleEnterEnvSetup = async () => {
+ if (!props.projectData?.project_id || !props.projectData?.graph_id) {
+ console.error('缺少项目或图谱信息')
+ return
+ }
+
+ creatingSimulation.value = true
+
+ try {
+ const res = await createSimulation({
+ project_id: props.projectData.project_id,
+ graph_id: props.projectData.graph_id,
+ enable_twitter: true,
+ enable_reddit: true
+ })
+
+ if (res.success && res.data?.simulation_id) {
+ // 跳转到 simulation 页面
+ router.push({
+ name: 'Simulation',
+ params: { simulationId: res.data.simulation_id }
+ })
+ } else {
+ console.error('创建模拟失败:', res.error)
+ alert('创建模拟失败: ' + (res.error || '未知错误'))
+ }
+ } catch (err) {
+ console.error('创建模拟异常:', err)
+ alert('创建模拟异常: ' + err.message)
+ } finally {
+ creatingSimulation.value = false
+ }
+}
const selectOntologyItem = (item, type) => {
selectedOntologyItem.value = { ...item, itemType: type }
diff --git a/frontend/src/components/Step2EnvSetup.vue b/frontend/src/components/Step2EnvSetup.vue
new file mode 100644
index 00000000..affa54ad
--- /dev/null
+++ b/frontend/src/components/Step2EnvSetup.vue
@@ -0,0 +1,1042 @@
+<template>
+ <div class="env-setup-panel">
+ <div class="scroll-container">
+ <!-- Step 01: 模拟实例 -->
+ <div class="step-card" :class="{ 'active': phase === 0, 'completed': phase > 0 }">
+ <div class="card-header">
+ <div class="step-info">
+ <span class="step-num">01</span>
+ <span class="step-title">模拟实例</span>
+ </div>
+ <div class="step-status">
+ <span v-if="phase > 0" class="badge success">已完成</span>
+ <span v-else class="badge processing">初始化</span>
+ </div>
+ </div>
+
+ <div class="card-content">
+ <p class="api-note">POST /api/simulation/create</p>
+ <p class="description">
+ 基于已构建的知识图谱创建模拟实例,初始化模拟环境
+ </p>
+
+ <div v-if="simulationId" class="info-card">
+ <div class="info-row">
+ <span class="info-label">Simulation ID</span>
+ <span class="info-value mono">{{ simulationId }}</span>
+ </div>
+ <div class="info-row">
+ <span class="info-label">Graph ID</span>
+ <span class="info-value mono">{{ projectData?.graph_id }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Step 02: 生成 Agent 人设 -->
+ <div class="step-card" :class="{ 'active': phase === 1, 'completed': phase > 1 }">
+ <div class="card-header">
+ <div class="step-info">
+ <span class="step-num">02</span>
+ <span class="step-title">生成 Agent 人设</span>
+ </div>
+ <div class="step-status">
+ <span v-if="phase > 1" class="badge success">已完成</span>
+ <span v-else-if="phase === 1" class="badge processing">{{ prepareProgress }}%</span>
+ <span v-else class="badge pending">等待</span>
+ </div>
+ </div>
+
+ <div class="card-content">
+ <p class="api-note">POST /api/simulation/prepare</p>
+ <p class="description">
+ 从知识图谱读取实体,使用 LLM 为每个实体生成详细的 Agent 人设与行为配置
+ </p>
+
+ <!-- Progress Bar -->
+ <div v-if="phase >= 1" class="progress-section">
+ <div class="progress-bar">
+ <div class="progress-fill" :style="{ width: prepareProgress + '%' }"></div>
+ </div>
+ <div class="progress-info">
+ <span class="progress-stage">{{ currentStage }}</span>
+ <span class="progress-detail">{{ progressMessage }}</span>
+ </div>
+ </div>
+
+ <!-- Profiles Stats -->
+ <div v-if="profiles.length > 0" class="stats-grid">
+ <div class="stat-card">
+ <span class="stat-value">{{ profiles.length }}</span>
+ <span class="stat-label">Agent 人设</span>
+ </div>
+ <div class="stat-card">
+ <span class="stat-value">{{ entityTypes.length }}</span>
+ <span class="stat-label">实体类型</span>
+ </div>
+ <div class="stat-card">
+ <span class="stat-value">{{ expectedTotal || '-' }}</span>
+ <span class="stat-label">预期总数</span>
+ </div>
+ </div>
+
+ <!-- Profiles List Preview -->
+ <div v-if="profiles.length > 0" class="profiles-preview">
+ <div class="preview-header">
+ <span class="preview-title">已生成的 Agent 人设</span>
+ <button class="expand-btn" @click="showProfilesDetail = !showProfilesDetail">
+ {{ showProfilesDetail ? '收起' : '展开全部' }}
+ </button>
+ </div>
+ <div class="profiles-list" :class="{ expanded: showProfilesDetail }">
+ <div
+ v-for="(profile, idx) in displayProfiles"
+ :key="idx"
+ class="profile-card"
+ @click="selectProfile(profile)"
+ >
+ <div class="profile-header">
+ <span class="profile-name">{{ profile.user_name || profile.username || `Agent ${idx}` }}</span>
+ <span class="profile-type">{{ profile.entity_type || 'Unknown' }}</span>
+ </div>
+ <p class="profile-bio">{{ truncateBio(profile.bio || profile.description || '暂无简介') }}</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Step 03: 生成模拟配置 -->
+ <div class="step-card" :class="{ 'active': phase === 2, 'completed': phase > 2 }">
+ <div class="card-header">
+ <div class="step-info">
+ <span class="step-num">03</span>
+ <span class="step-title">生成模拟配置</span>
+ </div>
+ <div class="step-status">
+ <span v-if="phase > 2" class="badge success">已完成</span>
+ <span v-else-if="phase === 2" class="badge processing">生成中</span>
+ <span v-else class="badge pending">等待</span>
+ </div>
+ </div>
+
+ <div class="card-content">
+ <p class="api-note">LLM 智能配置</p>
+ <p class="description">
+ LLM 根据模拟需求智能生成时间配置、Agent 活跃度、发言频率、事件触发等参数
+ </p>
+
+ <!-- Config Preview -->
+ <div v-if="simulationConfig" class="config-preview">
+ <div class="config-section">
+ <span class="config-label">模拟时长</span>
+ <span class="config-value">{{ simulationConfig.time_config?.simulation_hours || '-' }} 小时</span>
+ </div>
+ <div class="config-section">
+ <span class="config-label">模拟轮次</span>
+ <span class="config-value">{{ simulationConfig.time_config?.max_rounds || '-' }} 轮</span>
+ </div>
+ <div class="config-section">
+ <span class="config-label">平台</span>
+ <span class="config-value">
+ <span v-if="simulationConfig.platform_configs?.twitter" class="platform-tag">Twitter</span>
+ <span v-if="simulationConfig.platform_configs?.reddit" class="platform-tag">Reddit</span>
+ </span>
+ </div>
+
+ <!-- LLM Reasoning -->
+ <div v-if="simulationConfig.generation_reasoning" class="reasoning-section">
+ <span class="reasoning-label">LLM 配置推理</span>
+ <p class="reasoning-text">{{ simulationConfig.generation_reasoning }}</p>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Step 04: 准备完成 -->
+ <div class="step-card" :class="{ 'active': phase === 3, 'completed': phase >= 3 }">
+ <div class="card-header">
+ <div class="step-info">
+ <span class="step-num">04</span>
+ <span class="step-title">准备完成</span>
+ </div>
+ <div class="step-status">
+ <span v-if="phase >= 3" class="badge accent">就绪</span>
+ </div>
+ </div>
+
+ <div class="card-content">
+ <p class="description">模拟环境已准备就绪,可以开始运行模拟</p>
+ <div class="action-group">
+ <button
+ class="action-btn secondary"
+ @click="$emit('go-back')"
+ >
+ ← 返回图谱
+ </button>
+ <button
+ class="action-btn primary"
+ :disabled="phase < 3"
+ @click="$emit('next-step')"
+ >
+ 开始模拟 ➝
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Profile Detail Modal -->
+ <div v-if="selectedProfile" class="profile-modal-overlay" @click.self="selectedProfile = null">
+ <div class="profile-modal">
+ <div class="modal-header">
+ <span class="modal-title">{{ selectedProfile.user_name || selectedProfile.username }}</span>
+ <button class="close-btn" @click="selectedProfile = null">×</button>
+ </div>
+ <div class="modal-body">
+ <div class="modal-section">
+ <span class="section-label">实体类型</span>
+ <span class="section-value">{{ selectedProfile.entity_type }}</span>
+ </div>
+ <div class="modal-section">
+ <span class="section-label">来源实体</span>
+ <span class="section-value">{{ selectedProfile.source_entity_name || '-' }}</span>
+ </div>
+ <div class="modal-section">
+ <span class="section-label">人设简介</span>
+ <p class="section-text">{{ selectedProfile.bio || selectedProfile.description || '暂无简介' }}</p>
+ </div>
+ <div class="modal-section" v-if="selectedProfile.personality">
+ <span class="section-label">性格特点</span>
+ <p class="section-text">{{ selectedProfile.personality }}</p>
+ </div>
+ <div class="modal-section" v-if="selectedProfile.interests?.length">
+ <span class="section-label">兴趣标签</span>
+ <div class="tags-row">
+ <span v-for="tag in selectedProfile.interests" :key="tag" class="interest-tag">{{ tag }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Bottom Info / Logs -->
+ <div class="system-logs">
+ <div class="log-header">
+ <span class="log-title">SYSTEM DASHBOARD</span>
+ <span class="log-id">{{ simulationId || 'NO_SIMULATION' }}</span>
+ </div>
+ <div class="log-content" ref="logContent">
+ <div class="log-line" v-for="(log, idx) in systemLogs" :key="idx">
+ <span class="log-time">{{ log.time }}</span>
+ <span class="log-msg">{{ log.msg }}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup>
+import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'
+import {
+ prepareSimulation,
+ getPrepareStatus,
+ getSimulationProfilesRealtime,
+ getSimulationConfig
+} from '../api/simulation'
+
+const props = defineProps({
+ simulationId: String, // 从父组件传入
+ projectData: Object,
+ graphData: Object,
+ systemLogs: Array
+})
+
+const emit = defineEmits(['go-back', 'next-step', 'add-log', 'update-status'])
+
+// State
+const phase = ref(0) // 0: 初始化, 1: 生成人设, 2: 生成配置, 3: 完成
+const taskId = ref(null)
+const prepareProgress = ref(0)
+const currentStage = ref('')
+const progressMessage = ref('')
+const profiles = ref([])
+const entityTypes = ref([])
+const expectedTotal = ref(null)
+const simulationConfig = ref(null)
+const selectedProfile = ref(null)
+const showProfilesDetail = ref(false)
+
+// Polling timer
+let pollTimer = null
+let profilesTimer = null
+
+// Computed
+const displayProfiles = computed(() => {
+ if (showProfilesDetail.value) {
+ return profiles.value
+ }
+ return profiles.value.slice(0, 6)
+})
+
+// Methods
+const addLog = (msg) => {
+ emit('add-log', msg)
+}
+
+const truncateBio = (bio) => {
+ if (bio.length > 80) {
+ return bio.substring(0, 80) + '...'
+ }
+ return bio
+}
+
+const selectProfile = (profile) => {
+ selectedProfile.value = profile
+}
+
+// 自动开始准备模拟
+const startPrepareSimulation = async () => {
+ if (!props.simulationId) {
+ addLog('错误:缺少 simulationId')
+ emit('update-status', 'error')
+ return
+ }
+
+ // 标记第一步完成,开始第二步
+ phase.value = 1
+ addLog(`模拟实例已创建: ${props.simulationId}`)
+ addLog('正在准备模拟环境...')
+ emit('update-status', 'processing')
+
+ try {
+ const res = await prepareSimulation({
+ simulation_id: props.simulationId,
+ use_llm_for_profiles: true,
+ parallel_profile_count: 5
+ })
+
+ if (res.success && res.data) {
+ if (res.data.already_prepared) {
+ addLog('检测到已有完成的准备工作,直接使用')
+ await loadPreparedData()
+ return
+ }
+
+ taskId.value = res.data.task_id
+ addLog(`准备任务已启动: ${res.data.task_id}`)
+
+ // 开始轮询进度
+ startPolling()
+ // 开始实时获取 Profiles
+ startProfilesPolling()
+ } else {
+ addLog(`准备失败: ${res.error || '未知错误'}`)
+ emit('update-status', 'error')
+ }
+ } catch (err) {
+ addLog(`准备异常: ${err.message}`)
+ emit('update-status', 'error')
+ }
+}
+
+const startPolling = () => {
+ pollTimer = setInterval(pollPrepareStatus, 2000)
+}
+
+const stopPolling = () => {
+ if (pollTimer) {
+ clearInterval(pollTimer)
+ pollTimer = null
+ }
+}
+
+const startProfilesPolling = () => {
+ profilesTimer = setInterval(fetchProfilesRealtime, 3000)
+}
+
+const stopProfilesPolling = () => {
+ if (profilesTimer) {
+ clearInterval(profilesTimer)
+ profilesTimer = null
+ }
+}
+
+const pollPrepareStatus = async () => {
+ if (!taskId.value && !props.simulationId) return
+
+ try {
+ const res = await getPrepareStatus({
+ task_id: taskId.value,
+ simulation_id: props.simulationId
+ })
+
+ if (res.success && res.data) {
+ const data = res.data
+
+ // 更新进度
+ prepareProgress.value = data.progress || 0
+ progressMessage.value = data.message || ''
+
+ // 解析阶段信息
+ if (data.progress_detail) {
+ currentStage.value = data.progress_detail.current_stage_name || ''
+ } else if (data.message) {
+ // 从消息中提取阶段
+ const match = data.message.match(/\[(\d+)\/(\d+)\]\s*([^:]+)/)
+ if (match) {
+ currentStage.value = match[3].trim()
+ }
+ }
+
+ // 检查是否完成
+ if (data.status === 'completed' || data.status === 'ready' || data.already_prepared) {
+ addLog('准备工作已完成')
+ stopPolling()
+ stopProfilesPolling()
+ await loadPreparedData()
+ } else if (data.status === 'failed') {
+ addLog(`准备失败: ${data.error || '未知错误'}`)
+ stopPolling()
+ stopProfilesPolling()
+ }
+ }
+ } catch (err) {
+ console.warn('轮询状态失败:', err)
+ }
+}
+
+const fetchProfilesRealtime = async () => {
+ if (!props.simulationId) return
+
+ try {
+ const res = await getSimulationProfilesRealtime(props.simulationId, 'reddit')
+
+ if (res.success && res.data) {
+ profiles.value = res.data.profiles || []
+ expectedTotal.value = res.data.total_expected
+
+ // 提取实体类型
+ const types = new Set()
+ profiles.value.forEach(p => {
+ if (p.entity_type) types.add(p.entity_type)
+ })
+ entityTypes.value = Array.from(types)
+ }
+ } catch (err) {
+ console.warn('获取 Profiles 失败:', err)
+ }
+}
+
+const loadPreparedData = async () => {
+ phase.value = 2
+ addLog('正在加载配置数据...')
+
+ // 最后获取一次 Profiles
+ await fetchProfilesRealtime()
+
+ // 获取配置
+ try {
+ const res = await getSimulationConfig(props.simulationId)
+ if (res.success && res.data) {
+ simulationConfig.value = res.data
+ addLog('模拟配置加载成功')
+ addLog('环境搭建完成,可以开始模拟')
+ phase.value = 3
+ emit('update-status', 'completed')
+ }
+ } catch (err) {
+ addLog(`加载配置失败: ${err.message}`)
+ emit('update-status', 'error')
+ }
+}
+
+// Scroll log to bottom
+const logContent = ref(null)
+watch(() => props.systemLogs?.length, () => {
+ nextTick(() => {
+ if (logContent.value) {
+ logContent.value.scrollTop = logContent.value.scrollHeight
+ }
+ })
+})
+
+onMounted(() => {
+ // 自动开始准备流程
+ if (props.simulationId) {
+ addLog('Step2 环境搭建初始化')
+ startPrepareSimulation()
+ }
+})
+
+onUnmounted(() => {
+ stopPolling()
+ stopProfilesPolling()
+})
+</script>
+
+<style scoped>
+.env-setup-panel {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ background: #FAFAFA;
+ font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
+}
+
+.scroll-container {
+ flex: 1;
+ overflow-y: auto;
+ padding: 24px;
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
+}
+
+/* Step Card */
+.step-card {
+ background: #FFF;
+ border: 1px solid #E5E5E5;
+ border-radius: 8px;
+ overflow: hidden;
+ transition: all 0.3s ease;
+}
+
+.step-card.active {
+ border-color: #FF5722;
+ box-shadow: 0 2px 8px rgba(255, 87, 34, 0.1);
+}
+
+.step-card.completed {
+ border-color: #4CAF50;
+}
+
+.card-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 16px 20px;
+ background: #FAFAFA;
+ border-bottom: 1px solid #E5E5E5;
+}
+
+.step-info {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+}
+
+.step-num {
+ font-family: 'JetBrains Mono', monospace;
+ font-weight: 700;
+ font-size: 12px;
+ color: #999;
+}
+
+.step-title {
+ font-weight: 600;
+ font-size: 14px;
+ letter-spacing: 0.5px;
+}
+
+.badge {
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 11px;
+ font-weight: 600;
+ padding: 4px 10px;
+ border-radius: 4px;
+}
+
+.badge.success { background: #E8F5E9; color: #2E7D32; }
+.badge.processing { background: #FFF3E0; color: #E65100; }
+.badge.pending { background: #F5F5F5; color: #999; }
+.badge.accent { background: #E3F2FD; color: #1565C0; }
+
+.card-content {
+ padding: 20px;
+}
+
+.api-note {
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 11px;
+ color: #999;
+ margin-bottom: 8px;
+}
+
+.description {
+ font-size: 13px;
+ color: #666;
+ line-height: 1.6;
+ margin-bottom: 16px;
+}
+
+/* Action Section */
+.action-section {
+ margin-top: 16px;
+}
+
+.action-btn {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+ padding: 12px 24px;
+ font-size: 14px;
+ font-weight: 600;
+ border: none;
+ border-radius: 6px;
+ cursor: pointer;
+ transition: all 0.2s ease;
+}
+
+.action-btn.primary {
+ background: #000;
+ color: #FFF;
+}
+
+.action-btn.primary:hover:not(:disabled) {
+ background: #FF5722;
+}
+
+.action-btn.secondary {
+ background: #F5F5F5;
+ color: #333;
+}
+
+.action-btn.secondary:hover:not(:disabled) {
+ background: #E5E5E5;
+}
+
+.action-btn:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+}
+
+.action-group {
+ display: flex;
+ gap: 12px;
+ margin-top: 16px;
+}
+
+/* Info Card */
+.info-card {
+ background: #F5F5F5;
+ border-radius: 6px;
+ padding: 16px;
+ margin-top: 16px;
+}
+
+.info-row {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 8px 0;
+ border-bottom: 1px dashed #E0E0E0;
+}
+
+.info-row:last-child {
+ border-bottom: none;
+}
+
+.info-label {
+ font-size: 12px;
+ color: #666;
+}
+
+.info-value {
+ font-size: 13px;
+ font-weight: 500;
+}
+
+.info-value.mono {
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 12px;
+}
+
+/* Progress Section */
+.progress-section {
+ margin: 16px 0;
+}
+
+.progress-bar {
+ height: 6px;
+ background: #E5E5E5;
+ border-radius: 3px;
+ overflow: hidden;
+ margin-bottom: 12px;
+}
+
+.progress-fill {
+ height: 100%;
+ background: linear-gradient(90deg, #FF5722, #FF9800);
+ border-radius: 3px;
+ transition: width 0.3s ease;
+}
+
+.progress-info {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+}
+
+.progress-stage {
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 11px;
+ font-weight: 600;
+ color: #FF5722;
+ text-transform: uppercase;
+}
+
+.progress-detail {
+ font-size: 12px;
+ color: #666;
+ max-width: 60%;
+ text-align: right;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+/* Stats Grid */
+.stats-grid {
+ display: grid;
+ grid-template-columns: repeat(3, 1fr);
+ gap: 12px;
+ margin-top: 16px;
+}
+
+.stat-card {
+ background: #FAFAFA;
+ border: 1px solid #E5E5E5;
+ border-radius: 6px;
+ padding: 16px;
+ text-align: center;
+}
+
+.stat-value {
+ display: block;
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 24px;
+ font-weight: 700;
+ color: #333;
+}
+
+.stat-label {
+ display: block;
+ font-size: 11px;
+ color: #999;
+ margin-top: 4px;
+}
+
+/* Profiles Preview */
+.profiles-preview {
+ margin-top: 20px;
+ border-top: 1px solid #E5E5E5;
+ padding-top: 16px;
+}
+
+.preview-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 12px;
+}
+
+.preview-title {
+ font-size: 12px;
+ font-weight: 600;
+ color: #666;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+}
+
+.expand-btn {
+ font-size: 12px;
+ color: #FF5722;
+ background: none;
+ border: none;
+ cursor: pointer;
+}
+
+.profiles-list {
+ display: grid;
+ grid-template-columns: repeat(2, 1fr);
+ gap: 12px;
+ max-height: 240px;
+ overflow: hidden;
+ transition: max-height 0.3s ease;
+}
+
+.profiles-list.expanded {
+ max-height: none;
+}
+
+.profile-card {
+ background: #FAFAFA;
+ border: 1px solid #E5E5E5;
+ border-radius: 6px;
+ padding: 12px;
+ cursor: pointer;
+ transition: all 0.2s ease;
+}
+
+.profile-card:hover {
+ border-color: #FF5722;
+ background: #FFF;
+}
+
+.profile-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 8px;
+}
+
+.profile-name {
+ font-size: 13px;
+ font-weight: 600;
+ color: #333;
+}
+
+.profile-type {
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 10px;
+ background: #E3F2FD;
+ color: #1565C0;
+ padding: 2px 6px;
+ border-radius: 3px;
+}
+
+.profile-bio {
+ font-size: 12px;
+ color: #666;
+ line-height: 1.5;
+ margin: 0;
+}
+
+/* Config Preview */
+.config-preview {
+ background: #FAFAFA;
+ border-radius: 6px;
+ padding: 16px;
+ margin-top: 16px;
+}
+
+.config-section {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 10px 0;
+ border-bottom: 1px dashed #E0E0E0;
+}
+
+.config-section:last-child {
+ border-bottom: none;
+}
+
+.config-label {
+ font-size: 12px;
+ color: #666;
+}
+
+.config-value {
+ font-size: 14px;
+ font-weight: 600;
+ color: #333;
+}
+
+.platform-tag {
+ display: inline-block;
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 10px;
+ background: #333;
+ color: #FFF;
+ padding: 2px 8px;
+ border-radius: 3px;
+ margin-left: 6px;
+}
+
+.reasoning-section {
+ margin-top: 16px;
+ padding-top: 16px;
+ border-top: 1px solid #E0E0E0;
+}
+
+.reasoning-label {
+ display: block;
+ font-size: 11px;
+ font-weight: 600;
+ color: #999;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ margin-bottom: 8px;
+}
+
+.reasoning-text {
+ font-size: 12px;
+ color: #666;
+ line-height: 1.6;
+ margin: 0;
+}
+
+/* Profile Modal */
+.profile-modal-overlay {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background: rgba(0, 0, 0, 0.5);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ z-index: 1000;
+}
+
+.profile-modal {
+ background: #FFF;
+ border-radius: 12px;
+ width: 90%;
+ max-width: 500px;
+ max-height: 80vh;
+ overflow: hidden;
+ display: flex;
+ flex-direction: column;
+}
+
+.modal-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 20px 24px;
+ border-bottom: 1px solid #E5E5E5;
+}
+
+.modal-title {
+ font-size: 18px;
+ font-weight: 700;
+}
+
+.close-btn {
+ width: 32px;
+ height: 32px;
+ border: none;
+ background: #F5F5F5;
+ border-radius: 50%;
+ font-size: 18px;
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.close-btn:hover {
+ background: #E5E5E5;
+}
+
+.modal-body {
+ padding: 24px;
+ overflow-y: auto;
+}
+
+.modal-section {
+ margin-bottom: 20px;
+}
+
+.section-label {
+ display: block;
+ font-size: 11px;
+ font-weight: 600;
+ color: #999;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ margin-bottom: 6px;
+}
+
+.section-value {
+ font-size: 14px;
+ color: #333;
+}
+
+.section-text {
+ font-size: 13px;
+ color: #666;
+ line-height: 1.6;
+ margin: 0;
+}
+
+.tags-row {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+}
+
+.interest-tag {
+ font-size: 11px;
+ background: #F5F5F5;
+ color: #666;
+ padding: 4px 10px;
+ border-radius: 12px;
+}
+
+/* System Logs */
+.system-logs {
+ border-top: 1px solid #E5E5E5;
+ background: #1A1A1A;
+ color: #CCC;
+ font-family: 'JetBrains Mono', monospace;
+ font-size: 11px;
+}
+
+.log-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 8px 16px;
+ border-bottom: 1px solid #333;
+}
+
+.log-title {
+ font-weight: 600;
+ color: #FF5722;
+}
+
+.log-id {
+ color: #666;
+}
+
+.log-content {
+ height: 100px;
+ overflow-y: auto;
+ padding: 8px 16px;
+}
+
+.log-line {
+ display: flex;
+ gap: 12px;
+ padding: 4px 0;
+ border-bottom: 1px solid #2A2A2A;
+}
+
+.log-time {
+ color: #666;
+ flex-shrink: 0;
+}
+
+.log-msg {
+ color: #CCC;
+}
+
+/* Spinner */
+.spinner-sm {
+ width: 16px;
+ height: 16px;
+ border: 2px solid #E5E5E5;
+ border-top-color: #FF5722;
+ border-radius: 50%;
+ animation: spin 0.8s linear infinite;
+}
+
+@keyframes spin {
+ to { transform: rotate(360deg); }
+}
+</style>
diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js
index 4bae635b..f8a7a02c 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 7aef9733..333efe97 100644
--- a/frontend/src/views/MainView.vue
+++ b/frontend/src/views/MainView.vue
@@ -22,8 +22,8 @@
<div class="header-right">
<div class="workflow-step">
- <span class="step-num">Step 1/5</span>
- <span class="step-name">图谱构建</span>
+ <span class="step-num">Step {{ currentStep }}/5</span>
+ <span class="step-name">{{ stepNames[currentStep - 1] }}</span>
</div>
<div class="step-divider"></div>
<span class="status-indicator" :class="statusClass">
@@ -46,9 +46,11 @@
/>
</div>
- <!-- Right Panel: Workbench -->
+ <!-- Right Panel: Step Components -->
<div class="panel-wrapper right" :style="rightPanelStyle">
- <WorkbenchPanel
+ <!-- Step 1: 图谱构建 -->
+ <Step1GraphBuild
+ v-if="currentStep === 1"
:currentPhase="currentPhase"
:projectData="projectData"
:ontologyProgress="ontologyProgress"
@@ -57,6 +59,16 @@
:systemLogs="systemLogs"
@next-step="handleNextStep"
/>
+ <!-- Step 2: 环境搭建 -->
+ <Step2EnvSetup
+ v-else-if="currentStep === 2"
+ :projectData="projectData"
+ :graphData="graphData"
+ :systemLogs="systemLogs"
+ @go-back="handleGoBack"
+ @next-step="handleNextStep"
+ @add-log="addLog"
+ />
</div>
</main>
</div>
@@ -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 00000000..9c3e2bfd
--- /dev/null
+++ b/frontend/src/views/SimulationView.vue
@@ -0,0 +1,338 @@
+<template>
+ <div class="main-view">
+ <!-- Header -->
+ <header class="app-header">
+ <div class="header-left">
+ <div class="brand" @click="router.push('/')">MIROFISH</div>
+ </div>
+
+ <div class="header-center">
+ <div class="view-switcher">
+ <button
+ v-for="mode in ['graph', 'split', 'workbench']"
+ :key="mode"
+ class="switch-btn"
+ :class="{ active: viewMode === mode }"
+ @click="viewMode = mode"
+ >
+ {{ { graph: '图谱', split: '双栏', workbench: '工作台' }[mode] }}
+ </button>
+ </div>
+ </div>
+
+ <div class="header-right">
+ <div class="workflow-step">
+ <span class="step-num">Step 2/5</span>
+ <span class="step-name">环境搭建</span>
+ </div>
+ <div class="step-divider"></div>
+ <span class="status-indicator" :class="statusClass">
+ <span class="dot"></span>
+ {{ statusText }}
+ </span>
+ </div>
+ </header>
+
+ <!-- Main Content Area -->
+ <main class="content-area">
+ <!-- Left Panel: Graph -->
+ <div class="panel-wrapper left" :style="leftPanelStyle">
+ <GraphPanel
+ :graphData="graphData"
+ :loading="graphLoading"
+ :currentPhase="2"
+ @refresh="refreshGraph"
+ @toggle-maximize="toggleMaximize('graph')"
+ />
+ </div>
+
+ <!-- Right Panel: Step2 环境搭建 -->
+ <div class="panel-wrapper right" :style="rightPanelStyle">
+ <Step2EnvSetup
+ :simulationId="currentSimulationId"
+ :projectData="projectData"
+ :graphData="graphData"
+ :systemLogs="systemLogs"
+ @go-back="handleGoBack"
+ @next-step="handleNextStep"
+ @add-log="addLog"
+ @update-status="updateStatus"
+ />
+ </div>
+ </main>
+ </div>
+</template>
+
+<script setup>
+import { ref, computed, onMounted, onUnmounted } from 'vue'
+import { useRoute, useRouter } from 'vue-router'
+import GraphPanel from '../components/GraphPanel.vue'
+import Step2EnvSetup from '../components/Step2EnvSetup.vue'
+import { getProject, getGraphData } from '../api/graph'
+import { getSimulation } from '../api/simulation'
+
+const route = useRoute()
+const router = useRouter()
+
+// Props
+const props = defineProps({
+ simulationId: String
+})
+
+// Layout State
+const viewMode = ref('split')
+
+// Data State
+const currentSimulationId = ref(route.params.simulationId)
+const projectData = ref(null)
+const graphData = ref(null)
+const graphLoading = ref(false)
+const systemLogs = ref([])
+const currentStatus = ref('processing') // processing | completed | error
+
+// --- Computed Layout Styles ---
+const leftPanelStyle = computed(() => {
+ if (viewMode.value === 'graph') return { width: '100%', opacity: 1, transform: 'translateX(0)' }
+ if (viewMode.value === 'workbench') return { width: '0%', opacity: 0, transform: 'translateX(-20px)' }
+ return { width: '50%', opacity: 1, transform: 'translateX(0)' }
+})
+
+const rightPanelStyle = computed(() => {
+ if (viewMode.value === 'workbench') return { width: '100%', opacity: 1, transform: 'translateX(0)' }
+ if (viewMode.value === 'graph') return { width: '0%', opacity: 0, transform: 'translateX(20px)' }
+ return { width: '50%', opacity: 1, transform: 'translateX(0)' }
+})
+
+// --- Status Computed ---
+const statusClass = computed(() => {
+ return currentStatus.value
+})
+
+const statusText = computed(() => {
+ if (currentStatus.value === 'error') return 'Error'
+ if (currentStatus.value === 'completed') return 'Ready'
+ return 'Preparing'
+})
+
+// --- Helpers ---
+const addLog = (msg) => {
+ const time = new Date().toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' }) + '.' + new Date().getMilliseconds().toString().padStart(3, '0')
+ systemLogs.value.push({ time, msg })
+ if (systemLogs.value.length > 100) {
+ systemLogs.value.shift()
+ }
+}
+
+const updateStatus = (status) => {
+ currentStatus.value = status
+}
+
+// --- Layout Methods ---
+const toggleMaximize = (target) => {
+ if (viewMode.value === target) {
+ viewMode.value = 'split'
+ } else {
+ viewMode.value = target
+ }
+}
+
+const handleGoBack = () => {
+ // 返回到 process 页面
+ if (projectData.value?.project_id) {
+ router.push({ name: 'Process', params: { projectId: projectData.value.project_id } })
+ } else {
+ router.push('/')
+ }
+}
+
+const handleNextStep = () => {
+ addLog('进入 Step 3: 开始模拟')
+ // TODO: 跳转到 Step 3
+ alert('Step 3: 开始模拟 - Coming soon...')
+}
+
+// --- Data Logic ---
+const loadSimulationData = async () => {
+ try {
+ addLog(`加载模拟数据: ${currentSimulationId.value}`)
+
+ // 获取 simulation 信息
+ const simRes = await getSimulation(currentSimulationId.value)
+ if (simRes.success && simRes.data) {
+ const simData = simRes.data
+
+ // 获取 project 信息
+ if (simData.project_id) {
+ const projRes = await getProject(simData.project_id)
+ if (projRes.success && projRes.data) {
+ projectData.value = projRes.data
+ addLog(`项目加载成功: ${projRes.data.project_id}`)
+
+ // 获取 graph 数据
+ if (projRes.data.graph_id) {
+ await loadGraph(projRes.data.graph_id)
+ }
+ }
+ }
+ } else {
+ addLog(`加载模拟数据失败: ${simRes.error || '未知错误'}`)
+ }
+ } catch (err) {
+ addLog(`加载异常: ${err.message}`)
+ }
+}
+
+const loadGraph = async (graphId) => {
+ graphLoading.value = true
+ try {
+ const res = await getGraphData(graphId)
+ if (res.success) {
+ graphData.value = res.data
+ addLog('图谱数据加载成功')
+ }
+ } catch (err) {
+ addLog(`图谱加载失败: ${err.message}`)
+ } finally {
+ graphLoading.value = false
+ }
+}
+
+const refreshGraph = () => {
+ if (projectData.value?.graph_id) {
+ loadGraph(projectData.value.graph_id)
+ }
+}
+
+onMounted(() => {
+ addLog('SimulationView 初始化')
+ loadSimulationData()
+})
+</script>
+
+<style scoped>
+.main-view {
+ height: 100vh;
+ display: flex;
+ flex-direction: column;
+ background: #FFF;
+ overflow: hidden;
+ font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
+}
+
+/* Header */
+.app-header {
+ height: 60px;
+ border-bottom: 1px solid #EAEAEA;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0 24px;
+ background: #FFF;
+ z-index: 100;
+}
+
+.brand {
+ font-family: 'JetBrains Mono', monospace;
+ font-weight: 800;
+ font-size: 18px;
+ letter-spacing: 1px;
+ cursor: pointer;
+}
+
+.view-switcher {
+ display: flex;
+ background: #F5F5F5;
+ padding: 4px;
+ border-radius: 6px;
+ gap: 4px;
+}
+
+.switch-btn {
+ border: none;
+ background: transparent;
+ padding: 6px 16px;
+ font-size: 12px;
+ font-weight: 600;
+ color: #666;
+ border-radius: 4px;
+ cursor: pointer;
+ transition: all 0.2s;
+}
+
+.switch-btn.active {
+ background: #FFF;
+ color: #000;
+ box-shadow: 0 2px 4px rgba(0,0,0,0.05);
+}
+
+.header-right {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+}
+
+.workflow-step {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 14px;
+}
+
+.step-num {
+ font-family: 'JetBrains Mono', monospace;
+ font-weight: 700;
+ color: #999;
+}
+
+.step-name {
+ font-weight: 700;
+ color: #000;
+}
+
+.step-divider {
+ width: 1px;
+ height: 14px;
+ background-color: #E0E0E0;
+}
+
+.status-indicator {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12px;
+ color: #666;
+ font-weight: 500;
+}
+
+.dot {
+ width: 8px;
+ height: 8px;
+ border-radius: 50%;
+ background: #CCC;
+}
+
+.status-indicator.processing .dot { background: #FF5722; animation: pulse 1s infinite; }
+.status-indicator.completed .dot { background: #4CAF50; }
+.status-indicator.error .dot { background: #F44336; }
+
+@keyframes pulse { 50% { opacity: 0.5; } }
+
+/* Content */
+.content-area {
+ flex: 1;
+ display: flex;
+ position: relative;
+ overflow: hidden;
+}
+
+.panel-wrapper {
+ height: 100%;
+ overflow: hidden;
+ transition: width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s ease, transform 0.3s ease;
+ will-change: width, opacity, transform;
+}
+
+.panel-wrapper.left {
+ border-right: 1px solid #EAEAEA;
+}
+</style>