Unverified Commit 9beefd7d authored by zxhlyh's avatar zxhlyh Committed by GitHub

fix: auto prompt (#2768)

parent 88145efa
......@@ -26,6 +26,7 @@ import { ArrowNarrowRight } from '@/app/components/base/icons/src/vender/line/ar
import { useEventEmitterContextContext } from '@/context/event-emitter'
import { ADD_EXTERNAL_DATA_TOOL } from '@/app/components/app/configuration/config-var'
import { INSERT_VARIABLE_VALUE_BLOCK_COMMAND } from '@/app/components/base/prompt-editor/plugins/variable-block'
import { PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER } from '@/app/components/base/prompt-editor/plugins/update-block'
export type ISimplePromptInput = {
mode: AppType
......@@ -125,6 +126,10 @@ const Prompt: FC<ISimplePromptInput> = ({
if (mode === AppType.chat)
setIntroduction(res.opening_statement)
showAutomaticFalse()
eventEmitter?.emit({
type: PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER,
payload: res.prompt,
} as any)
}
const minHeight = 228
const [editorHeight, setEditorHeight] = useState(minHeight)
......
......@@ -32,6 +32,7 @@ import VariableValueBlock from './plugins/variable-value-block'
import { VariableValueBlockNode } from './plugins/variable-value-block/node'
import { CustomTextNode } from './plugins/custom-text/node'
import OnBlurBlock from './plugins/on-blur-block'
import UpdateBlock from './plugins/update-block'
import { textToEditorState } from './utils'
import type { Dataset } from './plugins/context-block'
import type { RoleName } from './plugins/history-block'
......@@ -222,6 +223,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
<VariableValueBlock />
<OnChangePlugin onChange={handleEditorChange} />
<OnBlurBlock onBlur={onBlur} />
<UpdateBlock />
{/* <TreeView /> */}
</div>
</LexicalComposer>
......
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { textToEditorState } from '../utils'
import { useEventEmitterContextContext } from '@/context/event-emitter'
export const PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER = 'PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER'
const UpdateBlock = () => {
const { eventEmitter } = useEventEmitterContextContext()
const [editor] = useLexicalComposerContext()
eventEmitter?.useSubscription((v: any) => {
if (v.type === PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER) {
const editorState = editor.parseEditorState(textToEditorState(v.payload))
editor.setEditorState(editorState)
}
})
return null
}
export default UpdateBlock
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment