import { Sources } from '@ant-design/x';
import XMarkdown, { type ComponentProps } from '@ant-design/x-markdown';
import { Tooltip } from 'antd';
import React, { useMemo } from 'react';
import type { RetrieverResource } from '~/api/dify-chat';
import '../../styles/components/chat-with-llm/markdown.css';
interface MarkdownProps {
content: string;
className?: string;
retrieverResources?: RetrieverResource[];
}
/**
* 引用索引组件 - 在文本中显示可点击的引用标记
*/
const SourceRefComponent = React.memo(({
children,
resources
}: ComponentProps & { resources?: RetrieverResource[] }) => {
const refNumber = parseInt(`${children}` || '0', 10);
// 如果没有资源数据或引用号无效,只显示上标数字
if (!resources || resources.length === 0 || refNumber <= 0) {
return [{children}];
}
// 查找对应的资源
const resource = resources.find(r => r.position === refNumber);
if (!resource) {
return [{children}];
}
// 构建引用项列表 - 显示完整内容
const items = resources.map((r) => ({
title: `${r.position}. ${r.document_name}`,
key: r.position,
description: r.content || '',
}));
return (