mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-19 18:09:08 +08:00
agent tool in chat
This commit is contained in:
parent
0c4af3a1d2
commit
0da06128e3
@ -7,17 +7,14 @@ import type {
|
|||||||
import { Markdown } from '@/app/components/base/markdown'
|
import { Markdown } from '@/app/components/base/markdown'
|
||||||
import Thought from '@/app/components/base/chat/chat/thought'
|
import Thought from '@/app/components/base/chat/chat/thought'
|
||||||
import ImageGallery from '@/app/components/base/image-gallery'
|
import ImageGallery from '@/app/components/base/image-gallery'
|
||||||
import type { Emoji } from '@/app/components/tools/types'
|
|
||||||
|
|
||||||
type AgentContentProps = {
|
type AgentContentProps = {
|
||||||
item: ChatItem
|
item: ChatItem
|
||||||
responding?: boolean
|
responding?: boolean
|
||||||
allToolIcons?: Record<string, string | Emoji>
|
|
||||||
}
|
}
|
||||||
const AgentContent: FC<AgentContentProps> = ({
|
const AgentContent: FC<AgentContentProps> = ({
|
||||||
item,
|
item,
|
||||||
responding,
|
responding,
|
||||||
allToolIcons,
|
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
annotation,
|
annotation,
|
||||||
@ -45,7 +42,6 @@ const AgentContent: FC<AgentContentProps> = ({
|
|||||||
{!!thought.tool && (
|
{!!thought.tool && (
|
||||||
<Thought
|
<Thought
|
||||||
thought={thought}
|
thought={thought}
|
||||||
allToolIcons={allToolIcons || {}}
|
|
||||||
isFinished={!!thought.observation || !responding}
|
isFinished={!!thought.observation || !responding}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -19,7 +19,6 @@ import { MessageFast } from '@/app/components/base/icons/src/vender/solid/commun
|
|||||||
import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
|
import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
|
||||||
import Citation from '@/app/components/base/chat/chat/citation'
|
import Citation from '@/app/components/base/chat/chat/citation'
|
||||||
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 type { Emoji } from '@/app/components/tools/types'
|
|
||||||
import type { AppData } from '@/models/share'
|
import type { AppData } from '@/models/share'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ type AnswerProps = {
|
|||||||
config?: ChatConfig
|
config?: ChatConfig
|
||||||
answerIcon?: ReactNode
|
answerIcon?: ReactNode
|
||||||
responding?: boolean
|
responding?: boolean
|
||||||
allToolIcons?: Record<string, string | Emoji>
|
|
||||||
showPromptLog?: boolean
|
showPromptLog?: boolean
|
||||||
chatAnswerContainerInner?: string
|
chatAnswerContainerInner?: string
|
||||||
hideProcessDetail?: boolean
|
hideProcessDetail?: boolean
|
||||||
@ -43,7 +41,6 @@ const Answer: FC<AnswerProps> = ({
|
|||||||
config,
|
config,
|
||||||
answerIcon,
|
answerIcon,
|
||||||
responding,
|
responding,
|
||||||
allToolIcons,
|
|
||||||
showPromptLog,
|
showPromptLog,
|
||||||
chatAnswerContainerInner,
|
chatAnswerContainerInner,
|
||||||
hideProcessDetail,
|
hideProcessDetail,
|
||||||
@ -171,7 +168,6 @@ const Answer: FC<AnswerProps> = ({
|
|||||||
<AgentContent
|
<AgentContent
|
||||||
item={item}
|
item={item}
|
||||||
responding={responding}
|
responding={responding}
|
||||||
allToolIcons={allToolIcons}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
71
web/app/components/base/chat/chat/answer/tool-detail.tsx
Normal file
71
web/app/components/base/chat/chat/answer/tool-detail.tsx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
RiArrowDownSLine,
|
||||||
|
RiArrowRightSLine,
|
||||||
|
RiHammerFill,
|
||||||
|
RiLoader2Line,
|
||||||
|
} from '@remixicon/react'
|
||||||
|
import type { ToolInfoInThought } from '../type'
|
||||||
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
|
type ToolDetailProps = {
|
||||||
|
payload: ToolInfoInThought
|
||||||
|
}
|
||||||
|
const ToolDetail = ({
|
||||||
|
payload,
|
||||||
|
}: ToolDetailProps) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { name, label, input, isFinished, output } = payload
|
||||||
|
const toolLabel = name.startsWith('dataset_') ? t('dataset.knowledge') : label
|
||||||
|
const [expand, setExpand] = useState(false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'rounded-xl',
|
||||||
|
!expand && 'border-l-[0.25px] border-components-panel-border bg-workflow-process-bg',
|
||||||
|
expand && 'border-[0.5px] border-components-panel-border-subtle bg-background-section-burn',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex items-center system-xs-medium text-text-tertiary px-2.5 py-2 cursor-pointer',
|
||||||
|
expand && 'pb-1.5',
|
||||||
|
)}
|
||||||
|
onClick={() => setExpand(!expand)}
|
||||||
|
>
|
||||||
|
{isFinished && <RiHammerFill className='mr-1 w-3.5 h-3.5' />}
|
||||||
|
{!isFinished && <RiLoader2Line className='mr-1 w-3.5 h-3.5 animate-spin' />}
|
||||||
|
{t(`tools.thought.${isFinished ? 'used' : 'using'}`)}
|
||||||
|
<div className='mx-1 text-text-secondary'>{toolLabel}</div>
|
||||||
|
{!expand && <RiArrowRightSLine className='w-4 h-4' />}
|
||||||
|
{expand && <RiArrowDownSLine className='ml-auto w-4 h-4' />}
|
||||||
|
</div>
|
||||||
|
{
|
||||||
|
expand && (
|
||||||
|
<>
|
||||||
|
<div className='mb-0.5 mx-1 rounded-[10px] bg-components-panel-on-panel-item-bg text-text-secondary'>
|
||||||
|
<div className='flex items-center justify-between px-2 pt-1 h-7 system-xs-semibold-uppercase'>
|
||||||
|
{t('tools.thought.requestTitle')}
|
||||||
|
</div>
|
||||||
|
<div className='pt-1 px-3 pb-2 code-xs-regular'>
|
||||||
|
{input}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='mx-1 mb-1 rounded-[10px] bg-components-panel-on-panel-item-bg text-text-secondary'>
|
||||||
|
<div className='flex items-center justify-between px-2 pt-1 h-7 system-xs-semibold-uppercase'>
|
||||||
|
{t('tools.thought.responseTitle')}
|
||||||
|
</div>
|
||||||
|
<div className='pt-1 px-3 pb-2 code-xs-regular'>
|
||||||
|
{output}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ToolDetail
|
@ -10,7 +10,6 @@ export type ChatContextValue = Pick<ChatProps, 'config'
|
|||||||
| 'showPromptLog'
|
| 'showPromptLog'
|
||||||
| 'questionIcon'
|
| 'questionIcon'
|
||||||
| 'answerIcon'
|
| 'answerIcon'
|
||||||
| 'allToolIcons'
|
|
||||||
| 'onSend'
|
| 'onSend'
|
||||||
| 'onAnnotationEdited'
|
| 'onAnnotationEdited'
|
||||||
| 'onAnnotationAdded'
|
| 'onAnnotationAdded'
|
||||||
@ -34,7 +33,6 @@ export const ChatContextProvider = ({
|
|||||||
showPromptLog,
|
showPromptLog,
|
||||||
questionIcon,
|
questionIcon,
|
||||||
answerIcon,
|
answerIcon,
|
||||||
allToolIcons,
|
|
||||||
onSend,
|
onSend,
|
||||||
onAnnotationEdited,
|
onAnnotationEdited,
|
||||||
onAnnotationAdded,
|
onAnnotationAdded,
|
||||||
@ -49,7 +47,6 @@ export const ChatContextProvider = ({
|
|||||||
showPromptLog,
|
showPromptLog,
|
||||||
questionIcon,
|
questionIcon,
|
||||||
answerIcon,
|
answerIcon,
|
||||||
allToolIcons,
|
|
||||||
onSend,
|
onSend,
|
||||||
onAnnotationEdited,
|
onAnnotationEdited,
|
||||||
onAnnotationAdded,
|
onAnnotationAdded,
|
||||||
|
@ -80,7 +80,6 @@ const Chat: FC<ChatProps> = ({
|
|||||||
showPromptLog,
|
showPromptLog,
|
||||||
questionIcon,
|
questionIcon,
|
||||||
answerIcon,
|
answerIcon,
|
||||||
allToolIcons,
|
|
||||||
onAnnotationAdded,
|
onAnnotationAdded,
|
||||||
onAnnotationEdited,
|
onAnnotationEdited,
|
||||||
onAnnotationRemoved,
|
onAnnotationRemoved,
|
||||||
@ -183,7 +182,6 @@ const Chat: FC<ChatProps> = ({
|
|||||||
showPromptLog={showPromptLog}
|
showPromptLog={showPromptLog}
|
||||||
questionIcon={questionIcon}
|
questionIcon={questionIcon}
|
||||||
answerIcon={answerIcon}
|
answerIcon={answerIcon}
|
||||||
allToolIcons={allToolIcons}
|
|
||||||
onSend={onSend}
|
onSend={onSend}
|
||||||
onAnnotationAdded={onAnnotationAdded}
|
onAnnotationAdded={onAnnotationAdded}
|
||||||
onAnnotationEdited={onAnnotationEdited}
|
onAnnotationEdited={onAnnotationEdited}
|
||||||
@ -214,7 +212,6 @@ const Chat: FC<ChatProps> = ({
|
|||||||
config={config}
|
config={config}
|
||||||
answerIcon={answerIcon}
|
answerIcon={answerIcon}
|
||||||
responding={isLast && isResponding}
|
responding={isLast && isResponding}
|
||||||
allToolIcons={allToolIcons}
|
|
||||||
showPromptLog={showPromptLog}
|
showPromptLog={showPromptLog}
|
||||||
chatAnswerContainerInner={chatAnswerContainerInner}
|
chatAnswerContainerInner={chatAnswerContainerInner}
|
||||||
hideProcessDetail={hideProcessDetail}
|
hideProcessDetail={hideProcessDetail}
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type { ThoughtItem, ToolInfoInThought } from '../type'
|
import type { ThoughtItem, ToolInfoInThought } from '../type'
|
||||||
import Tool from '@/app/components/base/chat/chat/thought/tool'
|
import ToolDetail from '@/app/components/base/chat/chat/answer/tool-detail'
|
||||||
import type { Emoji } from '@/app/components/tools/types'
|
|
||||||
|
|
||||||
export type IThoughtProps = {
|
export type IThoughtProps = {
|
||||||
thought: ThoughtItem
|
thought: ThoughtItem
|
||||||
allToolIcons: Record<string, string | Emoji>
|
|
||||||
isFinished: boolean
|
isFinished: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +22,6 @@ function getValue(value: string, isValueArray: boolean, index: number) {
|
|||||||
|
|
||||||
const Thought: FC<IThoughtProps> = ({
|
const Thought: FC<IThoughtProps> = ({
|
||||||
thought,
|
thought,
|
||||||
allToolIcons,
|
|
||||||
isFinished,
|
isFinished,
|
||||||
}) => {
|
}) => {
|
||||||
const [toolNames, isValueArray]: [string[], boolean] = (() => {
|
const [toolNames, isValueArray]: [string[], boolean] = (() => {
|
||||||
@ -50,10 +47,9 @@ const Thought: FC<IThoughtProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className='my-2 space-y-2'>
|
<div className='my-2 space-y-2'>
|
||||||
{toolThoughtList.map((item: ToolInfoInThought, index) => (
|
{toolThoughtList.map((item: ToolInfoInThought, index) => (
|
||||||
<Tool
|
<ToolDetail
|
||||||
key={index}
|
key={index}
|
||||||
payload={item}
|
payload={item}
|
||||||
allToolIcons={allToolIcons}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -119,8 +119,8 @@ const translation = {
|
|||||||
thought: {
|
thought: {
|
||||||
using: 'Using',
|
using: 'Using',
|
||||||
used: 'Used',
|
used: 'Used',
|
||||||
requestTitle: 'Request to',
|
requestTitle: 'Request',
|
||||||
responseTitle: 'Response from',
|
responseTitle: 'Response',
|
||||||
},
|
},
|
||||||
setBuiltInTools: {
|
setBuiltInTools: {
|
||||||
info: 'Info',
|
info: 'Info',
|
||||||
|
@ -119,8 +119,8 @@ const translation = {
|
|||||||
thought: {
|
thought: {
|
||||||
using: '正在使用',
|
using: '正在使用',
|
||||||
used: '已使用',
|
used: '已使用',
|
||||||
requestTitle: '请求来自',
|
requestTitle: '请求',
|
||||||
responseTitle: '响应来自',
|
responseTitle: '响应',
|
||||||
},
|
},
|
||||||
setBuiltInTools: {
|
setBuiltInTools: {
|
||||||
info: '信息',
|
info: '信息',
|
||||||
|
@ -91,6 +91,7 @@ module.exports = {
|
|||||||
backgroundImage: {
|
backgroundImage: {
|
||||||
'chatbot-bg': 'var(--color-chatbot-bg)',
|
'chatbot-bg': 'var(--color-chatbot-bg)',
|
||||||
'chat-bubble-bg': 'var(--color-chat-bubble-bg)',
|
'chat-bubble-bg': 'var(--color-chat-bubble-bg)',
|
||||||
|
'workflow-process-bg': 'var(--color-workflow-process-bg)',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -601,4 +601,5 @@ html[data-theme="dark"] {
|
|||||||
--color-chatbot-bg: linear-gradient(180deg, rgba(34, 34, 37, 0.90) 0%, rgba(29, 29, 32, 0.90) 90.48%);
|
--color-chatbot-bg: linear-gradient(180deg, rgba(34, 34, 37, 0.90) 0%, rgba(29, 29, 32, 0.90) 90.48%);
|
||||||
--color-chat-bubble-bg: linear-gradient(180deg, rgba(200, 206, 218, 0.08) 0%, rgba(200, 206, 218, 0.02) 100%);
|
--color-chat-bubble-bg: linear-gradient(180deg, rgba(200, 206, 218, 0.08) 0%, rgba(200, 206, 218, 0.02) 100%);
|
||||||
--color-third-party-Github: #FFFFFF;
|
--color-third-party-Github: #FFFFFF;
|
||||||
|
--color-workflow-process-bg: linear-gradient(90deg, rgba(24, 24, 27, 0.25) 0%, rgba(24, 24, 27, 0.04) 100%);
|
||||||
}
|
}
|
@ -601,4 +601,5 @@ html[data-theme="light"] {
|
|||||||
--color-chatbot-bg: linear-gradient(180deg, rgba(249, 250, 251, 0.90) 0%, rgba(242, 244, 247, 0.90) 90.48%);
|
--color-chatbot-bg: linear-gradient(180deg, rgba(249, 250, 251, 0.90) 0%, rgba(242, 244, 247, 0.90) 90.48%);
|
||||||
--color-chat-bubble-bg: linear-gradient(180deg, #FFF 0%, rgba(255, 255, 255, 0.60) 100%);
|
--color-chat-bubble-bg: linear-gradient(180deg, #FFF 0%, rgba(255, 255, 255, 0.60) 100%);
|
||||||
--color-third-party-Github: #1B1F24;
|
--color-third-party-Github: #1B1F24;
|
||||||
|
--color-workflow-process-bg: linear-gradient(90deg, rgba(200, 206, 218, 0.20) 0%, rgba(200, 206, 218, 0.04) 100%);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user