Commit b69b06a4 by 李伟康

feat(chat): 移除图表功能并优化聊天界面组件

- 移除聊天组件中的图表显示功能及相关代码
- 重构初始化问题组件的UI样式和布局
- 优化输入框的响应式交互体验
- 调整文本大小和颜色主题配置
- 移除多余的操作按钮和头像组件
- 优化代码结构和组件依赖关系
1 parent 67885416
...@@ -28,5 +28,4 @@ export const ChatConfigProvider = ({ children, config }: Props) => { ...@@ -28,5 +28,4 @@ export const ChatConfigProvider = ({ children, config }: Props) => {
return <ChatConfigContext.Provider value={value}>{children}</ChatConfigContext.Provider> return <ChatConfigContext.Provider value={value}>{children}</ChatConfigContext.Provider>
} }
export const useChatConfigContext = () => useContext(ChatConfigContext) export const useChatConfigContext = () => useContext(ChatConfigContext)
...@@ -453,7 +453,6 @@ export const useChat = (inputs: Inputs = {}) => { ...@@ -453,7 +453,6 @@ export const useChat = (inputs: Inputs = {}) => {
) )
const newResponseItem = data.find((item: any) => item.id === responseItem.id) const newResponseItem = data.find((item: any) => item.id === responseItem.id)
if (!newResponseItem) return if (!newResponseItem) return
updateChatTreeNode(responseItem.id, { updateChatTreeNode(responseItem.id, {
content: newResponseItem.answer, content: newResponseItem.answer,
log: [ log: [
...@@ -638,7 +637,10 @@ export const useChat = (inputs: Inputs = {}) => { ...@@ -638,7 +637,10 @@ export const useChat = (inputs: Inputs = {}) => {
) )
// 计算最终的聊天列表 // 计算最终的聊天列表
const chatList = useMemo(() => getThreadMessages(chatTree, targetMessageId), [chatTree, targetMessageId]) const chatList = useMemo(() => {
const realChatList = getThreadMessages(chatTree, targetMessageId)
return realChatList
}, [chatTree, targetMessageId])
// 更新 refs 中的聊天列表 // 更新 refs 中的聊天列表
useEffect(() => { useEffect(() => {
......
...@@ -3,15 +3,10 @@ import { memo } from 'react' ...@@ -3,15 +3,10 @@ import { memo } from 'react'
import { Markdown } from '@/app/components/base/markdown' import { Markdown } from '@/app/components/base/markdown'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useChatBodyContext } from '../../body/context' import { useChatBodyContext } from '../../body/context'
import ChartContent from './chart'
const BasicContent: FC = () => { const BasicContent: FC = () => {
const { annotation, content, isError, hasAgentThoughts, chart } = useChatBodyContext() const { annotation, content, isError, hasAgentThoughts } = useChatBodyContext()
// 优先显示图表
if (chart?.data && chart.data.length > 0) {
return <ChartContent />
}
if(!content.trim() || hasAgentThoughts) return null if(!content.trim() || hasAgentThoughts) return null
......
import type { FC } from 'react'
import { memo } from 'react'
import { useChatBodyContext } from '../../../body/context'
import PieChart from './pie-chart'
import LineChart from './line-chart'
// import BarChart from './bar-chart'
const ChartContent: FC = () => {
const { chart, content } = useChatBodyContext()
if (!chart?.data || !chart.data.length) {
// 如果没有图表数据,但可能有文本内容
return null
}
const renderChart = () => {
switch (chart.type) {
case 'pie':
return <PieChart data={chart.data} config={chart.config} />
case 'line':
return <LineChart data={chart.data} config={chart.config} />
// case 'bar':
// return <BarChart data={chart.data} config={chart.config} />
default:
return <div className="text-text-tertiary">暂不支持的图表类型:{chart.type}</div>
}
}
return (
<div className="space-y-3">
{/* 图表标题 */}
{chart.config?.title && (
<h3 className="body-lg-semibold text-text-primary">{chart.config.title}</h3>
)}
{/* 图表主体 */}
<div className="w-full min-h-[300px] p-4 bg-state-base-bg rounded-xl">
{renderChart()}
</div>
{/* 如果有文本内容,显示在图表下方 */}
{content && (
<div className="pt-2 border-t border-divider-subtle">
<div className="body-md-regular text-text-secondary">{content}</div>
</div>
)}
</div>
)
}
export default memo(ChartContent)
\ No newline at end of file \ No newline at end of file
import type { FC } from 'react'
import { useMemo } from 'react'
import type { ChartDataItem, ChartConfig } from '@/app/components/base/chat/chat/type'
interface LineChartProps {
data: ChartDataItem[]
config?: ChartConfig
}
const LineChart: FC<LineChartProps> = ({ data, config }) => {
const values = useMemo(() =>
data.map(item => Number(item.value) || 0)
, [data])
const maxValue = Math.max(...values, 1)
const minValue = Math.min(...values, 0)
const range = maxValue - minValue || 1
const width = 100
const height = 60
const padding = 5
const points = useMemo(() =>
data.map((item, index) => {
const x = padding + (index / (data.length - 1 || 1)) * (width - 2 * padding)
const y = height - padding - ((values[index] - minValue) / range) * (height - 2 * padding)
return `${x},${y}`
}).join(' ')
, [data, values, minValue, range, width, height, padding])
return (
<div className="w-full">
<svg viewBox={`0 0 ${width} ${height}`} className="w-full h-48">
{/* 网格线 */}
{config?.showGrid !== false && (
<>
{[0, 0.25, 0.5, 0.75, 1].map(ratio => (
<line
key={ratio}
x1={padding}
y1={padding + ratio * (height - 2 * padding)}
x2={width - padding}
y2={padding + ratio * (height - 2 * padding)}
stroke="#E5E7EB"
strokeWidth="0.5"
/>
))}
</>
)}
{/* 折线 */}
<polyline
points={points}
fill="none"
stroke="#3B82F6"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
{/* 数据点 */}
{data.map((item, index) => {
const x = padding + (index / (data.length - 1 || 1)) * (width - 2 * padding)
const y = height - padding - ((values[index] - minValue) / range) * (height - 2 * padding)
return (
<circle
key={index}
cx={x}
cy={y}
r="2"
fill="#3B82F6"
stroke="#fff"
strokeWidth="0.5"
/>
)
})}
</svg>
{/* X 轴标签 */}
{config?.showLegend !== false && (
<div className="flex justify-between mt-2 px-2">
{data.map((item, index) => (
<span key={index} className="text-xs text-text-tertiary truncate max-w-[80px]">
{item.name}
</span>
))}
</div>
)}
</div>
)
}
export default LineChart
\ No newline at end of file \ No newline at end of file
import type { FC } from 'react'
import { useMemo } from 'react'
import type { ChartDataItem, ChartConfig } from '@/app/components/base/chat/chat/type'
interface PieChartProps {
data: ChartDataItem[]
config?: ChartConfig
}
const PieChart: FC<PieChartProps> = ({ data, config }) => {
const colors = useMemo(() => [
'#36A2EB', '#FF6384', '#FFCE56', '#4BC0C0',
'#9966FF', '#FF9F40', '#C9CBCF', '#7BC225'
], [])
const total = useMemo(() =>
data.reduce((sum, item) => sum + (Number(item.value) || 0), 0)
, [data])
let cumulativePercent = 0
const getCoordinatesForPercent = (percent: number) => {
const x = Math.cos(2 * Math.PI * percent)
const y = Math.sin(2 * Math.PI * percent)
return [x, y]
}
const slices = useMemo(() => data.map((item, index) => {
const value = Number(item.value) || 0
const percent = value / total
const startPercent = cumulativePercent
cumulativePercent += percent
const [startX, startY] = getCoordinatesForPercent(startPercent)
const [endX, endY] = getCoordinatesForPercent(cumulativePercent)
const largeArcFlag = percent > 0.5 ? 1 : 0
const pathData = [
`M ${startX} ${startY}`,
`A 1 1 0 ${largeArcFlag} 1 ${endX} ${endY}`,
`L 0 0`,
].join(' ')
return {
pathData,
color: item.color || colors[index % colors.length],
name: item.name,
value: item.value,
percent: (percent * 100).toFixed(1)
}
}), [data, total, colors])
return (
<div className="flex items-center gap-6">
{/* SVG 饼图 */}
<svg viewBox="-1.2 -1.2 2.4 2.4" className="w-48 h-48 shrink-0">
{slices.map((slice, index) => (
<path
key={index}
d={slice.pathData}
fill={slice.color}
className="transition-opacity hover:opacity-80 cursor-pointer"
/>
))}
</svg>
{/* 图例 */}
{config?.showLegend !== false && (
<div className="flex flex-col gap-2 min-w-0">
{slices.map((slice, index) => (
<div key={index} className="flex items-center gap-2 text-sm">
<div
className="w-3 h-3 rounded-sm shrink-0"
style={{ backgroundColor: slice.color }}
/>
<span className="truncate">{slice.name}</span>
<span className="text-text-tertiary ml-auto">
{slice.value} ({slice.percent}%)
</span>
</div>
))}
</div>
)}
</div>
)
}
export default PieChart
\ No newline at end of file \ No newline at end of file
...@@ -3,7 +3,7 @@ import { memo } from 'react' ...@@ -3,7 +3,7 @@ import { memo } from 'react'
import { useChatBodyContext } from '../../body/context' import { useChatBodyContext } from '../../body/context'
import LoadingIcon from './loading-icon' import LoadingIcon from './loading-icon'
const LoadingText: FC = () => { const LoadingText: FC = () => {
const { responding,content ,hasAgentThoughts } = useChatBodyContext() const { responding ,content ,hasAgentThoughts } = useChatBodyContext()
if (!responding || content.trim()|| hasAgentThoughts) return null if (!responding || content.trim()|| hasAgentThoughts) return null
return ( return (
<div className="flex h-5 items-center justify-center think-class"> <div className="flex h-5 items-center justify-center think-class">
......
import type { FC, ReactNode } from 'react' import type { FC, ReactNode } from 'react'
import { memo, useEffect, useRef, useState } from 'react' import { memo, useEffect, useRef, useState } from 'react'
import Operation from './components/operation' // import Operation from './components/operation'
import BasicContent from './components/basic-content' import BasicContent from './components/basic-content'
import More from './components/more' import More from './components/more'
// import WorkflowProcessItem from "./workflow-process"; // import WorkflowProcessItem from "./workflow-process";
// import { EditTitle } from "@/app/components/app/annotation/edit-annotation-modal/edit-item"; // import { EditTitle } from "@/app/components/app/annotation/edit-annotation-modal/edit-item";
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import LoadingAvatar from './components/loading-avatar'
import LoadingText from './components/loading-text' import LoadingText from './components/loading-text'
import AnswerIcon from '@/app/components/base/answer-icon'
import { useChatBodyContext } from '../body/context' import { useChatBodyContext } from '../body/context'
import s from './index.module.scss' import s from './index.module.scss'
...@@ -16,7 +14,7 @@ type AnswerProps = { ...@@ -16,7 +14,7 @@ type AnswerProps = {
chatAnswerContainerInner?: string chatAnswerContainerInner?: string
} }
const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => { const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => {
const { containerRef, contentRef, workflowProcess, more, isAnswer } = useChatBodyContext() const { containerRef, contentRef, more, isAnswer } = useChatBodyContext()
if (!isAnswer) return null if (!isAnswer) return null
return ( return (
<div className="mb-2 flex last:mb-0"> <div className="mb-2 flex last:mb-0">
...@@ -30,7 +28,7 @@ const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => { ...@@ -30,7 +28,7 @@ const Answer: FC<AnswerProps> = ({ chatAnswerContainerInner }) => {
s['chat-answer-container-inner'] s['chat-answer-container-inner']
)}> )}>
{/* 工具 */} {/* 工具 */}
<Operation /> {/* <Operation /> */}
{/* 加载中 */} {/* 加载中 */}
<LoadingText /> <LoadingText />
{/* 内容 */} {/* 内容 */}
......
...@@ -12,7 +12,6 @@ interface ChatBodyContextType { ...@@ -12,7 +12,6 @@ interface ChatBodyContextType {
allFiles: ChatItem['allFiles'] allFiles: ChatItem['allFiles']
message_files: ChatItem['message_files'] message_files: ChatItem['message_files']
content: ChatItem['content'] content: ChatItem['content']
chart: ChatItem['chart']
index?: number index?: number
question?: string question?: string
isLast?: boolean isLast?: boolean
...@@ -69,7 +68,6 @@ export const ChatBodyProvider: React.FC<ChatBodyProviderProps> = ({ ...@@ -69,7 +68,6 @@ export const ChatBodyProvider: React.FC<ChatBodyProviderProps> = ({
id, id,
isOpeningStatement, isOpeningStatement,
content, content,
chart,
citation, citation,
agent_thoughts, agent_thoughts,
isAnswer, isAnswer,
...@@ -117,10 +115,9 @@ export const ChatBodyProvider: React.FC<ChatBodyProviderProps> = ({ ...@@ -117,10 +115,9 @@ export const ChatBodyProvider: React.FC<ChatBodyProviderProps> = ({
theme, theme,
isAnswer, isAnswer,
content, content,
chart,
parentMessageId, parentMessageId,
}), }),
[content, chart, isAnswer, isLast, isError, responding], [content, isAnswer, isLast, isError, responding],
) )
return <ChatBodyContext.Provider value={value}>{children}</ChatBodyContext.Provider> return <ChatBodyContext.Provider value={value}>{children}</ChatBodyContext.Provider>
......
...@@ -6,9 +6,7 @@ const MultipleLineOperation: FC = () => { ...@@ -6,9 +6,7 @@ const MultipleLineOperation: FC = () => {
return ( return (
<> <>
{isMultipleLine && ( {isMultipleLine && (
<div className="px-[9px]">
<Opration /> <Opration />
</div>
)} )}
</> </>
) )
......
...@@ -5,10 +5,12 @@ import { useTranslation } from 'react-i18next' ...@@ -5,10 +5,12 @@ import { useTranslation } from 'react-i18next'
import { useFileOperation } from '../../hooks' import { useFileOperation } from '../../hooks'
import { useMessageContext, useTextAreaHeightContext } from '@/app/components/base/chat/chat/footer/context' import { useMessageContext, useTextAreaHeightContext } from '@/app/components/base/chat/chat/footer/context'
import s from './wrapper.module.scss' import s from './wrapper.module.scss'
import { useChatRespondingContext } from '@/app/components/base/chat/chat-with-history/context'
const TextInput: React.FC<{ const TextInput: React.FC<{
children: React.ReactNode children: React.ReactNode
}> = React.memo(({ children }) => { }> = React.memo(({ children }) => {
const { isResponding } = useChatRespondingContext()
const { t } = useTranslation() const { t } = useTranslation()
const { query, setQuery, handleSend } = useMessageContext() const { query, setQuery, handleSend } = useMessageContext()
const historyRef = useRef(['']) const historyRef = useRef([''])
...@@ -74,7 +76,7 @@ const TextInput: React.FC<{ ...@@ -74,7 +76,7 @@ const TextInput: React.FC<{
}, [hasQuery]) }, [hasQuery])
return ( return (
// <div ref={wrapperRef} className="flex items-center justify-between"> // <div ref={wrapperRef} className="flex items-center justify-between">
<div ref={wrapperRef} className="flex items-center justify-between h-full"> <div ref={wrapperRef} className="flex items-center justify-between h-full m-h-48">
<div className="relative flex w-full grow items-center h-full"> <div className="relative flex w-full grow items-center h-full">
<div <div
ref={textValueRef} ref={textValueRef}
...@@ -101,6 +103,8 @@ const TextInput: React.FC<{ ...@@ -101,6 +103,8 @@ const TextInput: React.FC<{
onDragLeave={handleDragFileLeave} onDragLeave={handleDragFileLeave}
onDragOver={handleDragFileOver} onDragOver={handleDragFileOver}
onDrop={handleDropFile} onDrop={handleDropFile}
maxLength={1000}
disabled={isResponding}
/> />
</div> </div>
{!isMultipleLine && children} {!isMultipleLine && children}
......
.input-wrapper{ .input-wrapper{
height: 48px; min-height: 48px;
border-radius: 29px; border-radius: 29px;
background-color: #fff; background-color: #fff;
padding: 0 8px 0 16px; padding: 0 8px 0 16px;
......
import { FC, memo } from 'react' import { FC, memo } from 'react'
import { SEND_BUTTON } from '@/app/components/base/chat/constants'
import { useMessageContext } from '../../context' import { useMessageContext } from '../../context'
import { useChatRespondingContext, useChatContext } from '@/app/components/base/chat/chat-with-history/context'
const Send: FC = () => { const Send: FC = () => {
const { handleSend } = useMessageContext() const { handleSend } = useMessageContext()
return <svg onClick={handleSend} width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"> 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>
)
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)"> <g filter="url(#filter0_d_16_201)">
<path <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" 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"
...@@ -49,6 +99,6 @@ const Send: FC = () => { ...@@ -49,6 +99,6 @@ const Send: FC = () => {
</linearGradient> </linearGradient>
</defs> </defs>
</svg> </svg>
)
} }
export default memo(Send) export default memo(Send)
...@@ -23,7 +23,7 @@ const Footer: FC<FooterProps> = ({ isMobile, chatFooterRef, chatFooterInnerRef } ...@@ -23,7 +23,7 @@ const Footer: FC<FooterProps> = ({ isMobile, chatFooterRef, chatFooterInnerRef }
<ReStart /> <ReStart />
<Setting /> <Setting />
{/* {isShowPracticeButton && <Practice />} */} {/* {isShowPracticeButton && <Practice />} */}
{<StopResponding />} {/* {<StopResponding />} */}
</div> </div>
{/* {!!suggestedQuestions?.length && <TryToAsk suggestedQuestions={suggestedQuestions} isMobile={isMobile} />} */} {/* {!!suggestedQuestions?.length && <TryToAsk suggestedQuestions={suggestedQuestions} isMobile={isMobile} />} */}
{<ChatInput />} {<ChatInput />}
......
...@@ -8,38 +8,56 @@ ...@@ -8,38 +8,56 @@
* @FilePath: \ai-assistant\app\components\base\chat\chat\question\init-questions.tsx * @FilePath: \ai-assistant\app\components\base\chat\chat\question\init-questions.tsx
*/ */
import type { FC } from 'react' import type { FC } from 'react'
import { memo, useMemo, useEffect } from 'react' import {useMemo } from 'react'
import InitSuggest from './init-suggest' import InitSuggest from './init-suggest'
import AnswerIcon from '@/app/components/base/answer-icon'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { Markdown } from '@/app/components/base/markdown'
import { useChatConfigContext } from '../../chat-with-history/context/chat-config-context' import { useChatConfigContext } from '../../chat-with-history/context/chat-config-context'
import s from './question.module.scss'
import { AI_TIPS } from '@/app/components/base/chat/constants'
const InitQuestions: FC = () => { const InitQuestions: FC = () => {
console.log('InitQuestions') const { suggested_questions = [] } = useChatConfigContext()
const { suggested_questions = [], initial_message } = useChatConfigContext() if (!suggested_questions.length) return null
if (!initial_message && !suggested_questions.length) return null
return useMemo(() => { return useMemo(() => {
const suggestedQuestions = suggested_questions const suggestedQuestions = suggested_questions
.filter(q => !!q && q.trim()) .filter(q => !!q && q.trim())
.sort(() => Math.random() - 0.5) .sort(() => Math.random() - 0.5)
.slice(0, 3) .slice(0, 4)
return ( return (
<div className="mb-2 flex last:mb-0"> <div className={cn('mb-2 flex last:mb-0', s['suggested-questions-box'])}>
{/* <div className="relative h-10 w-10 shrink-0">{<AnswerIcon />}</div> */} {/* <div className="relative h-10 w-10 shrink-0">{<AnswerIcon />}</div> */}
<div className="chat-answer-container group ml-2 w-0 grow pb-2"> <img src={AI_TIPS} alt="AI Tips" className={cn(s['suggested-questions-title'])} />
<div className={cn('group relative pr-14')}> <div className={cn(s['suggested-questions-list'], 'group w-0 grow')}>
<div <div className={cn('flex', s['suggested-questions-list-tips'])}>
className={cn( 试试这样提问:
'body-lg-regular relative inline-block max-w-full rounded-2xl rounded-bl-none bg-chat-bubble-bg px-3 py-3 text-text-primary w-full', <div className={cn(s['change-btn'], 'flex')}>
)}> 换一批
{initial_message && <Markdown content={initial_message} />} <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
{suggestedQuestions.length > 0 && <InitSuggest suggestedQuestions={suggestedQuestions} />} <path
d="M3.70325 10.2555C4.17728 11.21 4.93959 11.9847 5.8782 12.4658C6.8168 12.9469 7.8822 13.1089 8.91799 12.9281C9.95377 12.7472 10.9052 12.2331 11.6327 11.4612C12.3602 10.6893 12.8252 9.70034 12.9597 8.6395C13.0941 7.57866 12.8907 6.50192 12.3794 5.56743C11.8682 4.63294 11.0759 3.88995 10.1192 3.4476C9.16232 3.00525 8.09137 2.88685 7.06359 3.1098C6.03579 3.33274 5.19347 3.83963 4.497 4.6406C4.41267 4.72955 4.08848 5.08852 3.81898 5.63019"
stroke="#0A3479"
stroke-opacity="0.6"
stroke-width="1.2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M6.29515 5.67386L3.49499 6.17762L3 3.32748"
stroke="#0A3479"
stroke-opacity="0.6"
stroke-width="1.2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div> </div>
</div> </div>
<div className={cn('group relative w-full')}>
{suggestedQuestions.length > 0 && <InitSuggest suggestedQuestions={suggestedQuestions} />}
</div>
</div> </div>
</div> </div>
) )
}, [initial_message]) }, [suggested_questions])
} }
export default InitQuestions export default InitQuestions
...@@ -12,18 +12,28 @@ import { memo } from 'react' ...@@ -12,18 +12,28 @@ import { memo } from 'react'
import { useChatContext } from '@/app/components/base/chat/chat-with-history/context/chat-context' import { useChatContext } from '@/app/components/base/chat/chat-with-history/context/chat-context'
import Button from '@/app/components/base/button/next-button' import Button from '@/app/components/base/button/next-button'
import { InputMessageType } from '@/app/components/base/chat/types' import { InputMessageType } from '@/app/components/base/chat/types'
import cn from '@/utils/classnames'
import s from './question.module.scss'
type InitSuggestProps = { type InitSuggestProps = {
suggestedQuestions?: string[] suggestedQuestions?: string[]
} }
const InitSuggest: FC<InitSuggestProps> = ({ suggestedQuestions = [] }) => { const InitSuggest: FC<InitSuggestProps> = ({ suggestedQuestions = [] }) => {
const { onSend } = useChatContext() const { onSend } = useChatContext()
return ( return (
<div className="w-[fit-content]"> <div className={cn('w-full', s['suggested-questions-item-box'])}>
{suggestedQuestions.map((question, index) => ( {suggestedQuestions.map((question, index) => (
<Button <div
className={cn(s['suggested-questions-item'],'flex items-center')}
key={index} key={index}
text={question} onClick={() => onSend?.(question, InputMessageType.QUESTION_IN_WELCOME)}>
onClick={() => onSend?.(question, InputMessageType.QUESTION_IN_WELCOME)}></Button> <div className={cn(s['suggested-questions-item-text'])}>{question}</div>
<svg className={cn(s['suggested-questions-item-icon'])} width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M12.7895 8.7334L10.3872 5.68652C10.3434 5.6309 10.2876 5.58593 10.2239 5.55497C10.1602 5.52402 10.0903 5.5079 10.0195 5.50781H9.07031C8.97217 5.50781 8.91797 5.62061 8.97803 5.69824L11.0918 8.37891H2.22656C2.16211 8.37891 2.10938 8.43164 2.10938 8.49609V9.375C2.10938 9.43945 2.16211 9.49219 2.22656 9.49219H12.4204C12.813 9.49219 13.0312 9.04102 12.7895 8.7334Z"
fill="#0A3479"
/>
</svg>
</div>
))} ))}
</div> </div>
) )
......
.question-boder{ .question-boder {
border-radius: 16px 16px 4px 16px; border-radius: 16px 16px 4px 16px;
background: linear-gradient(268.67deg, #4F72FF 1.13%, #4EA9FE 98.87%); background: linear-gradient(268.67deg, #4F72FF 1.13%, #4EA9FE 98.87%);
box-shadow: 2.67px 0px 4px 0px #83BDFF66; box-shadow: 2.67px 0px 4px 0px #83BDFF66;
}
.suggested-questions-box {
border-radius: 16px;
overflow: hidden;
flex-direction: column;
}
.suggested-questions-title {
height: 90px;
display: flex;
align-items: center;
}
.suggested-questions-list {
width: 100%;
border-radius: 16px;
margin-top: -38px;
background-color: #fff;
padding: 0 16px;
&-tips {
padding: 16px 0;
color: rgba(10, 52, 121, 0.60);
font-size: 13px;
font-weight: 400;
.change-btn {
margin-left: auto;
gap: 4px;
align-items: center;
}
}
}
.suggested-questions-item {
border-top: 1px solid #d8e6f066;
padding: 16px 0;
max-height: 75px;
box-sizing: border-box;
&-text {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-word;
}
&-icon {
flex-shrink: 0;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -12,8 +12,6 @@ import { memo, useMemo } from 'react' ...@@ -12,8 +12,6 @@ import { memo, useMemo } from 'react'
import { CssTransform } from '@/app/components/base/chat/embedded-chatbot/theme/utils' import { CssTransform } from '@/app/components/base/chat/embedded-chatbot/theme/utils'
import { Markdown } from '@/app/components/base/markdown' import { Markdown } from '@/app/components/base/markdown'
import { useChatBodyContext } from '@/app/components/base/chat/chat/body/context' import { useChatBodyContext } from '@/app/components/base/chat/chat/body/context'
import { AVATAR_USER_URL } from '@/app/components/base/chat/constants'
import AnswerIcon from '@/app/components/base/answer-icon'
import s from './question.module.scss' import s from './question.module.scss'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
const Question: FC = () => { const Question: FC = () => {
...@@ -29,9 +27,6 @@ const Question: FC = () => { ...@@ -29,9 +27,6 @@ const Question: FC = () => {
</div> </div>
<div className="mt-1 h-[8px]" /> <div className="mt-1 h-[8px]" />
</div> </div>
{/* <div className="h-10 w-10 shrink-0">
<AnswerIcon imageUrl={AVATAR_USER_URL} />
</div> */}
</div> </div>
) )
} }
......
...@@ -22,3 +22,5 @@ export const SEND_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai- ...@@ -22,3 +22,5 @@ export const SEND_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-
export const CLEAR_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-clear.png' export const CLEAR_BUTTON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/ai-clear.png'
export const LOADING_ICON = 'https://img02.glsx.com.cn/weapp/resource/saas/ai/loading-icon.png?v=1' 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'
import { FC, useMemo } from 'react'
import ReactECharts from 'echarts-for-react'
type ChartProps = {
content: string
}
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]) {
return null
}
if (chartData.is_chart == 'N') return null
let [data_1, data_2] = chartData.chart
let { type, metric } = data_1
let option: any = {}
let title = ''
let legendData = [metric]
if(data_2) legendData = [metric, data_2.metric]
if (type == 'bar' || type == 'line') {
option = {
grid: {
left: '20%',
right: '5%',
top: '10%',
bottom: '30%',
},
legend: {
data: legendData,
bottom: '0%',
itemWidth: 12,
itemHeight: 8,
textStyle: {
fontSize: 12,
color: '#133368',
},
},
xAxis: {
type: 'category',
boundaryGap:type == 'bar',
data: data_1.name,
splitLine: {
show: true,
lineStyle: {
color: '#E5E7EB',
type: 'dashed',
},
},
},
yAxis: {
type: 'value',
axisLabel: {
formatter: (value: number) => {
if (value >= 10000) {
return `${(value / 10000).toFixed(2)}w`
}
return value.toString()
},
},
splitLine: {
show: true,
lineStyle: {
color: '#E5E7EB',
type: 'dashed',
},
},
},
series: [
{
name: metric,
data: data_1.data || [],
type,
barMaxWidth: 20,
lineStyle: {
color: '#2C66F7',
width: 2,
},
itemStyle: {
color: '#2C66F7',
borderWidth: 2,
borderColor: '#fff',
},
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(44, 102, 247, 0.3)' },
{ offset: 1, color: 'rgba(44, 102, 247, 0)' },
],
},
},
},
],
}
if (data_2)
option.series = [
...option.series,
{
name: data_2.metric,
data: data_2.data || [],
type,
barMaxWidth: 20,
lineStyle: {
color: '#FF8D1A',
width: 2,
},
itemStyle: {
color: '#FF8D1A',
borderWidth: 2,
borderColor: '#fff',
},
areaStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(255, 141, 26, 0.2)' },
{ offset: 1, color: 'rgba(255, 141, 26, 0)' },
],
},
},
},
] as any
title = type == 'bar' ? '柱状图' : '折线图'
}
if (type == 'pie') {
option = {
color: ['#2A82E4', '#00BAAD', '#43CF7C', '#A5D63F', '#FF8D1A', '#FFC300', '#7948EA', '#C6C6C6'],
legend: {
left: '50%',
top: 'center',
orient: 'vertical',
itemWidth: 8,
itemHeight: 8,
textStyle: {
fontSize: 12,
color: '#133368',
},
itemGap: 8,
},
series: [
{
type: 'pie',
radius: ['30%', '50%'],
center: ['20%', '50%'],
padAngle: 5,
label: {
show: false,
position: 'center',
},
labelLine: {
show: false,
},
data: (() => {
const dataArray = data_1.data || []
const nameArray = data_1.name || []
if (dataArray.length <= 7) {
return dataArray.map((item, index) => ({ value: item, name: nameArray[index] }))
}
const top7 = dataArray.slice(0, 7).map((item, index) => ({
value: item,
name: nameArray[index],
}))
const otherSum = dataArray.slice(7).reduce((sum, val) => sum + val, 0)
return [...top7, { value: otherSum, name: '其他' }]
})(),
},
],
}
title = '饼壮图'
}
if (!title) return null
return (
<div className="chart-container">
<div className="chart-title">{title}</div>
<ReactECharts option={option} style={{ height: 240 }} />
</div>
)
}
export default Chart
...@@ -16,3 +16,4 @@ export { default as Video } from './video' ...@@ -16,3 +16,4 @@ export { default as Video } from './video'
export { default as MarkdownButton } from './button' export { default as MarkdownButton } from './button'
export { default as MarkdownForm } from './form' export { default as MarkdownForm } from './form'
export { default as Think } from './think' export { default as Think } from './think'
export {default as Chart} from './chart'
...@@ -8,7 +8,7 @@ import RehypeRaw from 'rehype-raw' ...@@ -8,7 +8,7 @@ import RehypeRaw from 'rehype-raw'
import { flow } from 'lodash-es' import { flow } from 'lodash-es'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils' import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils'
import { Audio, Code, Img, Link, MarkdownButton, MarkdownForm, Paragraph, Script, Think, Video } from './blocks' import { Audio, Code, Img, Link, MarkdownButton, MarkdownForm, Paragraph, Script, Think, Video, Chart } from './blocks'
import { useMemo } from 'react' import { useMemo } from 'react'
/** /**
...@@ -25,10 +25,32 @@ type MarkdownProps = { ...@@ -25,10 +25,32 @@ type MarkdownProps = {
customDisallowedElements?: string[] customDisallowedElements?: string[]
operationClassName?: string operationClassName?: string
} }
type MarkdownContent = {
mainContent: string
jsonContent?: string
}
export function Markdown(props: MarkdownProps) { export function Markdown(props: MarkdownProps) {
const latexContent = flow([preprocessThinkTag, preprocessLaTeX])(props.content) 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 }
}
return { mainContent: processedContent }
}, [processedContent])
const latexContent = contentObj.mainContent
return ( return (
<div className={cn('markdown-body', '!text-text-primary', props.className)}> <div className={cn('markdown-body ', '!text-text-primary', props.className)}>
<ReactMarkdown <ReactMarkdown
remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]} remarkPlugins={[RemarkGfm, [RemarkMath, { singleDollarTextMath: false }], RemarkBreaks]}
rehypePlugins={[ rehypePlugins={[
...@@ -77,6 +99,10 @@ export function Markdown(props: MarkdownProps) { ...@@ -77,6 +99,10 @@ export function Markdown(props: MarkdownProps) {
{/* Markdown detect has problem. */} {/* Markdown detect has problem. */}
{latexContent} {latexContent}
</ReactMarkdown> </ReactMarkdown>
{contentObj.jsonContent && (
<Chart content={contentObj.jsonContent || ''} />
)}
</div> </div>
) )
} }
\ No newline at end of file \ No newline at end of file
...@@ -739,4 +739,7 @@ button:focus-within { ...@@ -739,4 +739,7 @@ button:focus-within {
.think-class{ .think-class{
font-size: 13px; font-size: 13px;
color: #13336899; color: #13336899;
}
.m-h-48{
min-height: 48px;
} }
\ No newline at end of file \ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
margin: 0; margin: 0;
color: var(--color-text-primary); color: var(--color-text-primary);
background-color: var(--color-canvas-default); background-color: var(--color-canvas-default);
font-size: 15px; font-size: 14px;
font-weight: 400; font-weight: 400;
line-height: 1.6; line-height: 1.6;
word-wrap: break-word; word-wrap: break-word;
......
...@@ -353,7 +353,7 @@ html[data-theme="light"] { ...@@ -353,7 +353,7 @@ html[data-theme="light"] {
--color-components-icon-bg-orange-solid: #f79009; --color-components-icon-bg-orange-solid: #f79009;
--color-components-icon-bg-orange-soft: #fffaeb; --color-components-icon-bg-orange-soft: #fffaeb;
--color-text-primary: #101828; --color-text-primary: #133368;
--color-text-secondary: #354052; --color-text-secondary: #354052;
--color-text-tertiary: #676f83; --color-text-tertiary: #676f83;
--color-text-quaternary: #1018284d; --color-text-quaternary: #1018284d;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!