Commit d440b375 by 李伟康

feat(chat): 添加全局配置管理和报告功能

- 添加全局配置状态管理到应用store
- 集成外部配置加载器从远程URL获取配置
- 实现报告模块支持周报月报展示
- 更新Markdown解析器支持JSON内容提取
- 添加图表和报告渲染组件
- 修改聊天界面UI元素样式调整
- 更新发送停止清空按钮为图片图标
- 优化输入框占位符显示响应状态
- 实现重启功能替换为清空操作
- 添加设置按钮跳转到外部配置页面
- 实现建议问题批量刷新功能
- 修复输入消息类型枚举值错误
1 parent b69b06a4
......@@ -11,6 +11,7 @@ type State = {
showAgentLogModal: boolean
showMessageLogModal: boolean
showAppConfigureFeaturesModal: boolean
globalConfig: any
}
type Action = {
......@@ -22,6 +23,7 @@ type Action = {
setShowAgentLogModal: (showAgentLogModal: boolean) => void
setShowMessageLogModal: (showMessageLogModal: boolean) => void
setShowAppConfigureFeaturesModal: (showAppConfigureFeaturesModal: boolean) => void
setGlobalConfig: (globalConfig: any) => void
}
export const useStore = create<State & Action>(set => ({
......@@ -51,4 +53,6 @@ export const useStore = create<State & Action>(set => ({
}),
showAppConfigureFeaturesModal: false,
setShowAppConfigureFeaturesModal: showAppConfigureFeaturesModal => set(() => ({ showAppConfigureFeaturesModal })),
globalConfig: undefined,
setGlobalConfig: globalConfig => set(() => ({ globalConfig })),
}))
......@@ -4,15 +4,24 @@ import { Markdown } from '@/app/components/base/markdown'
import cn from '@/utils/classnames'
import { useChatBodyContext } from '../../body/context'
const BasicContent: FC = () => {
type BasicContentProps = {
onJsonContentReady?: (jsonContent: any) => React.ReactNode
}
const BasicContent: FC<BasicContentProps> = ({ onJsonContentReady }) => {
const { annotation, content, isError, hasAgentThoughts } = useChatBodyContext()
if(!content.trim() || hasAgentThoughts) return null
if (!content.trim() || hasAgentThoughts) return null
if (annotation?.logAnnotation) return <Markdown content={annotation?.logAnnotation.content || ''} />
return <Markdown className={cn(isError && '!text-[#F04438]')} content={content} />
return (
<Markdown
className={cn(isError && '!text-[#F04438]')}
content={content}
onJsonContentReady={onJsonContentReady}
/>
)
}
export default memo(BasicContent)
\ No newline at end of file
export default memo(BasicContent)
......@@ -4,7 +4,7 @@ import { LOADING_ICON } from "@/app/components/base/chat/constants";
const LoadingIcon: FC = () => {
return (
<img src={LOADING_ICON} alt="loading" className="w-5 h-5 mr-2" />
<img src={LOADING_ICON} alt="loading" className="w-5 h-5 mr-2" style={{ border: 'none' }} />
)
}
export default memo(LoadingIcon)
......@@ -2,4 +2,8 @@
background: linear-gradient(180deg, #EDF5FF 0%, #FFFFFF 19.65%, #FFFFFF 100%);
border-radius: 16px 16px 16px 4px;
}
.report-container{
margin: 16px 0;
border-radius: 16px;
}
\ No newline at end of file
......@@ -8,6 +8,9 @@ import More from './components/more'
import cn from '@/utils/classnames'
import LoadingText from './components/loading-text'
import { useChatBodyContext } from '../body/context'
import {
Report
} from '@/app/components/base/markdown/blocks'
import s from './index.module.scss'
type AnswerProps = {
......@@ -15,8 +18,16 @@ type AnswerProps = {
}
const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => {
const { containerRef, contentRef, more, isAnswer } = useChatBodyContext()
const [jsonContent, setJsonContent] = useState<any>(null)
if (!isAnswer) return null
const handleJsonContentReady = (content: any) => {
setJsonContent(content)
return null // 不在 BasicContent 内部渲染
}
return (
<>
<div className="mb-2 flex last:mb-0">
<div className="chat-answer-container group w-0 grow pb-2" ref={containerRef}>
{/* <LoadingAvatar /> */}
......@@ -32,12 +43,21 @@ const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => {
{/* 加载中 */}
<LoadingText />
{/* 内容 */}
<BasicContent />
<BasicContent
onJsonContentReady={handleJsonContentReady}
/>
</div>
</div>
<More more={more} />
</div>
</div>
{/* 在父组件层级渲染 JSON 内容 */}
{jsonContent && (
<div className={cn(s['report-container'])}>
<Report content={jsonContent} />
</div>
)}
</>
)
}
export default memo(Answer)
......@@ -89,7 +89,7 @@ const TextInput: React.FC<{
s['text-input'],
'body-lg-regular w-full resize-none bg-transparent p-1 leading-6 text-text-tertiary outline-none',
)}
placeholder={t('common.chat.inputPlaceholder') || ''}
placeholder={isResponding ? '正在生成回复...' : t('common.chat.inputPlaceholder') || ''}
autoFocus
maxRows={maxRow}
onResize={handleTextareaResize}
......
'use client'
import { useEffect } from 'react'
import { useStore } from '@/app/components/app/store'
const CONFIG_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsk-ai-data-assistant-config&env=develop'
export function ConfigLoader() {
const setGlobalConfig = useStore(state => state.setGlobalConfig)
useEffect(() => {
async function loadConfig() {
try {
const response = await fetch(CONFIG_URL)
const data = await response.json()
setGlobalConfig(data)
} catch (error) {
console.error('获取配置失败:', error)
}
}
loadConfig()
}, [setGlobalConfig])
return null
}
......@@ -3,6 +3,8 @@ import { useToastContext } from '@/app/components/base/toast'
import { FC, memo, useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context'
import { AI_DATA_CLEAR } from '@/app/components/base/chat/constants'
const ReStart: FC = () => {
const { t } = useTranslation()
const { notify } = useToastContext()
......@@ -37,15 +39,7 @@ const ReStart: FC = () => {
/>
)}
<div className="fixed-button" onClick={handleRestart}>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M3 10.25V15.5H15V10.25M3 10.25H15M3 10.25V6.875H7.5V2.5H10.5V6.875H15V10.25M11.25 15.5V13.25"
stroke="#0A3479"
stroke-width="1.3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<img src={AI_DATA_CLEAR} alt="Clear" title="Clear" className='footer-icon' />
清空
</div>
</>
......
import { FC, memo } from 'react'
import { useMessageContext } from '../../context'
import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context'
import { AI_DATA_SEND, AI_DATA_STOP } from '@/app/components/base/chat/constants'
const Send: FC = () => {
const { handleSend } = useMessageContext()
const { isResponding } = useChatRespondingContext()
const { onStopResponding: stopResponding } = useChatContext()
if (isResponding)
return (
<svg onClick={stopResponding} width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_84_1038)">
<path
d="M1.33337 20C1.33337 11.1634 8.49682 4 17.3334 4C26.1699 4 33.3334 11.1634 33.3334 20C33.3334 28.8366 26.1699 36 17.3334 36C8.49682 36 1.33337 28.8366 1.33337 20Z"
fill="url(#paint0_linear_84_1038)"
/>
<rect x="11.3334" y="14" width="12" height="12" rx="1.6" fill="white" />
</g>
<defs>
<filter
id="filter0_d_84_1038"
x="4.07696e-05"
y="0"
width="40"
height="40"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feOffset dx="2.66667" />
<feGaussianBlur stdDeviation="2" />
<feColorMatrix type="matrix" values="0 0 0 0 0.514423 0 0 0 0 0.741026 0 0 0 0 1 0 0 0 0.4 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_84_1038" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_84_1038" result="shape" />
</filter>
<linearGradient
id="paint0_linear_84_1038"
x1="17.3334"
y1="4"
x2="25.3976"
y2="33.8191"
gradientUnits="userSpaceOnUse">
<stop stop-color="#4F72FF" />
<stop offset="0.5" stop-color="#4EA9FE" />
<stop offset="1" stop-color="#4CE0FC" />
</linearGradient>
</defs>
</svg>
)
if (isResponding) return <img src={AI_DATA_STOP} onClick={stopResponding} alt="Stop" title="Stop" className='send-icon' />
return (
<svg onClick={handleSend} width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_16_201)">
<path
d="M1.33331 20C1.33331 11.1634 8.49676 4 17.3333 4C26.1699 4 33.3333 11.1634 33.3333 20C33.3333 28.8366 26.1699 36 17.3333 36C8.49676 36 1.33331 28.8366 1.33331 20Z"
fill="url(#paint0_linear_16_201)"
/>
<path
d="M16.4153 12.8361C16.7935 12.0796 17.8731 12.0796 18.2514 12.8361L24.2759 24.8851C24.6774 25.6882 23.9271 26.5833 23.0663 26.3283L17.6249 24.716C17.4346 24.6596 17.232 24.6596 17.0417 24.716L11.6004 26.3283C10.7395 26.5833 9.98921 25.6882 10.3907 24.8851L16.4153 12.8361Z"
fill="white"
/>
</g>
<defs>
<filter
id="filter0_d_16_201"
x="-2.02656e-05"
y="0"
width="40"
height="40"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feOffset dx="2.66667" />
<feGaussianBlur stdDeviation="2" />
<feColorMatrix type="matrix" values="0 0 0 0 0.514423 0 0 0 0 0.741026 0 0 0 0 1 0 0 0 0.4 0" />
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_16_201" />
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_16_201" result="shape" />
</filter>
<linearGradient
id="paint0_linear_16_201"
x1="17.3333"
y1="4"
x2="25.3975"
y2="33.8191"
gradientUnits="userSpaceOnUse">
<stop stop-color="#4F72FF" />
<stop offset="0.5" stop-color="#4EA9FE" />
<stop offset="1" stop-color="#4CE0FC" />
</linearGradient>
</defs>
</svg>
)
return <img src={AI_DATA_SEND} onClick={handleSend} alt="Send" title="Send" className='send-icon' />
}
export default memo(Send)
import { FC, memo } from 'react'
const ReStart: FC = () => {
import { useStore } from '@/app/components/app/store'
import { AI_DATA_SETTING ,GET_PARAMS} from '@/app/components/base/chat/constants'
const Setting: FC = () => {
const handleSettingClick = () => {
const sessionId = GET_PARAMS.get('sessionId')
const { globalConfig } = useStore.getState()
if (!globalConfig) {
console.warn('全局配置尚未加载')
return
}
const { settingUrl } = globalConfig
if (settingUrl) {
window.open(`${settingUrl}?sessionId=${sessionId}`)
} else {
console.warn('配置中未设置 settingUrl')
}
}
return (
<>
<div className="fixed-button">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M16.1173 8.32712C16.2354 8.5317 16.2976 8.76377 16.2976 9C16.2976 9.23623 16.2354 9.4683 16.1173 9.67288L13.1412 14.8271C13.0231 15.0317 12.8532 15.2016 12.6486 15.3197C12.444 15.4378 12.212 15.5 11.9757 15.5L6.02414 15.5C5.78792 15.5 5.55586 15.4378 5.35128 15.3197C5.14671 15.2016 4.97683 15.0317 4.85872 14.8271L1.88258 9.67288C1.76446 9.4683 1.70228 9.23623 1.70228 9C1.70228 8.76377 1.76446 8.5317 1.88258 8.32712L4.85872 3.17288C4.97683 2.9683 5.14671 2.79842 5.35128 2.68031C5.55586 2.56219 5.78792 2.50001 6.02414 2.5L11.9757 2.5C12.212 2.50001 12.444 2.56219 12.6486 2.68031C12.8532 2.79842 13.0231 2.9683 13.1412 3.17288L16.1173 8.32712ZM14.9519 9L11.9757 3.84576L6.02414 3.84576L3.048 9L6.02414 14.1542L11.9757 14.1542L14.9519 9ZM11.6915 9C11.6915 9.71383 11.4079 10.3984 10.9031 10.9032C10.3984 11.4079 9.71378 11.6915 8.99994 11.6915C8.28611 11.6915 7.60151 11.4079 7.09676 10.9032C6.592 10.3984 6.30843 9.71383 6.30843 9C6.30843 8.28617 6.592 7.60157 7.09676 7.09681C7.60151 6.59206 8.28611 6.30849 8.99994 6.30849C9.71378 6.30849 10.3984 6.59206 10.9031 7.09681C11.4079 7.60157 11.6915 8.28617 11.6915 9ZM10.3457 9C10.3457 8.82327 10.3109 8.64828 10.2433 8.485C10.1756 8.32173 10.0765 8.17337 9.95154 8.04841C9.82657 7.92344 9.67822 7.82431 9.51494 7.75668C9.35167 7.68905 9.17667 7.65424 8.99994 7.65424C8.82322 7.65424 8.64822 7.68905 8.48495 7.75668C8.32167 7.82431 8.17331 7.92344 8.04835 8.04841C7.92339 8.17337 7.82426 8.32173 7.75663 8.485C7.689 8.64828 7.65419 8.82327 7.65419 9C7.65419 9.35692 7.79597 9.69922 8.04835 9.95159C8.30073 10.204 8.64303 10.3458 8.99994 10.3458C9.35686 10.3458 9.69916 10.204 9.95154 9.95159C10.2039 9.69922 10.3457 9.35692 10.3457 9Z"
fill="#0A3479"
/>
</svg>
<div className="fixed-button" onClick={handleSettingClick}>
<img src={AI_DATA_SETTING} alt="Setting" title="Setting" className='footer-icon' />
设置
</div>
</>
)
}
export default memo(ReStart)
export default memo(Setting)
......@@ -5,6 +5,7 @@ import StopResponding from './components/stopResponding'
import cn from '@/utils/classnames'
import ReStart from './components/operation/restart'
import Setting from './components/operation/setting'
import { ConfigLoader } from './components/operation/config-loader'
import s from './index.module.scss'
type FooterProps = {
......@@ -16,6 +17,8 @@ type FooterProps = {
const Footer: FC<FooterProps> = ({ isMobile, chatFooterRef, chatFooterInnerRef }) => {
return (
<div className={cn('absolute bottom-0 flex justify-center bg-chat-input-mask pb-4 w-full',s['footer-mask'])} ref={chatFooterRef}>
{/* 配置加载器 */}
<ConfigLoader />
<div
ref={chatFooterInnerRef}
className={cn('relative', `mx-auto w-full max-w-[800px] ${isMobile ? 'px-2' : 'px-4'}`)}>
......
......@@ -8,7 +8,7 @@
* @FilePath: \ai-assistant\app\components\base\chat\chat\question\init-questions.tsx
*/
import type { FC } from 'react'
import {useMemo } from 'react'
import { useMemo, useState, useCallback } from 'react'
import InitSuggest from './init-suggest'
import cn from '@/utils/classnames'
import { useChatConfigContext } from '../../chat-with-history/context/chat-config-context'
......@@ -17,7 +17,14 @@ import { AI_TIPS } from '@/app/components/base/chat/constants'
const InitQuestions: FC = () => {
const { suggested_questions = [] } = useChatConfigContext()
const [refreshFlag, setRefreshFlag] = useState(0)
if (!suggested_questions.length) return null
const handleRefresh = useCallback(() => {
setRefreshFlag(prev => prev + 1)
}, [])
return useMemo(() => {
const suggestedQuestions = suggested_questions
.filter(q => !!q && q.trim())
......@@ -30,7 +37,7 @@ const InitQuestions: FC = () => {
<div className={cn(s['suggested-questions-list'], 'group w-0 grow')}>
<div className={cn('flex', s['suggested-questions-list-tips'])}>
试试这样提问:
<div className={cn(s['change-btn'], 'flex')}>
<div className={cn(s['change-btn'], 'flex')} onClick={handleRefresh}>
换一批
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
......@@ -58,6 +65,6 @@ const InitQuestions: FC = () => {
</div>
</div>
)
}, [suggested_questions])
}, [suggested_questions, refreshFlag])
}
export default InitQuestions
......@@ -56,5 +56,6 @@
}
&-icon {
flex-shrink: 0;
margin-left: auto;
}
}
\ No newline at end of file
......@@ -24,3 +24,12 @@ export const CLEAR_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai
export const LOADING_ICON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/loading-icon.png?v=1'
export const AI_TIPS = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-tips.png'
export const AI_DATA_SEND = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-send.png'
export const AI_DATA_STOP = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-stop.png'
export const AI_DATA_CLEAR = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-clear.png'
export const AI_DATA_SETTING = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-setting.png'
export const GET_PARAMS = __params
......@@ -77,7 +77,7 @@ export type InputMessageProp = {
export enum InputMessageType {
BY_HAND = '0',
BY_AUTO = '1',
QUESTION_IN_WELCOME = '2',
QUESTION_IN_WELCOME = '1',
BY_PRACTICE = '3',
QUESTION_IN_ANSWER = '4',
BY_SUGGEST = '5',
......
import { FC, useMemo } from 'react'
import { FC } from 'react'
import ReactECharts from 'echarts-for-react'
type ChartProps = {
content: string
content: any | null
}
interface ChartData {
is_chart?: string
chart?: Array<{
type?: string
name?: string[]
data?: number[]
metric?: string
}>
}
const Chart: FC<ChartProps> = ({ content }) => {
const chartData: ChartData | null = useMemo(() => {
try {
const cleanContent = content.replace(/^```json\s*|\s*```$/g, '').trim()
return JSON.parse(cleanContent)
} catch (e) {
console.error('Failed to parse chart JSON:', e)
return null
}
}, [content])
if (!chartData || !chartData.is_chart || !chartData.chart?.[0]) {
const chartData = content
if (!chartData || !chartData.chart?.[0]) {
return null
}
if (chartData.is_chart == 'N') return null
......
......@@ -17,3 +17,4 @@ export { default as MarkdownButton } from './button'
export { default as MarkdownForm } from './form'
export { default as Think } from './think'
export {default as Chart} from './chart'
export {default as Report} from './report'
.report-box {
background: linear-gradient(180deg, #edf5ff 0%, #fff 19.65%, #fff 100%);
border-radius: 16px;
}
.report-type-title {
display: flex;
align-items: center;
gap: 8px;
color: #133368;
font-size: 16px;
font-weight: 500;
padding: 12px 12px 8px;
.block {
line-height: 24px;
height: 24px;
color: #4f72ff;
font-size: 13px;
font-weight: 400;
padding: 0 10px;
border-radius: 32px;
background: rgba(79, 114, 255, 0.1);
}
&:before {
content: '';
border-top: 1px solid #e0e0e0;
width: 6px;
height: 20px;
border-radius: 584px;
background: linear-gradient(165deg, #4f72ff 10.64%, #4ea9fd 50%, #4ce0fc 89.36%);
box-shadow: 2px 0 3px 0 rgba(131, 189, 255, 0.4);
display: block;
}
}
\ No newline at end of file
import { FC, useRef, useEffect, useState } from 'react'
import { useStore } from '@/app/components/app/store'
import dayjs from 'dayjs'
import cn from '@/utils/classnames'
import s from './index.module.scss'
type ReportProps = {
content: any | null
}
const Report: FC<ReportProps> = ({ content }) => {
const { globalConfig } = useStore.getState()
const { report_end_date, report_start_date, report_type } = content
const reportType = report_type == '周报' ? 1 : 2
const iframeRef = useRef<HTMLIFrameElement>(null)
const [iframeHeight, setIframeHeight] = useState(500) // 默认高度
const reportDateText = () => {
if (!report_start_date) return ''
if (reportType === 2) {
// 月报:2026-01-10 转成 2026 年 1 月
return dayjs(report_start_date).format('YYYY年M月')
} else if (reportType === 1) {
// 周报:2026-01-10 转成 2026 年第 2 周
const date = dayjs(report_start_date)
const year = date.year()
// 计算是该年的第几周
const startOfYear = dayjs(`${year}-01-01`)
const weekNumber = Math.ceil((date.diff(startOfYear, 'day') + 1 + startOfYear.day()) / 7)
return `${year}年第${weekNumber}周`
}
return ''
}
if (!globalConfig) {
console.warn('全局配置尚未加载')
return null
}
let { reportUrl } = globalConfig
reportUrl += `?reportStartDate=${report_start_date}&reportEndDate=${report_end_date}&reportType=${reportType}`
const handleIframeLoad = () => {
if (iframeRef.current) {
try {
// 获取 iframe 内部文档的高度
const iframeDoc = iframeRef.current.contentDocument || iframeRef.current.contentWindow?.document
if (iframeDoc?.body) {
const height = Math.max(
iframeDoc.body.scrollHeight,
iframeDoc.body.offsetHeight,
iframeDoc.documentElement.scrollHeight,
iframeDoc.documentElement.offsetHeight,
)
setIframeHeight(height)
}
} catch (error) {
console.warn('无法获取 iframe 高度,可能由于跨域限制:', error)
// 跨域时使用默认高度或估算高度
setIframeHeight(800)
}
}
}
return (
<div className={cn(s['report-box'])}>
{reportUrl && (
<div className={cn(s['report-type-title'])}>
展业{report_type}
<div className={cn(s['block'])}>{reportDateText()}</div>
</div>
)}
{reportUrl ? (
<iframe
ref={iframeRef}
src={reportUrl}
title="报告预览"
width="100%"
height={iframeHeight}
onLoad={handleIframeLoad}
style={{ border: 'none', display: 'block', borderRadius: '16px' }}
/>
) : null}
</div>
)
}
export default Report
......@@ -75,25 +75,20 @@ export const Think = ({ children, ...props }: any) => {
{isComplete ? `${t('common.chat.thought')}\t(${elapsedTime.toFixed(1)}s)` : `${t('common.chat.thinking')}`}
{isComplete ? (
<div className={cn(s['arrow'], 'transition-transform duration-500 group-open:rotate-180')}>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M4.5 7.5L9 12L13.5 7.5"
stroke="#0A3479"
stroke-opacity="0.6"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<img src="https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-data-arrow.png" alt="arrow" />
</div>
) : (
''
)}
</div>
</summary>
<div className="ml-2 border-l border-components-panel-border p-3 text-text-secondary think-class">
{displayContent}
</div>
{displayContent ? (
<div className="ml-2 border-l border-components-panel-border p-3 text-text-secondary think-class">
{displayContent}
</div>
) : (
null
)}
</details>
)
}
......
......@@ -3,9 +3,22 @@
overflow-y: auto;
height: 100%;
}
.streaming_text {
transition: opacity 3s ease, transform 3s ease;
}
.arrow{
.arrow {
margin-left: auto;
width: 18px;
height: 18px;
}
.arrow img {
border: none !important;
}
.report-container {
width: calc(100vw - 52px);
}
\ No newline at end of file
......@@ -8,7 +8,19 @@ import RehypeRaw from 'rehype-raw'
import { flow } from 'lodash-es'
import cn from '@/utils/classnames'
import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils'
import { Audio, Code, Img, Link, MarkdownButton, MarkdownForm, Paragraph, Script, Think, Video, Chart } from './blocks'
import {
Audio,
Code,
Img,
Link,
MarkdownButton,
MarkdownForm,
Paragraph,
Script,
Think,
Video,
Chart,
} from './blocks'
import { useMemo } from 'react'
/**
......@@ -24,85 +36,103 @@ type MarkdownProps = {
className?: string
customDisallowedElements?: string[]
operationClassName?: string
onJsonContentReady?: (jsonContent: any) => React.ReactNode
}
type MarkdownContent = {
mainContent: string
jsonContent?: string
jsonContent?: any
}
export function Markdown(props: MarkdownProps) {
const processedContent = flow([preprocessThinkTag, preprocessLaTeX])(props.content)
const contentObj: MarkdownContent = useMemo(() => {
const jsonCodeBlockRegex = /```json\s*[\s\S]*?```/g
const match = jsonCodeBlockRegex.exec(processedContent)
if (match && match.index !== undefined) {
const mainContent = processedContent.substring(0, match.index)
const jsonContent = processedContent.substring(match.index)
return { mainContent, jsonContent }
// 提取第一个 ```json 块的内容
const jsonBlock = match[0]
// 移除 ```json 和 ``` 标记
const jsonContent = jsonBlock
.replace(/^```json\s*/, '')
.replace(/\s*```$/, '')
.trim()
try {
const parsedJson = JSON.parse(jsonContent)
return { mainContent, jsonContent: parsedJson }
} catch (e) {
console.error('JSON 解析失败:', e)
console.error('原始 JSON 内容:', jsonContent)
// JSON 解析失败时,将整个内容作为 mainContent
return { mainContent: processedContent }
}
}
return { mainContent: processedContent }
}, [processedContent])
const latexContent = contentObj.mainContent
return (
<div className={cn('markdown-body ', '!text-text-primary', props.className)}>
<ReactMarkdown
remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]}
rehypePlugins={[
RehypeKatex,
RehypeRaw as any,
// The Rehype plug-in is used to remove the ref attribute of an element
() => {
return (tree: any) => {
const iterate = (node: any) => {
if (node.type === 'element' && node.properties?.ref) delete node.properties.ref
<>
<div className={cn('markdown-body ', '!text-text-primary', props.className)}>
<ReactMarkdown
remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]}
rehypePlugins={[
RehypeKatex,
RehypeRaw as any,
// The Rehype plug-in is used to remove the ref attribute of an element
() => {
return (tree: any) => {
const iterate = (node: any) => {
if (node.type === 'element' && node.properties?.ref) delete node.properties.ref
if (node.type === 'element' && !/^[a-z][a-z0-9]*$/i.test(node.tagName)) {
node.type = 'text'
node.value = `<${node.tagName}`
}
if (node.type === 'element' && !/^[a-z][a-z0-9]*$/i.test(node.tagName)) {
node.type = 'text'
node.value = `<${node.tagName}`
}
if (node.children) node.children.forEach(iterate)
if (node.children) node.children.forEach(iterate)
}
tree.children.forEach(iterate)
}
tree.children.forEach(iterate)
}
},
]}
urlTransform={customUrlTransform}
disallowedElements={[
'iframe',
'head',
'html',
'meta',
'link',
'style',
'body',
...(props.customDisallowedElements || []),
]}
components={{
code: Code,
img: Img,
video: Video,
audio: Audio,
a: Link,
p: Paragraph,
button: MarkdownButton,
form: MarkdownForm,
script: Script as any,
details: Think,
}}>
{/* Markdown detect has problem. */}
{latexContent}
</ReactMarkdown>
{contentObj.jsonContent && (
<Chart content={contentObj.jsonContent || ''} />
)}
</div>
},
]}
urlTransform={customUrlTransform}
disallowedElements={[
'iframe',
'head',
'html',
'meta',
'link',
'style',
'body',
...(props.customDisallowedElements || []),
]}
components={{
code: Code,
img: Img,
video: Video,
audio: Audio,
a: Link,
p: Paragraph,
button: MarkdownButton,
form: MarkdownForm,
script: Script as any,
details: Think,
}}>
{/* Markdown detect has problem. */}
{latexContent}
</ReactMarkdown>
{contentObj.jsonContent && contentObj.jsonContent.is_chart == 'Y' ? (
<Chart content={contentObj.jsonContent} />
) : null}
</div>
{props.onJsonContentReady && contentObj.jsonContent ? (
<>{props.onJsonContentReady(contentObj.jsonContent)}</>
) : null}
</>
)
}
\ No newline at end of file
}
......@@ -32,7 +32,6 @@ export const viewport: Viewport = {
const LocaleLayout = async ({ children }: { children: React.ReactNode }) => {
const locale = await getLocaleOnServer()
return (
<html lang={locale ?? 'en'} className="h-full" suppressHydrationWarning>
<head>
......@@ -65,14 +64,14 @@ const LocaleLayout = async ({ children }: { children: React.ReactNode }) => {
<BrowserInitor>
<SentryInitor>
{/* <TanstackQueryIniter> */}
<ThemeProvider
attribute="data-theme"
forcedTheme="light"
defaultTheme="light" // TODO: change to 'system' when dark mode ready
enableSystem
disableTransitionOnChange>
<I18nServer>{children}</I18nServer>
</ThemeProvider>
<ThemeProvider
attribute="data-theme"
forcedTheme="light"
defaultTheme="light" // TODO: change to 'system' when dark mode ready
enableSystem
disableTransitionOnChange>
<I18nServer>{children}</I18nServer>
</ThemeProvider>
{/* </TanstackQueryIniter> */}
</SentryInitor>
</BrowserInitor>
......
......@@ -706,7 +706,7 @@ button:focus-within {
background-color: #f5f9ff;
}
.layout-bg::after{
.layout-bg::after {
content: "";
background: url('https://img02.glsx.com.cn/weapp/resource/saas/ai/layout-bg.png');
width: 100vw;
......@@ -736,10 +736,20 @@ button:focus-within {
font-size: 13px;
}
.think-class{
.think-class {
font-size: 13px;
color: #13336899;
}
.m-h-48{
.m-h-48 {
min-height: 48px;
}
.send-icon {
width: 32px;
height: 32px;
}
.footer-icon{
width: 18px;
height: 18px;
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!