feat(web): 1. user memory; 2. update workspace's model config

This commit is contained in:
zhaoying
2025-12-25 11:54:31 +08:00
parent a1def533af
commit 2b30a69b94
10 changed files with 155 additions and 89 deletions

View File

@@ -131,6 +131,9 @@ export const getEmotionHealth = (group_id: string) => {
export const getEmotionSuggestions = (group_id: string) => { export const getEmotionSuggestions = (group_id: string) => {
return request.post(`/memory/emotion/suggestions`, { group_id, limit: 20 }) return request.post(`/memory/emotion/suggestions`, { group_id, limit: 20 })
} }
export const analyticsRefresh = (end_user_id: string) => {
return request.post('/memory-storage/analytics/generate_cache', { end_user_id })
}
/*************** end 用户记忆 相关接口 ******************************/ /*************** end 用户记忆 相关接口 ******************************/
@@ -189,7 +192,7 @@ export const updateMemoryReflectionConfig = (values: SelfReflectionEngineConfig)
return request.post('/memory/reflection/save', values) return request.post('/memory/reflection/save', values)
} }
// 反思引擎-试运行 // 反思引擎-试运行
export const pilotRunMemoryReflectionConfig = (values: { config_id: number | string; dialogue_text: string; }) => { export const pilotRunMemoryReflectionConfig = (values: { config_id: number | string; language_type: string; }) => {
return request.get('/memory/reflection/run', values) return request.get('/memory/reflection/run', values)
} }

View File

@@ -1,5 +1,6 @@
import { request } from '@/utils/request' import { request } from '@/utils/request'
import type { SpaceModalData } from '@/views/SpaceManagement/types' import type { SpaceModalData } from '@/views/SpaceManagement/types'
import type { ConfigModalData } from '@/views/UserMemory/types'
// 空间列表 // 空间列表
export const getWorkspaces = () => { export const getWorkspaces = () => {
@@ -22,6 +23,6 @@ export const getWorkspaceModels = () => {
return request.get(`/workspaces/workspace_models`) return request.get(`/workspaces/workspace_models`)
} }
// 更新空间模型配置 // 更新空间模型配置
export const updateWorkspaceModels = () => { export const updateWorkspaceModels = (data: ConfigModalData) => {
return request.post(`/workspaces/workspace_models`) return request.put(`/workspaces/workspace_models`, data)
} }

View File

@@ -329,6 +329,7 @@ export const en = {
publicApiCannotRefreshToken: 'Public API cannot refresh token', publicApiCannotRefreshToken: 'Public API cannot refresh token',
refreshTokenNotExist: 'Refresh token does not exist', refreshTokenNotExist: 'Refresh token does not exist',
reset: 'Reset', reset: 'Reset',
refresh: 'Refresh'
}, },
model: { model: {
searchPlaceholder: 'search model…', searchPlaceholder: 'search model…',
@@ -1039,6 +1040,16 @@ export const en = {
MemorySummary: 'Episodic Memory', MemorySummary: 'Episodic Memory',
Statement: 'Emotional Memory', Statement: 'Emotional Memory',
ExtractedEntity: 'Short-term Memory', ExtractedEntity: 'Short-term Memory',
PERCEPTUAL_MEMORY: 'Perceptual Memory',
WORKING_MEMORY: 'Working Memory',
SHORT_TERM_MEMORY: 'Shot Term Memory',
LONG_TERM_MEMORY: 'Long Term Memory',
EXPLICIT_MEMORY: 'Explicit Memory',
IMPLICIT_MEMORY: 'Implicit Memory',
EMOTIONAL_MEMORY: 'Emotional Memory',
EPISODIC_MEMORY: 'Episodic Memory',
endUserProfile: 'Core Profile', endUserProfile: 'Core Profile',
editEndUserProfile: 'Edit', editEndUserProfile: 'Edit',
name: 'Name', name: 'Name',

View File

@@ -795,7 +795,8 @@ export const zh = {
logoutApiCannotRefreshToken: '退出登录接口不能刷新token', logoutApiCannotRefreshToken: '退出登录接口不能刷新token',
publicApiCannotRefreshToken: '公共接口不能刷新token', publicApiCannotRefreshToken: '公共接口不能刷新token',
refreshTokenNotExist: '刷新token不存在', refreshTokenNotExist: '刷新token不存在',
reset: '重置' reset: '重置',
refresh: '刷新'
}, },
product: { product: {
applicationManagement: '应用管理', applicationManagement: '应用管理',
@@ -1111,10 +1112,21 @@ export const zh = {
nodeStatistics: '记忆分类', nodeStatistics: '记忆分类',
total: '总计', total: '总计',
Chunk: '长期记忆', Chunk: '长期记忆',
MemorySummary: '情景记忆', MemorySummary: '情景记忆',
Statement: '情绪记忆', Statement: '情绪记忆',
ExtractedEntity: '短期记忆', ExtractedEntity: '短期记忆',
PERCEPTUAL_MEMORY: '感知记忆',
WORKING_MEMORY: '工作记忆',
SHORT_TERM_MEMORY: '短期记忆',
LONG_TERM_MEMORY: '长期记忆',
EXPLICIT_MEMORY: '显性记忆',
IMPLICIT_MEMORY: '隐性记忆',
EMOTIONAL_MEMORY: '情绪记忆',
EPISODIC_MEMORY: '情景记忆',
endUserProfile: '核心档案', endUserProfile: '核心档案',
editEndUserProfile: '编辑', editEndUserProfile: '编辑',
name: '姓名', name: '姓名',

View File

@@ -10,6 +10,7 @@ import type { ConfigForm, Result, ReflexionData, MemoryVerify, QualityAssessment
import CustomSelect from '@/components/CustomSelect'; import CustomSelect from '@/components/CustomSelect';
import { getModelListUrl } from '@/api/models' import { getModelListUrl } from '@/api/models'
import Tag from '@/components/Tag' import Tag from '@/components/Tag'
import { useI18n } from '@/store/locale';
const configList = [ const configList = [
// 启用反思引擎 // 启用反思引擎
@@ -78,6 +79,7 @@ const SelfReflectionEngine: React.FC = () => {
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [runLoading, setRunLoading] = useState(false) const [runLoading, setRunLoading] = useState(false)
const [result, setResult] = useState<Result | null>(null) const [result, setResult] = useState<Result | null>(null)
const { language } = useI18n()
const values = Form.useWatch([], form); const values = Form.useWatch([], form);
@@ -135,7 +137,7 @@ const SelfReflectionEngine: React.FC = () => {
.then(() => { .then(() => {
pilotRunMemoryReflectionConfig({ pilotRunMemoryReflectionConfig({
config_id: id, config_id: id,
dialogue_text: t('reflectionEngine.exampleText') language_type: language
}) })
.then((res) => { .then((res) => {
setResult(res as Result) setResult(res as Result)

View File

@@ -41,15 +41,15 @@ const ConfigModal = forwardRef<ConfigModalRef>((_props, ref) => {
.validateFields() .validateFields()
.then(() => { .then(() => {
setLoading(true) setLoading(true)
// updateWorkspaceModels(values as ConfigModalData) updateWorkspaceModels(values)
// .then(() => { .then(() => {
// setLoading(false) setLoading(false)
// handleClose() handleClose()
// message.success(t('common.createSuccess')) message.success(t('common.updateSuccess'))
// }) })
// .catch(() => { .catch(() => {
// setLoading(false) setLoading(false)
// }); });
handleClose() handleClose()
}) })

View File

@@ -1,7 +1,7 @@
import { type FC, useEffect, useState } from 'react' import { type FC, useEffect, useState, useRef } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import clsx from 'clsx' import clsx from 'clsx'
import { Row, Col, Skeleton } from 'antd' import { Row, Col, Skeleton, Flex, Button } from 'antd'
import { useParams } from 'react-router-dom' import { useParams } from 'react-router-dom'
import aboutUs from '@/assets/images/userMemory/aboutUs.svg' import aboutUs from '@/assets/images/userMemory/aboutUs.svg'
import down from '@/assets/images/userMemory/down.svg' import down from '@/assets/images/userMemory/down.svg'
@@ -10,7 +10,9 @@ import PieCard from './components/PieCard'
import RbCard from '@/components/RbCard/Card' import RbCard from '@/components/RbCard/Card'
import { import {
getUserSummary, getUserSummary,
analyticsRefresh
} from '@/api/memory' } from '@/api/memory'
import type { MemoryInsightRef } from './types'
import RelationshipNetwork from './components/RelationshipNetwork' import RelationshipNetwork from './components/RelationshipNetwork'
import MemoryInsight from './components/MemoryInsight' import MemoryInsight from './components/MemoryInsight'
import Empty from '@/components/Empty' import Empty from '@/components/Empty'
@@ -45,10 +47,12 @@ const Title: FC<TitleProps> = ({ type, title, icon, t, expanded, onClick }) => (
const Neo4j: FC = () => { const Neo4j: FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const { id } = useParams() const { id } = useParams()
const memoryInsightRef = useRef<MemoryInsightRef>(null)
const [expanded, setExpanded] = useState<string[]>(['aboutUs', 'interestDistribution', 'importantRelationships', 'importantMomentsInLife']) const [expanded, setExpanded] = useState<string[]>(['aboutUs', 'interestDistribution', 'importantRelationships', 'importantMomentsInLife'])
const [summary, setSummary] = useState<string | null>(null) const [summary, setSummary] = useState<string | null>(null)
const [loading, setLoading] = useState<Record<string, boolean>>({ const [loading, setLoading] = useState<Record<string, boolean>>({
summary: false, summary: false,
refresh: false
}) })
useEffect(() => { useEffect(() => {
@@ -70,73 +74,96 @@ const Neo4j: FC = () => {
setLoading(prev => ({ ...prev, summary: false })) setLoading(prev => ({ ...prev, summary: false }))
}) })
} }
const handleRefresh = () => {
setLoading(prev => ({ ...prev, refresh: true }))
analyticsRefresh(id as string)
.then(res => {
const response = res as { insight_success: boolean; summary_success: boolean; }
if (response.insight_success) {
memoryInsightRef.current?.getInsightReport()
}
if (response.summary_success) {
getSummary()
}
})
.finally(() => {
setLoading(prev => ({ ...prev, refresh: false }))
})
}
return ( return (
<Row gutter={[16, 16]} className="rb:pb-6"> <div>
<Col span={8}> <Flex justify="flex-end">
<Row gutter={[16, 16]}> <Button type="primary" loading={loading.refresh} className="rb:mb-3" onClick={handleRefresh}>
<Col span={24}> {t('common.refresh')}
<EndUserProfile /> </Button>
</Col> </Flex>
<Col span={24}> <Row gutter={[16, 16]} className="rb:pb-6">
<RbCard> <Col span={8}>
{/* 关于我 */} <Row gutter={[16, 16]}>
<> <Col span={24}>
<Title <EndUserProfile />
type="aboutUs" </Col>
title={t('userMemory.aboutMe')} <Col span={24}>
icon={aboutUs} <RbCard>
t={t} {/* 关于我 */}
expanded={expanded.includes('aboutUs')} <>
onClick={handleTitleClick} <Title
/> type="aboutUs"
{expanded.includes('aboutUs') && ( title={t('userMemory.aboutMe')}
<> icon={aboutUs}
{loading.summary t={t}
? <Skeleton className="rb:mt-4" /> expanded={expanded.includes('aboutUs')}
: summary onClick={handleTitleClick}
? <div className="rb:font-regular rb:leading-5.5 rb:pt-4"> />
{summary || '-'} {expanded.includes('aboutUs') && (
</div> <>
: <Empty size={88} className="rb:mt-12 rb:mb-20.25" /> {loading.summary
} ? <Skeleton className="rb:mt-4" />
</> : summary
)} ? <div className="rb:font-regular rb:leading-5.5 rb:pt-4">
</> {summary || '-'}
</div>
: <Empty size={88} className="rb:mt-12 rb:mb-20.25" />
}
</>
)}
</>
{/* 兴趣分布 */} {/* 兴趣分布 */}
<> <>
<Title <Title
type="interestDistribution" type="interestDistribution"
title={t('userMemory.interestDistribution')} title={t('userMemory.interestDistribution')}
icon={interestDistribution} icon={interestDistribution}
t={t} t={t}
expanded={expanded.includes('interestDistribution')} expanded={expanded.includes('interestDistribution')}
onClick={handleTitleClick} onClick={handleTitleClick}
/> />
{expanded.includes('interestDistribution') && ( {expanded.includes('interestDistribution') && (
<PieCard /> <PieCard />
)} )}
</> </>
</RbCard> </RbCard>
</Col> </Col>
</Row>
</Col>
<Col span={16}>
<Row gutter={[16, 16]}>
<Col span={24}>
<NodeStatistics />
</Col>
{/* 记忆洞察 */}
<Col span={24}>
<MemoryInsight ref={memoryInsightRef} />
</Col>
{/* 关系网络 + 记忆详情 */}
<RelationshipNetwork />
</Row>
</Col>
</Row> </Row>
</Col> </div>
<Col span={16}>
<Row gutter={[16, 16]}>
<Col span={24}>
<NodeStatistics />
</Col>
{/* 记忆洞察 */}
<Col span={24}>
<MemoryInsight />
</Col>
{/* 关系网络 + 记忆详情 */}
<RelationshipNetwork />
</Row>
</Col>
</Row>
) )
} }
export default Neo4j export default Neo4j

View File

@@ -1,4 +1,4 @@
import { type FC, useEffect, useState } from 'react' import { type FC, useEffect, useState, forwardRef, useImperativeHandle } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useParams } from 'react-router-dom' import { useParams } from 'react-router-dom'
import { Skeleton } from 'antd'; import { Skeleton } from 'antd';
@@ -7,8 +7,9 @@ import Empty from '@/components/Empty';
import { import {
getMemoryInsightReport, getMemoryInsightReport,
} from '@/api/memory' } from '@/api/memory'
import type { MemoryInsightRef } from '../types'
const MemoryInsight:FC = () => { const MemoryInsight = forwardRef<MemoryInsightRef>((_props, ref) => {
const { t } = useTranslation() const { t } = useTranslation()
const { id } = useParams() const { id } = useParams()
const [loading, setLoading] = useState<boolean>(false) const [loading, setLoading] = useState<boolean>(false)
@@ -31,6 +32,10 @@ const MemoryInsight:FC = () => {
setLoading(false) setLoading(false)
}) })
} }
// 暴露给父组件的方法
useImperativeHandle(ref, () => ({
getInsightReport,
}));
return ( return (
<RbCard <RbCard
title={t('userMemory.memoryInsight')} title={t('userMemory.memoryInsight')}
@@ -51,5 +56,5 @@ const MemoryInsight:FC = () => {
} }
</RbCard> </RbCard>
) )
} })
export default MemoryInsight export default MemoryInsight

View File

@@ -29,9 +29,11 @@ const NodeStatistics: FC = () => {
if (!id) return if (!id) return
setLoading(true) setLoading(true)
getNodeStatistics(id).then((res) => { getNodeStatistics(id).then((res) => {
const response = res as { nodes: NodeStatisticsItem[], total: number } const response = res as NodeStatisticsItem[]
setData(response.nodes) setData(response)
setTotal(response.total) // 计算count总计
const totalCount = response.reduce((sum, item) => sum + (item.count || 0), 0)
setTotal(totalCount)
setLoading(false) setLoading(false)
}) })
.finally(() => { .finally(() => {
@@ -40,7 +42,7 @@ const NodeStatistics: FC = () => {
} }
const handleViewDetail = (type: string) => { const handleViewDetail = (type: string) => {
switch (type) { switch (type) {
case 'Statement': case 'EMOTIONAL_MEMORY':
navigate(`/statement/${id}`) navigate(`/statement/${id}`)
break break
} }
@@ -56,19 +58,19 @@ const NodeStatistics: FC = () => {
> >
{loading {loading
? <Skeleton /> ? <Skeleton />
: data.length > 0 : data && data.length > 0
? <div className={`rb:w-full rb:grid rb:grid-cols-${data.length} rb:gap-2`}> ? <div className={`rb:w-full rb:grid rb:grid-cols-3 rb:gap-2`}>
{data.map(vo => ( {data.map(vo => (
<div <div
key={vo.type} key={vo.type}
className={clsx("rb:group rb:border rb:border-[#DFE4ED] rb:p-0 rb:rounded-xl rb:hover:shadow-[0px_2px_4px_0px_rgba(0,0,0,0.15)]", { className={clsx("rb:group rb:border rb:border-[#DFE4ED] rb:p-0 rb:rounded-xl rb:hover:shadow-[0px_2px_4px_0px_rgba(0,0,0,0.15)]", {
'rb:cursor-pointer': vo.type === 'Statement' 'rb:cursor-pointer': vo.type === 'EMOTIONAL_MEMORY'
})} })}
onClick={() => handleViewDetail(vo.type)} onClick={() => handleViewDetail(vo.type)}
> >
<div className="rb:gap-0.5 rb:p-3 rb:leading-4 rb:text-[#5B6167] rb:flex rb:items-center rb:justify-between rb:border-b rb:border-[#DFE4ED]"> <div className="rb:gap-0.5 rb:p-3 rb:leading-4 rb:text-[#5B6167] rb:flex rb:items-center rb:justify-between rb:border-b rb:border-[#DFE4ED]">
<div className="rb:wrap-break-word rb:line-clamp-1">{t(`userMemory.${vo.type}`)}</div> <div className="rb:wrap-break-word rb:line-clamp-1">{t(`userMemory.${vo.type}`)}</div>
{vo.type === 'Statement' && <div {vo.type === 'EMOTIONAL_MEMORY' && <div
className="rb:w-3 rb:h-3 rb:-ml-0.75 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/home/arrow_top_right.svg')] rb:group-hover:bg-[url('@/assets/images/home/arrow_top_right_hover.svg')]" className="rb:w-3 rb:h-3 rb:-ml-0.75 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/home/arrow_top_right.svg')] rb:group-hover:bg-[url('@/assets/images/home/arrow_top_right_hover.svg')]"
></div>} ></div>}
</div> </div>

View File

@@ -131,3 +131,6 @@ export interface EndUser {
export interface EndUserProfileModalRef { export interface EndUserProfileModalRef {
handleOpen: (vo: EndUser) => void; handleOpen: (vo: EndUser) => void;
} }
export interface MemoryInsightRef {
getInsightReport: () => void
}