mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00

* feat: stop toolCall and rename some field. (#46) * perf: node delete tip;pay tip * fix: toolCall cannot save child answer * feat: stop tool * fix: team modal * fix feckbackMoal auth bug (#47) * 简单的支持提示词运行tool。优化workflow模板 (#49) * remove templates * fix: request body undefined * feat: prompt tool run * feat: workflow tamplates modal * perf: plugin start * 4.7 (#50) * fix docker-compose download url (#994) original code is a bad url with '404 NOT FOUND' return. fix docker-compose download url, add 'v' before docker-compose version * Update ai_settings.md (#1000) * Update configuration.md * Update configuration.md * Fix history in classifyQuestion and extract modules (#1012) * Fix history in classifyQuestion and extract modules * Add chatValue2RuntimePrompt import and update text formatting * flow controller to packages * fix: rerank select * modal ui * perf: modal code path * point not sufficient * feat: http url support variable * fix http key * perf: prompt * perf: ai setting modal * simple edit ui --------- Co-authored-by: entorick <entorick11@qq.com> Co-authored-by: liujianglc <liujianglc@163.com> Co-authored-by: Fengrui Liu <liufengrui.work@bytedance.com> * fix team share redirect to login (#51) * feat: support openapi import plugins (#48) * feat: support openapi import plugins * feat: import from url * fix: add body params parse * fix build * fix * fix * fix * tool box ui (#52) * fix: training queue * feat: simple edit tool select * perf: simple edit dataset prompt * fix: chatbox tool ux * feat: quote prompt module * perf: plugin tools sign * perf: model avatar * tool selector ui * feat: max histories * perf: http plugin import (#53) * perf: plugin http import * chatBox ui * perf: name * fix: Node template card (#54) * fix: ts * setting modal * package * package * feat: add plugins search (#57) * feat: add plugins search * perf: change http plugin header input * Yjl (#56) * perf: prompt tool call * perf: chat box ux * doc * doc * price tip * perf: tool selector * ui' * fix: vector queue * fix: empty tool and empty response * fix: empty msg * perf: pg index * perf: ui tip * doc * tool tip --------- Co-authored-by: yst <77910600+yu-and-liu@users.noreply.github.com> Co-authored-by: entorick <entorick11@qq.com> Co-authored-by: liujianglc <liujianglc@163.com> Co-authored-by: Fengrui Liu <liufengrui.work@bytedance.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
131 lines
4.3 KiB
TypeScript
131 lines
4.3 KiB
TypeScript
import { useState, useRef, useTransition, useEffect, useMemo } from 'react';
|
|
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
import { PlainTextPlugin } from '@lexical/react/LexicalPlainTextPlugin';
|
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
import { Box } from '@chakra-ui/react';
|
|
import styles from './index.module.scss';
|
|
import { EditorState, LexicalEditor } from 'lexical';
|
|
import { getNanoid } from '@fastgpt/global/common/string/tools';
|
|
import { EditorVariablePickerType } from '../../Textarea/PromptEditor/type';
|
|
import { VariableNode } from '../../Textarea/PromptEditor/plugins/VariablePlugin/node';
|
|
import { textToEditorState } from '../../Textarea/PromptEditor/utils';
|
|
import DropDownMenu from '../../Textarea/PromptEditor/modules/DropDownMenu';
|
|
import { SingleLinePlugin } from '../../Textarea/PromptEditor/plugins/SingleLinePlugin';
|
|
import OnBlurPlugin from '../../Textarea/PromptEditor/plugins/OnBlurPlugin';
|
|
import VariablePlugin from '../../Textarea/PromptEditor/plugins/VariablePlugin';
|
|
import VariablePickerPlugin from '../../Textarea/PromptEditor/plugins/VariablePickerPlugin';
|
|
import FocusPlugin from '../../Textarea/PromptEditor/plugins/FocusPlugin';
|
|
|
|
export default function Editor({
|
|
h = 40,
|
|
hasVariablePlugin = true,
|
|
hasDropDownPlugin = false,
|
|
variables,
|
|
onChange,
|
|
onBlur,
|
|
value,
|
|
currentValue,
|
|
placeholder = '',
|
|
setDropdownValue,
|
|
updateTrigger
|
|
}: {
|
|
h?: number;
|
|
hasVariablePlugin?: boolean;
|
|
hasDropDownPlugin?: boolean;
|
|
variables: EditorVariablePickerType[];
|
|
onChange?: (editorState: EditorState) => void;
|
|
onBlur?: (editor: LexicalEditor) => void;
|
|
value?: string;
|
|
currentValue?: string;
|
|
placeholder?: string;
|
|
setDropdownValue?: (value: string) => void;
|
|
updateTrigger?: boolean;
|
|
}) {
|
|
const [key, setKey] = useState(getNanoid(6));
|
|
const [_, startSts] = useTransition();
|
|
const [focus, setFocus] = useState(false);
|
|
|
|
const initialConfig = {
|
|
namespace: 'HttpInput',
|
|
nodes: [VariableNode],
|
|
editorState: textToEditorState(value),
|
|
onError: (error: Error) => {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (focus) return;
|
|
setKey(getNanoid(6));
|
|
}, [value, variables.length]);
|
|
|
|
useEffect(() => {
|
|
setKey(getNanoid(6));
|
|
setFocus(false);
|
|
}, [updateTrigger]);
|
|
|
|
const dropdownVariables = useMemo(
|
|
() =>
|
|
variables.filter((item) => {
|
|
const key = item.key.toLowerCase();
|
|
const current = currentValue?.toLowerCase();
|
|
return key.includes(current || '') && item.key !== currentValue;
|
|
}),
|
|
[currentValue, variables]
|
|
);
|
|
|
|
return (
|
|
<Box position={'relative'} width={'full'} h={`${h}px`} cursor={'text'} overflowY={'visible'}>
|
|
<LexicalComposer initialConfig={initialConfig} key={key}>
|
|
<PlainTextPlugin
|
|
contentEditable={<ContentEditable className={styles.contentEditable} />}
|
|
placeholder={
|
|
<Box
|
|
position={'absolute'}
|
|
top={0}
|
|
left={0}
|
|
right={0}
|
|
bottom={0}
|
|
py={3}
|
|
px={2}
|
|
pointerEvents={'none'}
|
|
overflow={'overlay'}
|
|
>
|
|
<Box
|
|
color={'myGray.500'}
|
|
fontSize={'xs'}
|
|
userSelect={'none'}
|
|
whiteSpace={'pre-wrap'}
|
|
wordBreak={'break-all'}
|
|
h={'100%'}
|
|
>
|
|
{placeholder}
|
|
</Box>
|
|
</Box>
|
|
}
|
|
ErrorBoundary={LexicalErrorBoundary}
|
|
/>
|
|
<HistoryPlugin />
|
|
<FocusPlugin focus={focus} setFocus={setFocus} />
|
|
<OnChangePlugin
|
|
onChange={(e) => {
|
|
startSts(() => {
|
|
onChange?.(e);
|
|
});
|
|
}}
|
|
/>
|
|
{hasVariablePlugin ? <VariablePickerPlugin variables={variables} /> : ''}
|
|
<VariablePlugin variables={variables} />
|
|
<OnBlurPlugin onBlur={onBlur} />
|
|
<SingleLinePlugin />
|
|
</LexicalComposer>
|
|
{focus && hasDropDownPlugin && (
|
|
<DropDownMenu variables={dropdownVariables} setDropdownValue={setDropdownValue} />
|
|
)}
|
|
</Box>
|
|
);
|
|
}
|