Merge branch 'feat/rag-pipeline' into deploy/rag-dev

This commit is contained in:
zxhlyh 2025-06-13 14:43:38 +08:00
commit fcb2fa04e7
5 changed files with 42 additions and 11 deletions

View File

@ -10,7 +10,6 @@ import { CodeLanguage } from './types'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
import { fetchNodeDefault } from '@/service/workflow'
import { useStore as useAppStore } from '@/app/components/app/store'
import {
useNodesReadOnly,
} from '@/app/components/workflow/hooks'
@ -18,7 +17,7 @@ import {
const useConfig = (id: string, payload: CodeNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
const appId = useAppStore.getState().appDetail?.id
const appId = useStore(s => s.appId)
const [allLanguageDefault, setAllLanguageDefault] = useState<Record<CodeLanguage, CodeNodeType> | null>(null)
useEffect(() => {
@ -34,7 +33,7 @@ const useConfig = (id: string, payload: CodeNodeType) => {
}
}, [appId])
const defaultConfig = useStore(s => s.nodesDefaultConfigs)[payload.type]
const defaultConfig = useStore(s => s.nodesDefaultConfigs)?.[payload.type]
const { inputs, setInputs } = useNodeCrud<CodeNodeType>(id, payload)
const { handleVarListChange, handleAddVariable } = useVarList<CodeNodeType>({
inputs,

View File

@ -159,8 +159,9 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
}
<OutputVars>
{
COMMON_OUTPUT.map(item => (
COMMON_OUTPUT.map((item, index) => (
<VarItem
key={index}
name={item.name}
type={item.type}
description={item.description}
@ -168,8 +169,9 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
))
}
{
isLocalFile && LOCAL_FILE_OUTPUT.map(item => (
isLocalFile && LOCAL_FILE_OUTPUT.map((item, index) => (
<VarItem
key={index}
name={item.name}
type={item.type}
description={item.description}
@ -182,8 +184,9 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
))
}
{
isWebsiteCrawl && WEBSITE_CRAWL_OUTPUT.map(item => (
isWebsiteCrawl && WEBSITE_CRAWL_OUTPUT.map((item, index) => (
<VarItem
key={index}
name={item.name}
type={item.type}
description={item.description}
@ -191,8 +194,9 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
))
}
{
isOnlineDocument && ONLINE_DOCUMENT_OUTPUT.map(item => (
isOnlineDocument && ONLINE_DOCUMENT_OUTPUT.map((item, index) => (
<VarItem
key={index}
name={item.name}
type={item.type}
description={item.description}

View File

@ -16,6 +16,7 @@ import {
PortalToFollowElemContent,
PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem'
import { useStore } from '@/app/components/workflow/store'
const ExportImage: FC = () => {
const { t } = useTranslation()
@ -23,9 +24,10 @@ const ExportImage: FC = () => {
const appDetail = useAppStore(s => s.appDetail)
const [open, setOpen] = useState(false)
const knowledgeName = useStore(s => s.knowledgeName)
const handleExportImage = useCallback(async (type: 'png' | 'jpeg' | 'svg') => {
if (!appDetail)
if (!appDetail && !knowledgeName)
return
if (getNodesReadOnly())
@ -60,7 +62,7 @@ const ExportImage: FC = () => {
const link = document.createElement('a')
link.href = dataUrl
link.download = `${appDetail.name}.${type}`
link.download = `${appDetail ? appDetail.name : knowledgeName}.${type}`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
@ -68,7 +70,7 @@ const ExportImage: FC = () => {
catch (error) {
console.error('Export image failed:', error)
}
}, [getNodesReadOnly, appDetail])
}, [getNodesReadOnly, appDetail, knowledgeName])
const handleTrigger = useCallback(() => {
if (getNodesReadOnly())

26
web/config/index.spec.ts Normal file
View File

@ -0,0 +1,26 @@
// 写测试用例, VAR_REGEX 能匹配的情况和不能匹配的情况
import { VAR_REGEX, resetReg } from './index'
describe('VAR_REGEX', () => {
it('matched variable names', () => {
const vars = [
// node output variables
'{{#1749783300519.text#}}',
'{{#1749783300519.llm.a#}}',
'{{#1749783300519.llm.a.b.c#}}',
'{{#1749783300519.llm.a#}}',
// system variables
'{{#sys.query#}}',
// conversation variables
'{{#conversation.aaa#}}',
// env variables
'{{#env.a#}}',
// rag variables
'{{#rag.1748945155129.a#}}',
'{{#rag.shared.bbb#}}',
]
vars.forEach((variable) => {
expect(VAR_REGEX.test(variable)).toBe(true)
resetReg()
})
})
})

View File

@ -275,7 +275,7 @@ Thought: {{agent_scratchpad}}
`,
}
export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_]?\w{0,29}){1,10}(\.[a-zA-Z0-9_-]{1,50})?#)\}\}/gi
export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.\d+)?(\.[a-zA-Z_]\w{0,29}){1,10}#)\}\}/gi
export const resetReg = () => VAR_REGEX.lastIndex = 0