fix(web): share app chat support statement
This commit is contained in:
@@ -82,6 +82,7 @@ const ChatToolbar = forwardRef<ChatToolbarRef, ChatToolbarProps>(({
|
|||||||
setVariables: (variables) => {
|
setVariables: (variables) => {
|
||||||
console.log('variables', variables)
|
console.log('variables', variables)
|
||||||
form.setFieldValue('variables', variables)
|
form.setFieldValue('variables', variables)
|
||||||
|
onVariablesChange?.(variables)
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: ZhaoYing
|
* @Author: ZhaoYing
|
||||||
* @Date: 2026-02-03 16:29:21
|
* @Date: 2026-02-03 16:29:21
|
||||||
* @Last Modified by: ZhaoYing
|
* @Last Modified by: ZhaoYing
|
||||||
* @Last Modified time: 2026-03-31 16:50:10
|
* @Last Modified time: 2026-04-07 18:04:49
|
||||||
*/
|
*/
|
||||||
import { useEffect, useRef, useState, forwardRef, useImperativeHandle, useMemo } from 'react';
|
import { useEffect, useRef, useState, forwardRef, useImperativeHandle, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -354,6 +354,25 @@ const Agent = forwardRef<AgentRef, { onFeaturesLoad?: (features: FeaturesConfigF
|
|||||||
|
|
||||||
const handleSaveFeaturesConfig = (value: FeaturesConfigForm) => {
|
const handleSaveFeaturesConfig = (value: FeaturesConfigForm) => {
|
||||||
form.setFieldValue('features', value)
|
form.setFieldValue('features', value)
|
||||||
|
const { statement = '' } = value?.opening_statement || {}
|
||||||
|
onFeaturesLoad?.(value)
|
||||||
|
|
||||||
|
const usedVars = [...new Set([...(statement?.matchAll(/\{\{(\w+)\}\}/g) ?? [])].map(m => m[1]))]
|
||||||
|
const variables = values?.variables
|
||||||
|
const validNames = new Set(variables.map(v => v.name))
|
||||||
|
const invalid = usedVars.filter(v => !validNames.has(v))
|
||||||
|
if (invalid.length > 0) {
|
||||||
|
const newVars = invalid.map((name, i) => ({
|
||||||
|
index: variables.length + i,
|
||||||
|
name,
|
||||||
|
display_name: name,
|
||||||
|
type: 'text',
|
||||||
|
required: true,
|
||||||
|
max_length: 48,
|
||||||
|
}))
|
||||||
|
|
||||||
|
form.setFieldValue('variables', [...variables, ...newVars])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const modelLogo = useMemo(() => {
|
const modelLogo = useMemo(() => {
|
||||||
return defaultModel?.name && getListLogoUrl(defaultModel.provider, defaultModel.logo as string)
|
return defaultModel?.name && getListLogoUrl(defaultModel.provider, defaultModel.logo as string)
|
||||||
@@ -385,7 +404,8 @@ const Agent = forwardRef<AgentRef, { onFeaturesLoad?: (features: FeaturesConfigF
|
|||||||
if (vo.list?.length === 0) {
|
if (vo.list?.length === 0) {
|
||||||
return { ...vo, list: [assistantMsg] }
|
return { ...vo, list: [assistantMsg] }
|
||||||
} else if (vo.list && vo.list[0].role === 'assistant') {
|
} else if (vo.list && vo.list[0].role === 'assistant') {
|
||||||
return { ...vo, list: [assistantMsg, ...vo.list.slice(1)] }
|
vo.list[0] = assistantMsg
|
||||||
|
return { ...vo, list: [...vo.list] }
|
||||||
} else {
|
} else {
|
||||||
return { ...vo, list: [assistantMsg, ...(vo.list || [])] }
|
return { ...vo, list: [assistantMsg, ...(vo.list || [])] }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: ZhaoYing
|
* @Author: ZhaoYing
|
||||||
* @Date: 2026-03-13 17:27:52
|
* @Date: 2026-03-13 17:27:52
|
||||||
* @Last Modified by: ZhaoYing
|
* @Last Modified by: ZhaoYing
|
||||||
* @Last Modified time: 2026-04-02 17:58:07
|
* @Last Modified time: 2026-04-07 18:08:18
|
||||||
*/
|
*/
|
||||||
import { type FC, useState, useRef, useEffect } from 'react'
|
import { type FC, useState, useRef, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -27,6 +27,7 @@ import type { TestChatProps } from './type'
|
|||||||
import type { SSEMessage } from '@/utils/stream'
|
import type { SSEMessage } from '@/utils/stream'
|
||||||
import type { FeaturesConfigForm } from '@/views/ApplicationConfig/types'
|
import type { FeaturesConfigForm } from '@/views/ApplicationConfig/types'
|
||||||
import { getFileStatusById } from '@/api/fileStorage'
|
import { getFileStatusById } from '@/api/fileStorage'
|
||||||
|
import { replaceVariables } from '@/views/ApplicationConfig/Agent'
|
||||||
|
|
||||||
const formatParams = (message: string, conversation_id: string | null, files: any[] = [], variables: Record<string, any>) => {
|
const formatParams = (message: string, conversation_id: string | null, files: any[] = [], variables: Record<string, any>) => {
|
||||||
return {
|
return {
|
||||||
@@ -86,6 +87,7 @@ const TestChat: FC<TestChatProps> = ({
|
|||||||
const [message, setMessage] = useState<string | undefined>(undefined)
|
const [message, setMessage] = useState<string | undefined>(undefined)
|
||||||
const [fileList, setFileList] = useState<any[]>([])
|
const [fileList, setFileList] = useState<any[]>([])
|
||||||
const [features, setFeatures] = useState<FeaturesConfigForm>({} as FeaturesConfigForm)
|
const [features, setFeatures] = useState<FeaturesConfigForm>({} as FeaturesConfigForm)
|
||||||
|
const [variables, setVariables] = useState<Variable[]>([])
|
||||||
|
|
||||||
const audioPollingRef = useRef<Map<string, ReturnType<typeof setInterval>>>(new Map())
|
const audioPollingRef = useRef<Map<string, ReturnType<typeof setInterval>>>(new Map())
|
||||||
const [audioStatusMap, setAudioStatusMap] = useState<Record<string, string>>({})
|
const [audioStatusMap, setAudioStatusMap] = useState<Record<string, string>>({})
|
||||||
@@ -107,7 +109,7 @@ const TestChat: FC<TestChatProps> = ({
|
|||||||
setFeatures(config?.features || {} as FeaturesConfigForm)
|
setFeatures(config?.features || {} as FeaturesConfigForm)
|
||||||
|
|
||||||
|
|
||||||
if (config?.features?.opening_statement?.statement && config?.features?.opening_statement?.statement.trim() !== '') {
|
if (config?.features?.opening_statement.enabled && config?.features?.opening_statement?.statement && config?.features?.opening_statement?.statement.trim() !== '') {
|
||||||
setChatList(prev => [...prev, {
|
setChatList(prev => [...prev, {
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
created_at: Date.now(),
|
created_at: Date.now(),
|
||||||
@@ -144,6 +146,7 @@ const TestChat: FC<TestChatProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
toolbarRef.current?.setVariables([...initVariables])
|
toolbarRef.current?.setVariables([...initVariables])
|
||||||
|
setVariables([...initVariables])
|
||||||
}
|
}
|
||||||
|
|
||||||
const addUserMessage = (message: string, files: any[]) => {
|
const addUserMessage = (message: string, files: any[]) => {
|
||||||
@@ -560,6 +563,24 @@ const TestChat: FC<TestChatProps> = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const opening_statement = features?.opening_statement
|
||||||
|
|
||||||
|
if (opening_statement?.enabled && opening_statement?.statement && opening_statement?.statement.trim() !== '') {
|
||||||
|
const assistantMsg: ChatItem = {
|
||||||
|
role: 'assistant',
|
||||||
|
content: replaceVariables(opening_statement.statement, variables as any),
|
||||||
|
meta_data: {
|
||||||
|
suggested_questions: opening_statement?.suggested_questions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setChatList(prev => {
|
||||||
|
prev[0] = assistantMsg
|
||||||
|
return [...prev]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [chatList.length, features?.opening_statement, variables])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rb:w-250 rb:mx-auto rb:h-full">
|
<div className="rb:w-250 rb:mx-auto rb:h-full">
|
||||||
<RbCard
|
<RbCard
|
||||||
@@ -592,6 +613,7 @@ const TestChat: FC<TestChatProps> = ({
|
|||||||
ref={toolbarRef}
|
ref={toolbarRef}
|
||||||
features={features}
|
features={features}
|
||||||
onFilesChange={setFileList}
|
onFilesChange={setFileList}
|
||||||
|
onVariablesChange={setVariables}
|
||||||
/>
|
/>
|
||||||
</Chat>
|
</Chat>
|
||||||
</RbCard>
|
</RbCard>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: ZhaoYing
|
* @Author: ZhaoYing
|
||||||
* @Date: 2026-02-03 16:58:03
|
* @Date: 2026-02-03 16:58:03
|
||||||
* @Last Modified by: ZhaoYing
|
* @Last Modified by: ZhaoYing
|
||||||
* @Last Modified time: 2026-03-31 16:24:47
|
* @Last Modified time: 2026-04-07 18:08:52
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Conversation Page
|
* Conversation Page
|
||||||
@@ -178,7 +178,7 @@ const Conversation: FC = () => {
|
|||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (features?.opening_statement?.statement) {
|
if (features?.opening_statement.enabled && features?.opening_statement?.statement) {
|
||||||
setChatList([{
|
setChatList([{
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: features.opening_statement.statement,
|
content: features.opening_statement.statement,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: ZhaoYing
|
* @Author: ZhaoYing
|
||||||
* @Date: 2026-02-06 21:10:56
|
* @Date: 2026-02-06 21:10:56
|
||||||
* @Last Modified by: ZhaoYing
|
* @Last Modified by: ZhaoYing
|
||||||
* @Last Modified time: 2026-04-07 17:06:02
|
* @Last Modified time: 2026-04-07 18:07:38
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Workflow Chat Component
|
* Workflow Chat Component
|
||||||
@@ -68,8 +68,8 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef; data: Work
|
|||||||
const handleOpen = () => {
|
const handleOpen = () => {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
|
|
||||||
if (features?.opening_statement?.statement && features?.opening_statement?.statement.trim() !== '') {
|
if (features?.opening_statement?.enabled && features?.opening_statement?.statement && features?.opening_statement?.statement.trim() !== '') {
|
||||||
setChatList(prev => [...prev, {
|
setChatList([{
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
created_at: Date.now(),
|
created_at: Date.now(),
|
||||||
content: features?.opening_statement?.statement,
|
content: features?.opening_statement?.statement,
|
||||||
@@ -431,8 +431,12 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef; data: Work
|
|||||||
suggested_questions: opening_statement?.suggested_questions
|
suggested_questions: opening_statement?.suggested_questions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('variables', assistantMsg)
|
setChatList(prev => {
|
||||||
setChatList(prev => [assistantMsg, ...prev.slice(1)])
|
if (prev[0]?.role === 'assistant') {
|
||||||
|
prev[0] = assistantMsg
|
||||||
|
}
|
||||||
|
return [...prev]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [chatList.length, features?.opening_statement, variables])
|
}, [chatList.length, features?.opening_statement, variables])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user