mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
Merge branch 'main' into feat/external-knowledge-api
# Conflicts: # api/poetry.lock
This commit is contained in:
@ -22,7 +22,7 @@ const Activate = () => {
|
||||
<Header />
|
||||
<ActivateForm />
|
||||
<div className='px-8 py-6 text-sm font-normal text-gray-500'>
|
||||
© {new Date().getFullYear()} Dify, Inc. All rights reserved.
|
||||
© {new Date().getFullYear()} LangGenius, Inc. All rights reserved.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React, { useCallback, useState } from 'react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import ModalFoot from '../modal-foot'
|
||||
@ -40,6 +40,12 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
||||
const { t } = useTranslation()
|
||||
const [tempPayload, setTempPayload] = useState<InputVar>(payload || getNewVarInWorkflow('') as any)
|
||||
const { type, label, variable, options, max_length } = tempPayload
|
||||
const modalRef = useRef<HTMLDivElement>(null)
|
||||
useEffect(() => {
|
||||
// To fix the first input element auto focus, then directly close modal will raise error
|
||||
if (isShow)
|
||||
modalRef.current?.focus()
|
||||
}, [isShow])
|
||||
|
||||
const isStringInput = type === InputVarType.textInput || type === InputVarType.paragraph
|
||||
const checkVariableName = useCallback((value: string) => {
|
||||
@ -135,7 +141,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
||||
isShow={isShow}
|
||||
onClose={onClose}
|
||||
>
|
||||
<div className='mb-8'>
|
||||
<div className='mb-8' ref={modalRef} tabIndex={-1}>
|
||||
<div className='space-y-2'>
|
||||
|
||||
<Field title={t('appDebug.variableConfig.fieldType')}>
|
||||
|
||||
@ -55,6 +55,8 @@ const Filter: FC<IFilterProps> = ({ isChatMode, appId, queryParams, setQueryPara
|
||||
className='!w-[300px]'
|
||||
onSelect={
|
||||
(item) => {
|
||||
if (!item.value)
|
||||
return
|
||||
setQueryParams({ ...queryParams, annotation_status: item.value as string })
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,8 @@ const Filter: FC<IFilterProps> = ({ queryParams, setQueryParams }: IFilterProps)
|
||||
className='!min-w-[100px]'
|
||||
onSelect={
|
||||
(item) => {
|
||||
if (!item.value)
|
||||
return
|
||||
setQueryParams({ ...queryParams, status: item.value as string })
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +85,19 @@ const Answer: FC<AnswerProps> = ({
|
||||
getContentWidth()
|
||||
}, [responding])
|
||||
|
||||
// Recalculate contentWidth when content changes (e.g., SVG preview/source toggle)
|
||||
useEffect(() => {
|
||||
if (!containerRef.current)
|
||||
return
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
getContentWidth()
|
||||
})
|
||||
resizeObserver.observe(containerRef.current)
|
||||
return () => {
|
||||
resizeObserver.disconnect()
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className='flex mb-2 last:mb-0'>
|
||||
<div className='shrink-0 relative w-10 h-10'>
|
||||
|
||||
@ -116,59 +116,80 @@ const CodeBlock: CodeComponent = memo(({ inline, className, children, ...props }
|
||||
const match = /language-(\w+)/.exec(className || '')
|
||||
const language = match?.[1]
|
||||
const languageShowName = getCorrectCapitalizationLanguageName(language || '')
|
||||
let chartData = JSON.parse(String('{"title":{"text":"ECharts error - Wrong JSON format."}}').replace(/\n$/, ''))
|
||||
if (language === 'echarts') {
|
||||
try {
|
||||
chartData = JSON.parse(String(children).replace(/\n$/, ''))
|
||||
const chartData = useMemo(() => {
|
||||
if (language === 'echarts') {
|
||||
try {
|
||||
return JSON.parse(String(children).replace(/\n$/, ''))
|
||||
}
|
||||
catch (error) {}
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
}
|
||||
return JSON.parse('{"title":{"text":"ECharts error - Wrong JSON format."}}')
|
||||
}, [language, children])
|
||||
|
||||
// Use `useMemo` to ensure that `SyntaxHighlighter` only re-renders when necessary
|
||||
return useMemo(() => {
|
||||
return (!inline && match)
|
||||
? (
|
||||
<div>
|
||||
<div
|
||||
className='flex justify-between h-8 items-center p-1 pl-3 border-b'
|
||||
style={{
|
||||
borderColor: 'rgba(0, 0, 0, 0.05)',
|
||||
}}
|
||||
>
|
||||
<div className='text-[13px] text-gray-500 font-normal'>{languageShowName}</div>
|
||||
<div style={{ display: 'flex' }}>
|
||||
{language === 'mermaid' && <SVGBtn isSVG={isSVG} setIsSVG={setIsSVG}/>}
|
||||
<CopyBtn
|
||||
className='mr-1'
|
||||
value={String(children).replace(/\n$/, '')}
|
||||
isPlain
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{(language === 'mermaid' && isSVG)
|
||||
? (<Flowchart PrimitiveCode={String(children).replace(/\n$/, '')} />)
|
||||
: (language === 'echarts'
|
||||
? (<div style={{ minHeight: '350px', minWidth: '700px' }}><ErrorBoundary><ReactEcharts option={chartData} /></ErrorBoundary></div>)
|
||||
: (language === 'svg'
|
||||
? (<ErrorBoundary><SVGRenderer content={String(children).replace(/\n$/, '')} /></ErrorBoundary>)
|
||||
: (<SyntaxHighlighter
|
||||
{...props}
|
||||
style={atelierHeathLight}
|
||||
customStyle={{
|
||||
paddingLeft: 12,
|
||||
backgroundColor: '#fff',
|
||||
}}
|
||||
language={match[1]}
|
||||
showLineNumbers
|
||||
PreTag="div"
|
||||
>
|
||||
{String(children).replace(/\n$/, '')}
|
||||
</SyntaxHighlighter>)))}
|
||||
const renderCodeContent = useMemo(() => {
|
||||
const content = String(children).replace(/\n$/, '')
|
||||
if (language === 'mermaid' && isSVG) {
|
||||
return <Flowchart PrimitiveCode={content} />
|
||||
}
|
||||
else if (language === 'echarts') {
|
||||
return (
|
||||
<div style={{ minHeight: '350px', minWidth: '700px' }}>
|
||||
<ErrorBoundary>
|
||||
<ReactEcharts option={chartData} />
|
||||
</ErrorBoundary>
|
||||
</div>
|
||||
)
|
||||
: (<code {...props} className={className}>{children}</code>)
|
||||
}, [chartData, children, className, inline, isSVG, language, languageShowName, match, props])
|
||||
}
|
||||
else if (language === 'svg' && isSVG) {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<SVGRenderer content={content} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
else {
|
||||
return (
|
||||
<SyntaxHighlighter
|
||||
{...props}
|
||||
style={atelierHeathLight}
|
||||
customStyle={{
|
||||
paddingLeft: 12,
|
||||
backgroundColor: '#fff',
|
||||
}}
|
||||
language={match?.[1]}
|
||||
showLineNumbers
|
||||
PreTag="div"
|
||||
>
|
||||
{content}
|
||||
</SyntaxHighlighter>
|
||||
)
|
||||
}
|
||||
}, [language, match, props, children, chartData, isSVG])
|
||||
|
||||
if (inline || !match)
|
||||
return <code {...props} className={className}>{children}</code>
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className='flex justify-between h-8 items-center p-1 pl-3 border-b'
|
||||
style={{
|
||||
borderColor: 'rgba(0, 0, 0, 0.05)',
|
||||
}}
|
||||
>
|
||||
<div className='text-[13px] text-gray-500 font-normal'>{languageShowName}</div>
|
||||
<div style={{ display: 'flex' }}>
|
||||
{(['mermaid', 'svg']).includes(language!) && <SVGBtn isSVG={isSVG} setIsSVG={setIsSVG}/>}
|
||||
<CopyBtn
|
||||
className='mr-1'
|
||||
value={String(children).replace(/\n$/, '')}
|
||||
isPlain
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{renderCodeContent}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
CodeBlock.displayName = 'CodeBlock'
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ export const SVGRenderer = ({ content }: { content: string }) => {
|
||||
if (svgRef.current) {
|
||||
try {
|
||||
svgRef.current.innerHTML = ''
|
||||
const draw = SVG().addTo(svgRef.current).size('100%', '100%')
|
||||
const draw = SVG().addTo(svgRef.current)
|
||||
|
||||
const parser = new DOMParser()
|
||||
const svgDoc = parser.parseFromString(content, 'image/svg+xml')
|
||||
@ -40,13 +40,11 @@ export const SVGRenderer = ({ content }: { content: string }) => {
|
||||
|
||||
const originalWidth = parseInt(svgElement.getAttribute('width') || '400', 10)
|
||||
const originalHeight = parseInt(svgElement.getAttribute('height') || '600', 10)
|
||||
const scale = Math.min(windowSize.width / originalWidth, windowSize.height / originalHeight, 1)
|
||||
const scaledWidth = originalWidth * scale
|
||||
const scaledHeight = originalHeight * scale
|
||||
draw.size(scaledWidth, scaledHeight)
|
||||
draw.viewbox(0, 0, originalWidth, originalHeight)
|
||||
|
||||
svgRef.current.style.width = `${Math.min(originalWidth, 298)}px`
|
||||
|
||||
const rootElement = draw.svg(content)
|
||||
rootElement.scale(scale)
|
||||
|
||||
rootElement.click(() => {
|
||||
setImagePreview(svgToDataURL(svgElement as Element))
|
||||
@ -54,7 +52,7 @@ export const SVGRenderer = ({ content }: { content: string }) => {
|
||||
}
|
||||
catch (error) {
|
||||
if (svgRef.current)
|
||||
svgRef.current.innerHTML = 'Error rendering SVG. Wait for the image content to complete.'
|
||||
svgRef.current.innerHTML = '<span style="padding: 1rem;">Error rendering SVG. Wait for the image content to complete.</span>'
|
||||
}
|
||||
}
|
||||
}, [content, windowSize])
|
||||
@ -62,14 +60,14 @@ export const SVGRenderer = ({ content }: { content: string }) => {
|
||||
return (
|
||||
<>
|
||||
<div ref={svgRef} style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
minHeight: '300px',
|
||||
maxHeight: '80vh',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
cursor: 'pointer',
|
||||
wordBreak: 'break-word',
|
||||
whiteSpace: 'normal',
|
||||
margin: '0 auto',
|
||||
}} />
|
||||
{imagePreview && (<ImagePreview url={imagePreview} title='Preview' onCancel={() => setImagePreview('')} />)}
|
||||
</>
|
||||
|
||||
@ -65,7 +65,7 @@ const WorkflowToolConfigureButton = ({
|
||||
else {
|
||||
if (item.type === 'paragraph' && param.type !== 'string')
|
||||
return true
|
||||
if (param.type !== item.type && !(param.type === 'string' && item.type === 'paragraph'))
|
||||
if (item.type === 'text-input' && param.type !== 'string')
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ const Node: FC<NodeProps<HttpNodeType>> = ({
|
||||
<div className='mb-1 px-3 py-1'>
|
||||
<div className='flex items-start p-1 rounded-md bg-gray-100'>
|
||||
<div className='flex items-center h-4 shrink-0 px-1 rounded bg-gray-25 text-xs font-semibold text-gray-700 uppercase'>{method}</div>
|
||||
<div className='pl-1'>
|
||||
<div className='pl-1 pt-1'>
|
||||
<ReadonlyInputWithSelectVar
|
||||
value={url}
|
||||
nodeId={id}
|
||||
|
||||
@ -90,7 +90,7 @@ const ChatRecord = () => {
|
||||
return (
|
||||
<div
|
||||
className={`
|
||||
flex flex-col w-[400px] rounded-l-2xl h-full border border-black/2 shadow-xl
|
||||
flex flex-col w-[420px] rounded-l-2xl h-full border border-black/2 shadow-xl
|
||||
`}
|
||||
style={{
|
||||
background: 'linear-gradient(156deg, rgba(242, 244, 247, 0.80) 0%, rgba(242, 244, 247, 0.00) 99.43%), var(--white, #FFF)',
|
||||
@ -121,7 +121,7 @@ const ChatRecord = () => {
|
||||
supportCitationHitInfo: true,
|
||||
} as any}
|
||||
chatList={chatList}
|
||||
chatContainerClassName='px-4'
|
||||
chatContainerClassName='px-3'
|
||||
chatContainerInnerClassName='pt-6 w-full max-w-full mx-auto'
|
||||
chatFooterClassName='px-4 rounded-b-2xl'
|
||||
chatFooterInnerClassName='pb-4 w-full max-w-full mx-auto'
|
||||
@ -129,6 +129,8 @@ const ChatRecord = () => {
|
||||
noChatInput
|
||||
allToolIcons={{}}
|
||||
showPromptLog
|
||||
noSpacing
|
||||
chatAnswerContainerInner='!pr-2'
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@ -28,7 +28,7 @@ const ForgotPassword = () => {
|
||||
<Header />
|
||||
{token ? <ChangePasswordForm /> : <ForgotPasswordForm />}
|
||||
<div className='px-8 py-6 text-sm font-normal text-gray-500'>
|
||||
© {new Date().getFullYear()} Dify, Inc. All rights reserved.
|
||||
© {new Date().getFullYear()} LangGenius, Inc. All rights reserved.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -22,7 +22,7 @@ const Install = () => {
|
||||
<Header />
|
||||
<InstallForm />
|
||||
<div className='px-8 py-6 text-sm font-normal text-gray-500'>
|
||||
© {new Date().getFullYear()} Dify, Inc. All rights reserved.
|
||||
© {new Date().getFullYear()} LangGenius, Inc. All rights reserved.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -202,7 +202,7 @@ const translation = {
|
||||
invitationLink: 'Enlace de invitación',
|
||||
failedInvitationEmails: 'Los siguientes usuarios no fueron invitados exitosamente',
|
||||
ok: 'OK',
|
||||
removeFromTeam: 'Eliminar del equipo',
|
||||
removeFromTeam: 'Eliminar del espacio de trabajo',
|
||||
removeFromTeamTip: 'Se eliminará el acceso al equipo',
|
||||
setAdmin: 'Establecer como administrador',
|
||||
setMember: 'Establecer como miembro ordinario',
|
||||
|
||||
@ -200,7 +200,7 @@ const translation = {
|
||||
invitationLink: '邀请链接',
|
||||
failedInvitationEmails: '邀请以下邮箱失败',
|
||||
ok: '好的',
|
||||
removeFromTeam: '移除团队',
|
||||
removeFromTeam: '移出团队',
|
||||
removeFromTeamTip: '将取消团队访问',
|
||||
setAdmin: '设为管理员',
|
||||
setMember: '设为普通成员',
|
||||
|
||||
@ -194,7 +194,7 @@ const translation = {
|
||||
invitationLink: '邀請連結',
|
||||
failedInvitationEmails: '邀請以下郵箱失敗',
|
||||
ok: '好的',
|
||||
removeFromTeam: '移除團隊',
|
||||
removeFromTeam: '移出團隊',
|
||||
removeFromTeamTip: '將取消團隊訪問',
|
||||
setAdmin: '設為管理員',
|
||||
setMember: '設為普通成員',
|
||||
|
||||
Reference in New Issue
Block a user