fix: prompt-editor regex.lastIndex needed to reset (#9097)

Co-authored-by: Chen(MAC) <chenchen404@outlook.com>
This commit is contained in:
Pika 2024-10-09 10:22:20 +08:00 committed by GitHub
parent 3a0734d94c
commit 0540995e5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View File

@ -12,7 +12,7 @@ import type { WorkflowVariableBlockType } from '../../types'
import { CustomTextNode } from '../custom-text/node' import { CustomTextNode } from '../custom-text/node'
import { $createWorkflowVariableBlockNode } from './node' import { $createWorkflowVariableBlockNode } from './node'
import { WorkflowVariableBlockNode } from './index' import { WorkflowVariableBlockNode } from './index'
import { VAR_REGEX as REGEX } from '@/config' import { VAR_REGEX as REGEX, resetReg } from '@/config'
const WorkflowVariableBlockReplacementBlock = ({ const WorkflowVariableBlockReplacementBlock = ({
workflowNodesMap, workflowNodesMap,
@ -48,11 +48,12 @@ const WorkflowVariableBlockReplacementBlock = ({
}, []) }, [])
const transformListener = useCallback((textNode: any) => { const transformListener = useCallback((textNode: any) => {
resetReg()
return decoratorTransform(textNode, getMatch, createWorkflowVariableBlockNode) return decoratorTransform(textNode, getMatch, createWorkflowVariableBlockNode)
}, [createWorkflowVariableBlockNode, getMatch]) }, [createWorkflowVariableBlockNode, getMatch])
useEffect(() => { useEffect(() => {
REGEX.lastIndex = 0 resetReg()
return mergeRegister( return mergeRegister(
editor.registerNodeTransform(CustomTextNode, transformListener), editor.registerNodeTransform(CustomTextNode, transformListener),
) )

View File

@ -246,6 +246,8 @@ Thought: {{agent_scratchpad}}
export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}/gi export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}/gi
export const resetReg = () => VAR_REGEX.lastIndex = 0
export let textGenerationTimeoutMs = 60000 export let textGenerationTimeoutMs = 60000
if (process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS && process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS !== '') if (process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS && process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS !== '')