fix(web): share app chat support statement

This commit is contained in:
zhaoying
2026-04-07 18:09:32 +08:00
parent be8c481d6d
commit 856c6f6d78
5 changed files with 58 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing
* @Date: 2026-02-03 16:29:21
* @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 { useTranslation } from 'react-i18next'
@@ -354,6 +354,25 @@ const Agent = forwardRef<AgentRef, { onFeaturesLoad?: (features: FeaturesConfigF
const handleSaveFeaturesConfig = (value: FeaturesConfigForm) => {
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(() => {
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) {
return { ...vo, list: [assistantMsg] }
} 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 {
return { ...vo, list: [assistantMsg, ...(vo.list || [])] }
}