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

@@ -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 clsx from 'clsx'
import { Row, Col, Skeleton } from 'antd'
import { Row, Col, Skeleton, Flex, Button } from 'antd'
import { useParams } from 'react-router-dom'
import aboutUs from '@/assets/images/userMemory/aboutUs.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 {
getUserSummary,
analyticsRefresh
} from '@/api/memory'
import type { MemoryInsightRef } from './types'
import RelationshipNetwork from './components/RelationshipNetwork'
import MemoryInsight from './components/MemoryInsight'
import Empty from '@/components/Empty'
@@ -45,10 +47,12 @@ const Title: FC<TitleProps> = ({ type, title, icon, t, expanded, onClick }) => (
const Neo4j: FC = () => {
const { t } = useTranslation()
const { id } = useParams()
const memoryInsightRef = useRef<MemoryInsightRef>(null)
const [expanded, setExpanded] = useState<string[]>(['aboutUs', 'interestDistribution', 'importantRelationships', 'importantMomentsInLife'])
const [summary, setSummary] = useState<string | null>(null)
const [loading, setLoading] = useState<Record<string, boolean>>({
summary: false,
refresh: false
})
useEffect(() => {
@@ -70,73 +74,96 @@ const Neo4j: FC = () => {
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 (
<Row gutter={[16, 16]} className="rb:pb-6">
<Col span={8}>
<Row gutter={[16, 16]}>
<Col span={24}>
<EndUserProfile />
</Col>
<Col span={24}>
<RbCard>
{/* 关于我 */}
<>
<Title
type="aboutUs"
title={t('userMemory.aboutMe')}
icon={aboutUs}
t={t}
expanded={expanded.includes('aboutUs')}
onClick={handleTitleClick}
/>
{expanded.includes('aboutUs') && (
<>
{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" />
}
</>
)}
</>
<div>
<Flex justify="flex-end">
<Button type="primary" loading={loading.refresh} className="rb:mb-3" onClick={handleRefresh}>
{t('common.refresh')}
</Button>
</Flex>
<Row gutter={[16, 16]} className="rb:pb-6">
<Col span={8}>
<Row gutter={[16, 16]}>
<Col span={24}>
<EndUserProfile />
</Col>
<Col span={24}>
<RbCard>
{/* 关于我 */}
<>
<Title
type="aboutUs"
title={t('userMemory.aboutMe')}
icon={aboutUs}
t={t}
expanded={expanded.includes('aboutUs')}
onClick={handleTitleClick}
/>
{expanded.includes('aboutUs') && (
<>
{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
type="interestDistribution"
title={t('userMemory.interestDistribution')}
icon={interestDistribution}
t={t}
expanded={expanded.includes('interestDistribution')}
onClick={handleTitleClick}
/>
{/* 兴趣分布 */}
<>
<Title
type="interestDistribution"
title={t('userMemory.interestDistribution')}
icon={interestDistribution}
t={t}
expanded={expanded.includes('interestDistribution')}
onClick={handleTitleClick}
/>
{expanded.includes('interestDistribution') && (
<PieCard />
)}
</>
</RbCard>
</Col>
{expanded.includes('interestDistribution') && (
<PieCard />
)}
</>
</RbCard>
</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>
</Col>
<Col span={16}>
<Row gutter={[16, 16]}>
<Col span={24}>
<NodeStatistics />
</Col>
{/* 记忆洞察 */}
<Col span={24}>
<MemoryInsight />
</Col>
{/* 关系网络 + 记忆详情 */}
<RelationshipNetwork />
</Row>
</Col>
</Row>
</div>
)
}
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 { useParams } from 'react-router-dom'
import { Skeleton } from 'antd';
@@ -7,8 +7,9 @@ import Empty from '@/components/Empty';
import {
getMemoryInsightReport,
} from '@/api/memory'
import type { MemoryInsightRef } from '../types'
const MemoryInsight:FC = () => {
const MemoryInsight = forwardRef<MemoryInsightRef>((_props, ref) => {
const { t } = useTranslation()
const { id } = useParams()
const [loading, setLoading] = useState<boolean>(false)
@@ -31,6 +32,10 @@ const MemoryInsight:FC = () => {
setLoading(false)
})
}
// 暴露给父组件的方法
useImperativeHandle(ref, () => ({
getInsightReport,
}));
return (
<RbCard
title={t('userMemory.memoryInsight')}
@@ -51,5 +56,5 @@ const MemoryInsight:FC = () => {
}
</RbCard>
)
}
})
export default MemoryInsight

View File

@@ -29,9 +29,11 @@ const NodeStatistics: FC = () => {
if (!id) return
setLoading(true)
getNodeStatistics(id).then((res) => {
const response = res as { nodes: NodeStatisticsItem[], total: number }
setData(response.nodes)
setTotal(response.total)
const response = res as NodeStatisticsItem[]
setData(response)
// 计算count总计
const totalCount = response.reduce((sum, item) => sum + (item.count || 0), 0)
setTotal(totalCount)
setLoading(false)
})
.finally(() => {
@@ -40,7 +42,7 @@ const NodeStatistics: FC = () => {
}
const handleViewDetail = (type: string) => {
switch (type) {
case 'Statement':
case 'EMOTIONAL_MEMORY':
navigate(`/statement/${id}`)
break
}
@@ -56,19 +58,19 @@ const NodeStatistics: FC = () => {
>
{loading
? <Skeleton />
: data.length > 0
? <div className={`rb:w-full rb:grid rb:grid-cols-${data.length} rb:gap-2`}>
: data && data.length > 0
? <div className={`rb:w-full rb:grid rb:grid-cols-3 rb:gap-2`}>
{data.map(vo => (
<div
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)]", {
'rb:cursor-pointer': vo.type === 'Statement'
'rb:cursor-pointer': vo.type === 'EMOTIONAL_MEMORY'
})}
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: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')]"
></div>}
</div>

View File

@@ -130,4 +130,7 @@ export interface EndUser {
}
export interface EndUserProfileModalRef {
handleOpen: (vo: EndUser) => void;
}
export interface MemoryInsightRef {
getInsightReport: () => void
}