diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index 64df9b22b5..a10b0c67d6 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -49,6 +49,7 @@ export type PromptEditorProps = { value?: string editable?: boolean outToolDisabled?: boolean + canNotAddContext?: boolean onChange?: (text: string) => void onBlur?: () => void onFocus?: () => void @@ -88,6 +89,7 @@ const PromptEditor: FC = ({ value, editable = true, outToolDisabled = false, + canNotAddContext = false, onChange, onBlur, onFocus, @@ -190,11 +192,13 @@ const PromptEditor: FC = ({ onAddContext={contextBlock.onAddContext} onInsert={contextBlock.onInsert} onDelete={contextBlock.onDelete} + canNotAddContext={canNotAddContext} /> ) diff --git a/web/app/components/base/prompt-editor/plugins/context-block-replacement-block.tsx b/web/app/components/base/prompt-editor/plugins/context-block-replacement-block.tsx index 0b591b08cf..b08c08058f 100644 --- a/web/app/components/base/prompt-editor/plugins/context-block-replacement-block.tsx +++ b/web/app/components/base/prompt-editor/plugins/context-block-replacement-block.tsx @@ -21,6 +21,7 @@ const ContextBlockReplacementBlock: FC = ({ datasets, onAddContext, onInsert, + canNotAddContext, }) => { const [editor] = useLexicalComposerContext() @@ -32,7 +33,7 @@ const ContextBlockReplacementBlock: FC = ({ const createContextBlockNode = useCallback((): ContextBlockNode => { if (onInsert) onInsert() - return $applyNodeReplacement($createContextBlockNode(datasets, onAddContext)) + return $applyNodeReplacement($createContextBlockNode(datasets, onAddContext, canNotAddContext)) }, [datasets, onAddContext, onInsert]) const getMatch = useCallback((text: string) => { diff --git a/web/app/components/base/prompt-editor/plugins/context-block/component.tsx b/web/app/components/base/prompt-editor/plugins/context-block/component.tsx index 098762b034..2741850b4c 100644 --- a/web/app/components/base/prompt-editor/plugins/context-block/component.tsx +++ b/web/app/components/base/prompt-editor/plugins/context-block/component.tsx @@ -18,12 +18,14 @@ type ContextBlockComponentProps = { nodeKey: string datasets?: Dataset[] onAddContext: () => void + canNotAddContext?: boolean } const ContextBlockComponent: FC = ({ nodeKey, datasets = [], onAddContext, + canNotAddContext, }) => { const { t } = useTranslation() const [ref, isSelected] = useSelectOrDelete(nodeKey, DELETE_CONTEXT_BLOCK_COMMAND) @@ -44,52 +46,55 @@ const ContextBlockComponent: FC = ({ `} ref={ref}>
{t('common.promptEditor.context.item.title')}
- - -
+ +
{localDatasets.length}
-
- -
-
-
- {t('common.promptEditor.context.modal.title', { num: localDatasets.length })} -
-
- { - localDatasets.map(dataset => ( -
-
- -
-
{dataset.name}
-
- )) - } -
-
-
- + + +
+
+
+ {t('common.promptEditor.context.modal.title', { num: localDatasets.length })}
-
{t('common.promptEditor.context.modal.add')}
+
+ { + localDatasets.map(dataset => ( +
+
+ +
+
{dataset.name}
+
+ )) + } +
+
+
+ +
+
{t('common.promptEditor.context.modal.add')}
+
+
+
+ {t('common.promptEditor.context.modal.footer')}
-
- {t('common.promptEditor.context.modal.footer')} -
-
- - + + + )} +
) } diff --git a/web/app/components/base/prompt-editor/plugins/context-block/index.tsx b/web/app/components/base/prompt-editor/plugins/context-block/index.tsx index f646902b9a..98f825a7ec 100644 --- a/web/app/components/base/prompt-editor/plugins/context-block/index.tsx +++ b/web/app/components/base/prompt-editor/plugins/context-block/index.tsx @@ -26,12 +26,14 @@ export type ContextBlockProps = { onAddContext: () => void onInsert?: () => void onDelete?: () => void + canNotAddContext?: boolean } const ContextBlock: FC = ({ datasets, onAddContext, onInsert, onDelete, + canNotAddContext, }) => { const [editor] = useLexicalComposerContext() @@ -43,7 +45,7 @@ const ContextBlock: FC = ({ editor.registerCommand( INSERT_CONTEXT_BLOCK_COMMAND, () => { - const contextBlockNode = $createContextBlockNode(datasets, onAddContext) + const contextBlockNode = $createContextBlockNode(datasets, onAddContext, canNotAddContext) $insertNodes([contextBlockNode]) diff --git a/web/app/components/base/prompt-editor/plugins/context-block/node.tsx b/web/app/components/base/prompt-editor/plugins/context-block/node.tsx index c1146499bc..4bcd49b678 100644 --- a/web/app/components/base/prompt-editor/plugins/context-block/node.tsx +++ b/web/app/components/base/prompt-editor/plugins/context-block/node.tsx @@ -3,11 +3,12 @@ import { DecoratorNode } from 'lexical' import ContextBlockComponent from './component' import type { Dataset } from './index' -export type SerializedNode = SerializedLexicalNode & { datasets: Dataset[]; onAddContext: () => void } +export type SerializedNode = SerializedLexicalNode & { datasets: Dataset[]; onAddContext: () => void; canNotAddContext: boolean } export class ContextBlockNode extends DecoratorNode { __datasets: Dataset[] __onAddContext: () => void + __canNotAddContext: boolean static getType(): string { return 'context-block' @@ -21,11 +22,12 @@ export class ContextBlockNode extends DecoratorNode { return true } - constructor(datasets: Dataset[], onAddContext: () => void, key?: NodeKey) { + constructor(datasets: Dataset[], onAddContext: () => void, key?: NodeKey, canNotAddContext?: boolean) { super(key) this.__datasets = datasets this.__onAddContext = onAddContext + this.__canNotAddContext = canNotAddContext || false } createDOM(): HTMLElement { @@ -44,6 +46,7 @@ export class ContextBlockNode extends DecoratorNode { nodeKey={this.getKey()} datasets={this.getDatasets()} onAddContext={this.getOnAddContext()} + canNotAddContext={this.__canNotAddContext} /> ) } @@ -61,7 +64,7 @@ export class ContextBlockNode extends DecoratorNode { } static importJSON(serializedNode: SerializedNode): ContextBlockNode { - const node = $createContextBlockNode(serializedNode.datasets, serializedNode.onAddContext) + const node = $createContextBlockNode(serializedNode.datasets, serializedNode.onAddContext, serializedNode.canNotAddContext) return node } @@ -72,6 +75,7 @@ export class ContextBlockNode extends DecoratorNode { version: 1, datasets: this.getDatasets(), onAddContext: this.getOnAddContext(), + canNotAddContext: this.__canNotAddContext, } } @@ -79,8 +83,8 @@ export class ContextBlockNode extends DecoratorNode { return '{{#context#}}' } } -export function $createContextBlockNode(datasets: Dataset[], onAddContext: () => void): ContextBlockNode { - return new ContextBlockNode(datasets, onAddContext) +export function $createContextBlockNode(datasets: Dataset[], onAddContext: () => void, canNotAddContext?: boolean): ContextBlockNode { + return new ContextBlockNode(datasets, onAddContext, undefined, canNotAddContext) } export function $isContextBlockNode( diff --git a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx index 87ec9a2e69..1772b005fa 100644 --- a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx +++ b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx @@ -118,6 +118,7 @@ const Editor: FC = ({ style={isExpand ? { height: editorExpandHeight - 5 } : {}} value={value} outToolDisabled + canNotAddContext contextBlock={{ show: justVar ? false : isShowContext, selectable: !hasSetBlockStatus?.context, diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 6f4a066ffb..7c7a744da3 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -167,7 +167,7 @@ const Panel: FC> = ({ readOnly={readOnly} isChatModel={isChatModel} isChatApp={isChatMode} - isShowContext={inputs.context?.variable_selector?.length > 0} + isShowContext payload={inputs.prompt_template} variables={inputs.variables.map(item => item.variable)} onChange={handlePromptChange}