mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Yansong Zhang <916125788@qq.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: hj24 <mambahj24@gmail.com> Co-authored-by: hj24 <huangjian@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Ayush Baluni <73417844+aayushbaluni@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: jimcody1995 <jjimcody@gmail.com> Co-authored-by: James <63717587+jamesrayammons@users.noreply.github.com> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: Stephen Zhou <hi@hyoban.cc> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jerryzai <jerryzh8710@protonmail.com> Co-authored-by: NVIDIAN <speedy.hpc@hotmail.com> Co-authored-by: ai-hpc <ai-hpc@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Junghwan <70629228+shaun0927@users.noreply.github.com> Co-authored-by: HeYinKazune <70251095+HeYin-OS@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Jingyi <jingyi.qi@dify.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: sxxtony <166789813+sxxtony@users.noreply.github.com>
112 lines
3.3 KiB
TypeScript
112 lines
3.3 KiB
TypeScript
'use client'
|
|
import type { FC } from 'react'
|
|
import { useMemo } from 'react'
|
|
import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
|
|
import { FileList } from '@/app/components/base/file-uploader'
|
|
import { getProcessedFilesFromResponse } from '@/app/components/base/file-uploader/utils'
|
|
import { Markdown } from '@/app/components/base/markdown'
|
|
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
|
|
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
|
import StatusContainer from '@/app/components/workflow/run/status-container'
|
|
|
|
type OutputPanelProps = {
|
|
isRunning?: boolean
|
|
outputs?: any
|
|
error?: string
|
|
height?: number
|
|
}
|
|
|
|
const OutputPanel: FC<OutputPanelProps> = ({
|
|
isRunning,
|
|
outputs,
|
|
error,
|
|
height,
|
|
}) => {
|
|
const isTextOutput = useMemo(() => {
|
|
if (!outputs || typeof outputs !== 'object')
|
|
return false
|
|
const keys = Object.keys(outputs)
|
|
const value = outputs[keys[0]!]
|
|
return keys.length === 1 && (
|
|
typeof value === 'string'
|
|
|| (Array.isArray(value) && value.every(item => typeof item === 'string'))
|
|
)
|
|
}, [outputs])
|
|
|
|
const fileList = useMemo(() => {
|
|
const fileList: any[] = []
|
|
if (!outputs)
|
|
return fileList
|
|
if (Object.keys(outputs).length > 1)
|
|
return fileList
|
|
for (const key in outputs) {
|
|
if (Array.isArray(outputs[key])) {
|
|
outputs[key].map((output: any) => {
|
|
if (output?.dify_model_identity === '__dify__file__')
|
|
fileList.push(output)
|
|
return null
|
|
})
|
|
}
|
|
else if (outputs[key]?.dify_model_identity === '__dify__file__') {
|
|
fileList.push(outputs[key])
|
|
}
|
|
}
|
|
return getProcessedFilesFromResponse(fileList)
|
|
}, [outputs])
|
|
return (
|
|
<div className="p-2">
|
|
{isRunning && (
|
|
<div className="pt-4 pl-[26px]">
|
|
<LoadingAnim type="text" />
|
|
</div>
|
|
)}
|
|
{!isRunning && error && (
|
|
<div className="px-4">
|
|
<StatusContainer status="failed">{error}</StatusContainer>
|
|
</div>
|
|
)}
|
|
{!isRunning && !outputs && (
|
|
<div className="px-4 py-2">
|
|
<Markdown content="No Output" />
|
|
</div>
|
|
)}
|
|
{isTextOutput && (
|
|
<div className="px-4 py-2">
|
|
<Markdown
|
|
content={
|
|
Array.isArray(outputs[Object.keys(outputs)[0]!])
|
|
? outputs[Object.keys(outputs)[0]!].join('\n')
|
|
: (outputs[Object.keys(outputs)[0]!] || '')
|
|
}
|
|
/>
|
|
</div>
|
|
)}
|
|
{fileList.length > 0 && (
|
|
<div className="px-4 py-2">
|
|
<FileList
|
|
files={fileList}
|
|
showDeleteAction={false}
|
|
showDownloadAction
|
|
canPreview
|
|
/>
|
|
</div>
|
|
)}
|
|
{!isTextOutput && outputs && Object.keys(outputs).length > 0 && height! > 0 && (
|
|
<div className="flex flex-col gap-2">
|
|
<CodeEditor
|
|
showFileList
|
|
readOnly
|
|
title={<div tabIndex={0}>Output</div>}
|
|
language={CodeLanguage.json}
|
|
value={JSON.stringify(outputs, null, 2)}
|
|
isJSONStringifyBeauty
|
|
height={height ? (height - 16) / 2 : undefined}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default OutputPanel
|