feat(memory): dream-v2 D1 — Memory Timeline view (frontend + backend)

This commit is contained in:
matevip 2026-04-21 04:58:26 +08:00
parent 155bab1739
commit 90067d1c9f
9 changed files with 532 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package vip.mate.memory.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vip.mate.common.result.R;
import vip.mate.memory.model.DreamReportEntity;
import vip.mate.memory.repository.DreamReportMapper;
import vip.mate.workspace.core.annotation.RequireWorkspaceRole;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Dream report API provides paginated access to dream history for the Memory Timeline UI.
*
* @author MateClaw Team
*/
@Tag(name = "Dream Reports")
@RestController
@RequestMapping("/api/v1/memory/{agentId}/dream")
@RequiredArgsConstructor
public class DreamController {
private final DreamReportMapper dreamReportMapper;
@Operation(summary = "List dream reports (paginated, newest first)")
@GetMapping("/reports")
@RequireWorkspaceRole("viewer")
public R<Map<String, Object>> listReports(
@PathVariable Long agentId,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "20") int size) {
Page<DreamReportEntity> pageParam = new Page<>(page, size);
Page<DreamReportEntity> result = dreamReportMapper.selectPage(pageParam,
new LambdaQueryWrapper<DreamReportEntity>()
.eq(DreamReportEntity::getAgentId, agentId)
.eq(DreamReportEntity::getDeleted, 0)
.orderByDesc(DreamReportEntity::getStartedAt));
Map<String, Object> data = new LinkedHashMap<>();
data.put("records", result.getRecords());
data.put("total", result.getTotal());
data.put("page", result.getCurrent());
data.put("size", result.getSize());
return R.ok(data);
}
@Operation(summary = "Get a single dream report by ID")
@GetMapping("/reports/{reportId}")
@RequireWorkspaceRole("viewer")
public R<DreamReportEntity> getReport(
@PathVariable Long agentId,
@PathVariable Long reportId) {
DreamReportEntity entity = dreamReportMapper.selectOne(
new LambdaQueryWrapper<DreamReportEntity>()
.eq(DreamReportEntity::getId, reportId)
.eq(DreamReportEntity::getAgentId, agentId)
.eq(DreamReportEntity::getDeleted, 0));
if (entity == null) {
return R.fail("Report not found");
}
return R.ok(entity);
}
}

View File

@ -237,6 +237,7 @@ export default {
cronJobs: 'Cron Jobs',
settings: 'Settings',
logout: 'Logout',
memory: 'Memory',
themeLight: 'Light',
themeDark: 'Dark',
themeSystem: 'System',
@ -1780,4 +1781,26 @@ export default {
tokens: 'Tokens',
},
},
memory: {
title: 'Memory',
selectAgent: 'Select Agent',
selectAgentHint: 'Select an agent to view its memory',
tabTimeline: 'Dream Timeline',
tabMemory: 'Long-term Memory',
tabProfile: 'Profile',
tabFacts: 'Facts',
noReports: 'No dream reports yet',
report: {
mode: 'Mode',
topic: 'Topic',
status: 'Status',
time: 'Time',
candidates: 'Candidates',
promoted: 'Promoted',
rejected: 'Rejected',
trigger: 'Trigger',
reason: 'LLM Reason',
diff: 'Change Summary',
},
},
} as const

View File

@ -239,6 +239,7 @@ export default {
logout: '退出登录',
themeLight: '浅色',
themeDark: '深色',
memory: '记忆',
themeSystem: '跟随系统',
themeLabel: '外观',
languageLabel: '语言',
@ -1790,4 +1791,26 @@ export default {
tokens: 'Token',
},
},
memory: {
title: '记忆管理',
selectAgent: '选择 Agent',
selectAgentHint: '请先选择一个 Agent 查看其记忆',
tabTimeline: 'Dream 时间线',
tabMemory: '长期记忆',
tabProfile: '用户画像',
tabFacts: '事实库',
noReports: '暂无 Dream 记录',
report: {
mode: '模式',
topic: '主题',
status: '状态',
time: '时间',
candidates: '候选数',
promoted: '已整合',
rejected: '未采纳',
trigger: '触发方式',
reason: 'LLM 理由',
diff: '变更摘要',
},
},
} as const

View File

@ -33,6 +33,12 @@ const router = createRouter({
component: () => import('@/views/Wiki/index.vue'),
meta: { title: 'Wiki' },
},
{
path: 'memory',
name: 'Memory',
component: () => import('@/views/Memory/index.vue'),
meta: { title: 'Memory' },
},
// ==================== Connect ====================
{
path: 'channels',

View File

@ -0,0 +1,53 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { http } from '@/api'
export interface DreamReportItem {
id: string
agentId: number
mode: string
topic: string | null
triggerSource: string
triggeredBy: string
startedAt: string
finishedAt: string
candidateCount: number
promotedCount: number
rejectedCount: number
memoryDiff: string | null
llmReason: string | null
status: string
errorMessage: string | null
}
export const useMemoryStore = defineStore('memory', () => {
const reports = ref<DreamReportItem[]>([])
const total = ref(0)
const loading = ref(false)
const currentReport = ref<DreamReportItem | null>(null)
async function fetchReports(agentId: number, page = 1, size = 20) {
loading.value = true
try {
const res = await http.get(`/memory/${agentId}/dream/reports`, {
params: { page, size },
})
reports.value = res.data.records || []
total.value = res.data.total || 0
} finally {
loading.value = false
}
}
async function fetchReport(agentId: number, reportId: string) {
loading.value = true
try {
const res = await http.get(`/memory/${agentId}/dream/reports/${reportId}`)
currentReport.value = res.data
} finally {
loading.value = false
}
}
return { reports, total, loading, currentReport, fetchReports, fetchReport }
})

View File

@ -0,0 +1,114 @@
<template>
<el-drawer v-model="visible" :title="panelTitle" size="480px" @close="emit('close')">
<div v-if="!report" class="panel-loading">
<el-skeleton :rows="6" animated />
</div>
<div v-else class="panel-content">
<el-descriptions :column="1" border size="small">
<el-descriptions-item :label="t('memory.report.mode')">
<el-tag :type="report.mode === 'FOCUSED' ? 'warning' : 'info'" size="small">{{ report.mode }}</el-tag>
</el-descriptions-item>
<el-descriptions-item v-if="report.topic" :label="t('memory.report.topic')">
{{ report.topic }}
</el-descriptions-item>
<el-descriptions-item :label="t('memory.report.status')">
<el-tag :type="statusType(report.status)" size="small">{{ report.status }}</el-tag>
</el-descriptions-item>
<el-descriptions-item :label="t('memory.report.time')">
{{ formatTime(report.startedAt) }} ~ {{ formatTime(report.finishedAt) }}
</el-descriptions-item>
<el-descriptions-item :label="t('memory.report.candidates')">
{{ report.candidateCount }}
</el-descriptions-item>
<el-descriptions-item :label="t('memory.report.promoted')">
<span class="text-success">{{ report.promotedCount }}</span>
</el-descriptions-item>
<el-descriptions-item :label="t('memory.report.rejected')">
<span class="text-danger">{{ report.rejectedCount }}</span>
</el-descriptions-item>
<el-descriptions-item :label="t('memory.report.trigger')">
{{ report.triggerSource }} / {{ report.triggeredBy }}
</el-descriptions-item>
</el-descriptions>
<div v-if="report.llmReason" class="section">
<h4>{{ t('memory.report.reason') }}</h4>
<p class="reason-text">{{ report.llmReason }}</p>
</div>
<div v-if="report.memoryDiff" class="section">
<h4>{{ t('memory.report.diff') }}</h4>
<code class="diff-text">{{ report.memoryDiff }}</code>
</div>
<div v-if="report.errorMessage" class="section error-section">
<h4>Error</h4>
<p class="error-text">{{ report.errorMessage }}</p>
</div>
</div>
</el-drawer>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import type { DreamReportItem } from '@/stores/useMemoryStore'
const props = defineProps<{ report: DreamReportItem | null }>()
const emit = defineEmits<{ close: [] }>()
const { t } = useI18n()
const visible = computed(() => props.report !== null)
const panelTitle = computed(() => {
if (!props.report) return ''
return `Dream Report — ${props.report.mode}`
})
function statusType(status: string) {
if (status === 'SUCCESS') return 'success'
if (status === 'FAILED') return 'danger'
return 'warning'
}
function formatTime(isoStr: string) {
if (!isoStr) return ''
return new Date(isoStr).toLocaleString()
}
</script>
<style scoped>
.panel-content {
padding: 0 4px;
}
.panel-loading {
padding: 20px;
}
.section {
margin-top: 16px;
}
.section h4 {
margin: 0 0 8px;
font-size: 14px;
color: var(--el-text-color-primary);
}
.reason-text {
font-size: 13px;
color: var(--el-text-color-regular);
line-height: 1.5;
}
.diff-text {
display: block;
padding: 8px 12px;
background: var(--el-fill-color-lighter);
border-radius: 4px;
font-size: 12px;
white-space: pre-wrap;
}
.error-section .error-text {
color: var(--el-color-danger);
font-size: 13px;
}
.text-success { color: var(--el-color-success); font-weight: 600; }
.text-danger { color: var(--el-color-danger); font-weight: 600; }
</style>

View File

@ -0,0 +1,167 @@
<template>
<div class="dream-timeline">
<div v-if="store.loading" class="loading-state">
<el-skeleton :rows="5" animated />
</div>
<el-empty v-else-if="store.reports.length === 0" :description="t('memory.noReports')" />
<div v-else class="timeline-list">
<div
v-for="report in store.reports"
:key="report.id"
class="timeline-item"
:class="{ active: selectedId === report.id }"
@click="selectReport(report)"
>
<div class="timeline-dot" :class="report.status.toLowerCase()" />
<div class="timeline-content">
<div class="timeline-header">
<el-tag :type="modeTagType(report.mode)" size="small">{{ report.mode }}</el-tag>
<span class="timeline-time">{{ formatTime(report.startedAt) }}</span>
</div>
<div class="timeline-meta">
<span v-if="report.topic" class="topic">{{ report.topic }}</span>
<span class="counts">
+{{ report.promotedCount }} / -{{ report.rejectedCount }} / {{ report.candidateCount }} candidates
</span>
</div>
<div v-if="report.llmReason" class="timeline-reason">{{ truncate(report.llmReason, 80) }}</div>
</div>
</div>
<div class="pagination-wrapper">
<el-pagination
v-model:current-page="currentPage"
:page-size="pageSize"
:total="store.total"
layout="prev, pager, next"
@current-change="onPageChange"
/>
</div>
</div>
<!-- Detail panel -->
<DreamReportPanel v-if="selectedId" :report="store.currentReport" @close="selectedId = null" />
</div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useMemoryStore, type DreamReportItem } from '@/stores/useMemoryStore'
import DreamReportPanel from './DreamReportPanel.vue'
const props = defineProps<{ agentId: number }>()
const { t } = useI18n()
const store = useMemoryStore()
const currentPage = ref(1)
const pageSize = 20
const selectedId = ref<string | null>(null)
watch(() => props.agentId, () => {
currentPage.value = 1
selectedId.value = null
loadReports()
}, { immediate: true })
function loadReports() {
store.fetchReports(props.agentId, currentPage.value, pageSize)
}
function onPageChange(page: number) {
currentPage.value = page
loadReports()
}
function selectReport(report: DreamReportItem) {
selectedId.value = report.id
store.fetchReport(props.agentId, report.id)
}
function modeTagType(mode: string) {
return mode === 'FOCUSED' ? 'warning' : 'info'
}
function formatTime(isoStr: string) {
if (!isoStr) return ''
const d = new Date(isoStr)
return d.toLocaleString()
}
function truncate(str: string, max: number) {
return str.length > max ? str.slice(0, max) + '...' : str
}
</script>
<style scoped>
.dream-timeline {
position: relative;
}
.timeline-list {
padding-left: 20px;
border-left: 2px solid var(--el-border-color-lighter);
}
.timeline-item {
position: relative;
padding: 12px 16px;
margin-bottom: 8px;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.2s;
}
.timeline-item:hover {
background-color: var(--el-fill-color-light);
}
.timeline-item.active {
background-color: var(--el-color-primary-light-9);
}
.timeline-dot {
position: absolute;
left: -27px;
top: 18px;
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--el-color-info);
}
.timeline-dot.success { background: var(--el-color-success); }
.timeline-dot.failed { background: var(--el-color-danger); }
.timeline-dot.skipped { background: var(--el-color-warning); }
.timeline-header {
display: flex;
align-items: center;
gap: 8px;
}
.timeline-time {
font-size: 12px;
color: var(--el-text-color-secondary);
}
.timeline-meta {
margin-top: 4px;
font-size: 13px;
color: var(--el-text-color-regular);
}
.timeline-meta .topic {
font-weight: 500;
margin-right: 8px;
}
.timeline-meta .counts {
color: var(--el-text-color-secondary);
font-size: 12px;
}
.timeline-reason {
margin-top: 4px;
font-size: 12px;
color: var(--el-text-color-secondary);
font-style: italic;
}
.pagination-wrapper {
margin-top: 16px;
display: flex;
justify-content: center;
}
.loading-state {
padding: 20px;
}
</style>

View File

@ -0,0 +1,72 @@
<template>
<div class="memory-view">
<div class="memory-header">
<h2>{{ t('memory.title') }}</h2>
<el-select v-model="selectedAgentId" :placeholder="t('memory.selectAgent')" style="width: 200px" @change="onAgentChange">
<el-option v-for="agent in agents" :key="agent.id" :label="agent.name" :value="agent.id" />
</el-select>
</div>
<el-tabs v-model="activeTab" class="memory-tabs">
<el-tab-pane :label="t('memory.tabTimeline')" name="timeline">
<DreamTimeline v-if="selectedAgentId" :agent-id="selectedAgentId" />
<el-empty v-else :description="t('memory.selectAgentHint')" />
</el-tab-pane>
<el-tab-pane :label="t('memory.tabMemory')" name="memory" disabled>
<el-empty description="Phase 2b" />
</el-tab-pane>
<el-tab-pane :label="t('memory.tabProfile')" name="profile" disabled>
<el-empty description="Phase 2b" />
</el-tab-pane>
<el-tab-pane :label="t('memory.tabFacts')" name="facts" disabled>
<el-empty description="Phase 3" />
</el-tab-pane>
</el-tabs>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useAgentStore } from '@/stores/useAgentStore'
import DreamTimeline from './components/DreamTimeline.vue'
const { t } = useI18n()
const agentStore = useAgentStore()
const agents = ref<any[]>([])
const selectedAgentId = ref<number | null>(null)
const activeTab = ref('timeline')
onMounted(async () => {
await agentStore.fetchAgents()
agents.value = agentStore.agents
if (agents.value.length > 0) {
selectedAgentId.value = agents.value[0].id
}
})
function onAgentChange() {
// DreamTimeline watches agentId prop
}
</script>
<style scoped>
.memory-view {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
.memory-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
}
.memory-header h2 {
margin: 0;
font-size: 20px;
}
.memory-tabs {
margin-top: 10px;
}
</style>

View File

@ -306,6 +306,11 @@ const navGroups = computed(() => [
label: t('nav.wiki'),
icon: `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/><line x1="8" y1="7" x2="16" y2="7"/><line x1="8" y1="11" x2="14" y2="11"/></svg>`,
},
{
path: '/memory',
label: t('nav.memory'),
icon: `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2a4 4 0 0 1 4 4v2a4 4 0 0 1-8 0V6a4 4 0 0 1 4-4z"/><path d="M16 14H8a4 4 0 0 0-4 4v2h16v-2a4 4 0 0 0-4-4z"/><line x1="12" y1="11" x2="12" y2="14"/></svg>`,
},
],
},
{