feat(web): rag content api

This commit is contained in:
zhaoying
2026-03-31 15:43:18 +08:00
parent 02660c7c97
commit 52ae914e17
8 changed files with 68 additions and 18 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing * @Author: ZhaoYing
* @Date: 2026-02-02 15:18:19 * @Date: 2026-02-02 15:18:19
* @Last Modified by: ZhaoYing * @Last Modified by: ZhaoYing
* @Last Modified time: 2026-03-27 15:52:37 * @Last Modified time: 2026-03-31 15:31:18
*/ */
/** /**
* PageScrollList Component * PageScrollList Component
@@ -48,7 +48,7 @@ interface PageScrollListProps<T, Q = Record<string, unknown>> {
/** API endpoint URL */ /** API endpoint URL */
url: string; url: string;
/** Function to render each list item */ /** Function to render each list item */
renderItem: (item: T) => React.ReactNode; renderItem: (item: T, index: number) => React.ReactNode;
/** Query parameters for API request */ /** Query parameters for API request */
query?: Q; query?: Q;
/** Number of columns in grid layout */ /** Number of columns in grid layout */
@@ -57,6 +57,8 @@ interface PageScrollListProps<T, Q = Record<string, unknown>> {
className?: string; className?: string;
needLoading?: boolean; needLoading?: boolean;
heightClass?: string; heightClass?: string;
gutter?: [number, number] | number;
onTotalChange?: (total: number) => void;
} }
const defaultHeightClass = 'rb:h-[calc(100vh-116px)]!'; const defaultHeightClass = 'rb:h-[calc(100vh-116px)]!';
@@ -70,6 +72,8 @@ const PageScrollList = forwardRef(<T, Q = Record<string, unknown>>({
className = '', className = '',
needLoading = true, needLoading = true,
heightClass, heightClass,
gutter = [12, 12],
onTotalChange,
}: PageScrollListProps<T, Q>, ref: React.Ref<PageScrollListRef>) => { }: PageScrollListProps<T, Q>, ref: React.Ref<PageScrollListRef>) => {
/** Expose refresh method to parent component */ /** Expose refresh method to parent component */
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
@@ -88,6 +92,7 @@ const PageScrollList = forwardRef(<T, Q = Record<string, unknown>>({
const pageRef = useRef(1); const pageRef = useRef(1);
const loadingRef = useRef(false); const loadingRef = useRef(false);
const hasMoreRef = useRef(true); const hasMoreRef = useRef(true);
const [total, setTotal] = useState(0);
/** Load more data from API with pagination */ /** Load more data from API with pagination */
const loadMoreData = (reset?: boolean) => { const loadMoreData = (reset?: boolean) => {
@@ -107,6 +112,9 @@ const PageScrollList = forwardRef(<T, Q = Record<string, unknown>>({
setData(prev => reset ? results : [...prev, ...results]); setData(prev => reset ? results : [...prev, ...results]);
hasMoreRef.current = response.page?.hasnext; hasMoreRef.current = response.page?.hasnext;
setHasMore(response.page?.hasnext); setHasMore(response.page?.hasnext);
const newTotal = response.page?.total || 0;
setTotal(newTotal);
onTotalChange?.(newTotal);
}) })
.catch(() => { .catch(() => {
hasMoreRef.current = false; hasMoreRef.current = false;
@@ -156,11 +164,11 @@ const PageScrollList = forwardRef(<T, Q = Record<string, unknown>>({
{/* Render grid list or empty state */} {/* Render grid list or empty state */}
{data.length > 0 ? ( {data.length > 0 ? (
<Row <Row
gutter={[12, 12]} gutter={gutter}
> >
{data.map((item, index) => ( {data.map((item, index) => (
<Col key={(item as any).id || index} span={24/column}> <Col key={(item as any).id || index} span={24/column}>
{renderItem(item)} {renderItem(item, index)}
</Col> </Col>
))} ))}
</Row> </Row>

View File

@@ -1,3 +1,6 @@
.rb-modal {
top: 40px;
}
.rb-modal .ant-modal-footer .ant-btn { .rb-modal .ant-modal-footer .ant-btn {
height: 32px !important; height: 32px !important;
padding: 0 15px !important; padding: 0 15px !important;

View File

@@ -627,6 +627,8 @@ export const en = {
vision: 'Vision', vision: 'Vision',
audio: 'Audio', audio: 'Audio',
video: 'Video', video: 'Video',
thinking: 'Deep Thinking',
is_thinking: 'Deep Thinking Support',
}, },
knowledgeBase: { knowledgeBase: {
home: 'Home', home: 'Home',
@@ -1421,6 +1423,7 @@ export const en = {
citation: 'Citation and Attribution', citation: 'Citation and Attribution',
citation_desc: 'Display the attribution of source documents and generated content', citation_desc: 'Display the attribution of source documents and generated content',
invalidVariablesTitle: "The following undefined variables are referenced in the conversation opening. Do you want to save the opening configuration?", invalidVariablesTitle: "The following undefined variables are referenced in the conversation opening. Do you want to save the opening configuration?",
deep_thinking: 'Enable Deep Thinking',
apps: 'My Apps', apps: 'My Apps',
sharing: 'Sharing', sharing: 'Sharing',
@@ -1594,6 +1597,8 @@ export const en = {
core_entities: 'Core Entities', core_entities: 'Core Entities',
communityDetailEmptyDesc: 'Click on a community in the chart on the left to view details', communityDetailEmptyDesc: 'Click on a community in the chart on the left to view details',
communityLoadingTip: 'Generating community graph', communityLoadingTip: 'Generating community graph',
assistant: 'AI Assistant',
totalRagMemory: 'Total number of memories',
}, },
space: { space: {
createSpace: 'Create Space', createSpace: 'Create Space',
@@ -1828,6 +1833,8 @@ Memory Bear: After the rebellion, regional warlordism intensified for several re
memoryTipTitle: 'Are you sure you want to enable conversation memory? Conversations will be saved to the memory store.', memoryTipTitle: 'Are you sure you want to enable conversation memory? Conversations will be saved to the memory store.',
stopAudioRecorder: 'Stop Recording', stopAudioRecorder: 'Stop Recording',
startAudioRecorder: 'Start Recording', startAudioRecorder: 'Start Recording',
citations: 'Citations',
reasoning_content: 'Deep reasoning Content',
}, },
login: { login: {
title: 'Red Bear Memory Science', title: 'Red Bear Memory Science',

View File

@@ -795,6 +795,7 @@ export const zh = {
citation: '引用和归属', citation: '引用和归属',
citation_desc: '显示源文档和生成内容的归属部分', citation_desc: '显示源文档和生成内容的归属部分',
invalidVariablesTitle: "对话开场白中引用了以下未定义的变量,是否保存开场白配置?", invalidVariablesTitle: "对话开场白中引用了以下未定义的变量,是否保存开场白配置?",
deep_thinking: '开启深度思考',
apps: '我的应用', apps: '我的应用',
sharing: '共享', sharing: '共享',
@@ -1274,6 +1275,8 @@ export const zh = {
vision: '视觉', vision: '视觉',
audio: '音频', audio: '音频',
video: '视频', video: '视频',
thinking: '深度思考',
is_thinking: '支持深度思考',
}, },
timezones: { timezones: {
'Asia/Shanghai': '中国标准时间 (UTC+8)', 'Asia/Shanghai': '中国标准时间 (UTC+8)',
@@ -1592,6 +1595,8 @@ export const zh = {
core_entities: '核心实体', core_entities: '核心实体',
communityDetailEmptyDesc: '点击左侧图表中的社区查看详情', communityDetailEmptyDesc: '点击左侧图表中的社区查看详情',
communityLoadingTip: '社区图谱生成中', communityLoadingTip: '社区图谱生成中',
assistant: 'AI 助手',
totalRagMemory: '记忆总数',
}, },
space: { space: {
createSpace: '创建空间', createSpace: '创建空间',
@@ -1825,6 +1830,7 @@ export const zh = {
stopAudioRecorder: '停止录音', stopAudioRecorder: '停止录音',
startAudioRecorder: '开始录音', startAudioRecorder: '开始录音',
citations: '引用', citations: '引用',
reasoning_content: '深度思考内容',
}, },
login: { login: {
title: '红熊记忆科学', title: '红熊记忆科学',

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing * @Author: ZhaoYing
* @Date: 2026-02-03 17:57:11 * @Date: 2026-02-03 17:57:11
* @Last Modified by: ZhaoYing * @Last Modified by: ZhaoYing
* @Last Modified time: 2026-03-27 10:26:31 * @Last Modified time: 2026-03-31 15:29:45
*/ */
/** /**
* RAG User Memory Detail View * RAG User Memory Detail View
@@ -114,7 +114,7 @@ const Rag: FC = () => {
} }
return ( return (
<Row gutter={[16, 16]} className="rb:h-full!"> <Row gutter={[16, 16]} className="rb:h-full!">
<Col span={8}> <Col span={8} className="rb:h-full!">
<RbCard <RbCard
bodyClassName="rb:p-3! rb:pt-4!" bodyClassName="rb:p-3! rb:pt-4!"
className="rb:h-full!" className="rb:h-full!"
@@ -175,7 +175,7 @@ const Rag: FC = () => {
</> </>
</RbCard> </RbCard>
</Col> </Col>
<Col span={16}> <Col span={16} className="rb:h-full!">
<ConversationMemory /> <ConversationMemory />
</Col> </Col>
</Row> </Row>

View File

@@ -2,38 +2,64 @@
* @Author: ZhaoYing * @Author: ZhaoYing
* @Date: 2026-02-03 18:34:04 * @Date: 2026-02-03 18:34:04
* @Last Modified by: ZhaoYing * @Last Modified by: ZhaoYing
* @Last Modified time: 2026-03-27 10:28:53 * @Last Modified time: 2026-03-31 15:35:13
*/ */
import { type FC } from 'react' import { type FC, useState } 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 { Divider, Flex } from 'antd'
import clsx from 'clsx'
import RbCard from '@/components/RbCard/Card' import RbCard from '@/components/RbCard/Card'
import PageScrollList from '@/components/PageScrollList' import PageScrollList from '@/components/PageScrollList'
import Markdown from '@/components/Markdown' import Markdown from '@/components/Markdown'
import { getRagContentUrl } from '@/api/memory' import { getRagContentUrl } from '@/api/memory'
interface DataItem {
role: 'user' | 'assistant';
content: string;
}
const ConversationMemory: FC = () => { const ConversationMemory: FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const { id } = useParams() const { id } = useParams()
const [total, setTotal] = useState(0)
return ( return (
<RbCard <RbCard
title={t('userMemory.conversationMemory')} title={<span className="rb:font-[MiSans-Bold] rb:font-bold">{t('userMemory.conversationMemory')}</span>}
headerType="borderless" headerType="borderless"
headerClassName="rb:min-h-[54px]! rb:pt-0! rb:mb-0! rb:font-[MiSans-Bold] rb:font-bold" headerClassName="rb:min-h-[54px]! rb:pt-0! rb:mb-0!"
bodyClassName="rb:p-4! rb:pt-0! rb:h-[calc(100%-54px)]!" bodyClassName="rb:p-4! rb:pt-0! rb:pb-1! rb:h-[calc(100%-54px)]!"
className="rb:h-full!" className="rb:h-full!"
extra={<div className="rb:text-[#5B6167] rb:leading-5">{t('userMemory.totalRagMemory')}: <span className="rb:font-medium rb:text-[#171719]">{total}</span></div>}
> >
<PageScrollList<string> <PageScrollList<DataItem>
url={getRagContentUrl} url={getRagContentUrl}
query={{ end_user_id: id }} query={{ end_user_id: id }}
column={1} column={1}
renderItem={(item: string) => ( gutter={0}
<div onTotalChange={setTotal}
className="rb:rounded-lg rb-border rb:px-4 rb:py-3 rb:bg-[#F0F3F8] rb:mt-2 rb:text-[#212332] rb:text-sm" renderItem={(item, index) => (
<div>
{index !== 0 && <Divider className="rb:mt-1! rb:mb-3! rb:ml-11!" />}
<Flex
align="start"
gap={12}
> >
<Markdown content={item} /> <div className={clsx("rb:size-8 rb:bg-cover", {
'rb:bg-[url(src/assets/images/conversation/user.png)]': item.role === 'user',
'rb:bg-[url(src/assets/images/conversation/ai.png)]': item.role === 'assistant',
})}></div>
<div
className="rb:flex-1"
>
<div className="rb:text-[12px] rb:text-[#5B6167] rb:leading-4.5 rb:mb-0.5">
{item.role === 'assistant' ? t('userMemory.assistant') : t('userMemory.user')}
</div>
<Markdown content={item.content} />
</div>
</Flex>
</div> </div>
)} )}
className="rb:h-full!" className="rb:h-full!"