mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 15:17:39 +08:00
fix
This commit is contained in:
parent
7cef0fff89
commit
896a29b836
@ -105,7 +105,6 @@ export type PromptEditorProps = {
|
|||||||
errorMessageBlock?: ErrorMessageBlockType
|
errorMessageBlock?: ErrorMessageBlockType
|
||||||
lastRunBlock?: LastRunBlockType
|
lastRunBlock?: LastRunBlockType
|
||||||
isSupportFileVar?: boolean
|
isSupportFileVar?: boolean
|
||||||
isMemorySupported?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PromptEditor: FC<PromptEditorProps> = ({
|
const PromptEditor: FC<PromptEditorProps> = ({
|
||||||
@ -131,7 +130,6 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
|||||||
errorMessageBlock,
|
errorMessageBlock,
|
||||||
lastRunBlock,
|
lastRunBlock,
|
||||||
isSupportFileVar,
|
isSupportFileVar,
|
||||||
isMemorySupported,
|
|
||||||
}) => {
|
}) => {
|
||||||
const { eventEmitter } = useEventEmitterContextContext()
|
const { eventEmitter } = useEventEmitterContextContext()
|
||||||
const initialConfig = {
|
const initialConfig = {
|
||||||
@ -202,7 +200,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
|||||||
}
|
}
|
||||||
ErrorBoundary={LexicalErrorBoundary}
|
ErrorBoundary={LexicalErrorBoundary}
|
||||||
/>
|
/>
|
||||||
{isMemorySupported && workflowVariableBlock?.show && (
|
{workflowVariableBlock?.show && workflowVariableBlock?.isMemorySupported && (
|
||||||
<MemoryPopupPlugin
|
<MemoryPopupPlugin
|
||||||
instanceId={instanceId}
|
instanceId={instanceId}
|
||||||
memoryVariables={workflowVariableBlock?.variables?.find(v => v.nodeId === 'memory_block')?.vars || []}
|
memoryVariables={workflowVariableBlock?.variables?.find(v => v.nodeId === 'memory_block')?.vars || []}
|
||||||
@ -269,7 +267,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
|||||||
{
|
{
|
||||||
workflowVariableBlock?.show && (
|
workflowVariableBlock?.show && (
|
||||||
<>
|
<>
|
||||||
<WorkflowVariableBlock {...workflowVariableBlock} />
|
<WorkflowVariableBlock {...workflowVariableBlock } />
|
||||||
<WorkflowVariableBlockReplacementBlock {...workflowVariableBlock} />
|
<WorkflowVariableBlockReplacementBlock {...workflowVariableBlock} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -283,7 +283,19 @@ export const useOptions = (
|
|||||||
const workflowVariableOptions = useMemo(() => {
|
const workflowVariableOptions = useMemo(() => {
|
||||||
if (!workflowVariableBlockType?.show)
|
if (!workflowVariableBlockType?.show)
|
||||||
return []
|
return []
|
||||||
const res = workflowVariableBlockType.variables || []
|
let res = workflowVariableBlockType.variables || []
|
||||||
|
|
||||||
|
if (!workflowVariableBlockType.isMemorySupported) {
|
||||||
|
res = res.map((v) => {
|
||||||
|
if (v.nodeId === 'conversation') {
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
vars: v.vars.filter(vv => !vv.variable.startsWith('memory_block.')),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
})
|
||||||
|
}
|
||||||
if(errorMessageBlockType?.show && res.findIndex(v => v.nodeId === 'error_message') === -1) {
|
if(errorMessageBlockType?.show && res.findIndex(v => v.nodeId === 'error_message') === -1) {
|
||||||
res.unshift({
|
res.unshift({
|
||||||
nodeId: 'error_message',
|
nodeId: 'error_message',
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import {
|
|||||||
memo,
|
memo,
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -34,12 +35,12 @@ type WorkflowVariableBlockComponentProps = {
|
|||||||
workflowNodesMap: WorkflowNodesMap
|
workflowNodesMap: WorkflowNodesMap
|
||||||
environmentVariables?: Var[]
|
environmentVariables?: Var[]
|
||||||
conversationVariables?: Var[]
|
conversationVariables?: Var[]
|
||||||
memoryVariables?: Var[]
|
|
||||||
ragVariables?: Var[]
|
ragVariables?: Var[]
|
||||||
getVarType?: (payload: {
|
getVarType?: (payload: {
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
valueSelector: ValueSelector,
|
valueSelector: ValueSelector,
|
||||||
}) => Type
|
}) => Type
|
||||||
|
isMemorySupported?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const WorkflowVariableBlockComponent = ({
|
const WorkflowVariableBlockComponent = ({
|
||||||
@ -49,8 +50,8 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
getVarType,
|
getVarType,
|
||||||
environmentVariables,
|
environmentVariables,
|
||||||
conversationVariables,
|
conversationVariables,
|
||||||
memoryVariables,
|
|
||||||
ragVariables,
|
ragVariables,
|
||||||
|
isMemorySupported,
|
||||||
}: WorkflowVariableBlockComponentProps) => {
|
}: WorkflowVariableBlockComponentProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [editor] = useLexicalComposerContext()
|
const [editor] = useLexicalComposerContext()
|
||||||
@ -72,6 +73,8 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
const isMemoryVar = isMemoryVariable(variables)
|
const isMemoryVar = isMemoryVariable(variables)
|
||||||
const isException = isExceptionVariable(varName, node?.type)
|
const isException = isExceptionVariable(varName, node?.type)
|
||||||
|
|
||||||
|
const memoryVariables = conversationVariables?.filter(v => v.variable.startsWith('memory_block.'))
|
||||||
|
|
||||||
let variableValid = true
|
let variableValid = true
|
||||||
if (isEnv) {
|
if (isEnv) {
|
||||||
if (environmentVariables)
|
if (environmentVariables)
|
||||||
@ -84,6 +87,9 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
else if (isMemoryVar) {
|
else if (isMemoryVar) {
|
||||||
if (memoryVariables)
|
if (memoryVariables)
|
||||||
variableValid = memoryVariables.some(v => v.variable === `${variables?.[0] ?? ''}.${variables?.[1] ?? ''}`)
|
variableValid = memoryVariables.some(v => v.variable === `${variables?.[0] ?? ''}.${variables?.[1] ?? ''}`)
|
||||||
|
|
||||||
|
if (!isMemorySupported)
|
||||||
|
variableValid = false
|
||||||
}
|
}
|
||||||
else if (isRagVar) {
|
else if (isRagVar) {
|
||||||
if (ragVariables)
|
if (ragVariables)
|
||||||
@ -133,11 +139,28 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
})
|
})
|
||||||
}, [node, reactflow, store])
|
}, [node, reactflow, store])
|
||||||
|
|
||||||
|
const memoriedVariables = useMemo(() => {
|
||||||
|
if (variables[0] === 'memory_block') {
|
||||||
|
const currentMemoryVariable = memoryVariables?.find(v => v.variable === variables.join('.'))
|
||||||
|
|
||||||
|
if (currentMemoryVariable && currentMemoryVariable.memoryVariableName) {
|
||||||
|
return [
|
||||||
|
'memory_block',
|
||||||
|
currentMemoryVariable.memoryVariableName,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables
|
||||||
|
}, [memoryVariables, variables])
|
||||||
|
|
||||||
const Item = (
|
const Item = (
|
||||||
<VariableLabelInEditor
|
<VariableLabelInEditor
|
||||||
nodeType={node?.type}
|
nodeType={node?.type}
|
||||||
nodeTitle={node?.title}
|
nodeTitle={node?.title}
|
||||||
variables={variables}
|
variables={memoriedVariables}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
handleVariableJump()
|
handleVariableJump()
|
||||||
@ -151,7 +174,7 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
return Item
|
return <div>{Item}</div>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
@ -159,10 +182,10 @@ const WorkflowVariableBlockComponent = ({
|
|||||||
popupContent={
|
popupContent={
|
||||||
<VarFullPathPanel
|
<VarFullPathPanel
|
||||||
nodeName={node.title}
|
nodeName={node.title}
|
||||||
path={variables.slice(1)}
|
path={memoriedVariables.slice(1)}
|
||||||
varType={getVarType ? getVarType({
|
varType={getVarType ? getVarType({
|
||||||
nodeId: variables[0],
|
nodeId: memoriedVariables[0],
|
||||||
valueSelector: variables,
|
valueSelector: memoriedVariables,
|
||||||
}) : Type.string}
|
}) : Type.string}
|
||||||
nodeType={node?.type}
|
nodeType={node?.type}
|
||||||
/>}
|
/>}
|
||||||
|
|||||||
@ -32,9 +32,19 @@ const WorkflowVariableBlock = memo(({
|
|||||||
onInsert,
|
onInsert,
|
||||||
onDelete,
|
onDelete,
|
||||||
getVarType,
|
getVarType,
|
||||||
|
variables: originalVariables,
|
||||||
|
isMemorySupported,
|
||||||
}: WorkflowVariableBlockType) => {
|
}: WorkflowVariableBlockType) => {
|
||||||
const [editor] = useLexicalComposerContext()
|
const [editor] = useLexicalComposerContext()
|
||||||
|
|
||||||
|
const ragVariables = originalVariables?.reduce<any[]>((acc, curr) => {
|
||||||
|
if (curr.nodeId === 'rag')
|
||||||
|
acc.push(...curr.vars)
|
||||||
|
else
|
||||||
|
acc.push(...curr.vars.filter(v => v.isRagVariable))
|
||||||
|
return acc
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
editor.dispatchCommand(UPDATE_WORKFLOW_NODES_MAP, workflowNodesMap)
|
editor.dispatchCommand(UPDATE_WORKFLOW_NODES_MAP, workflowNodesMap)
|
||||||
@ -50,7 +60,7 @@ const WorkflowVariableBlock = memo(({
|
|||||||
INSERT_WORKFLOW_VARIABLE_BLOCK_COMMAND,
|
INSERT_WORKFLOW_VARIABLE_BLOCK_COMMAND,
|
||||||
(variables: string[]) => {
|
(variables: string[]) => {
|
||||||
editor.dispatchCommand(CLEAR_HIDE_MENU_TIMEOUT, undefined)
|
editor.dispatchCommand(CLEAR_HIDE_MENU_TIMEOUT, undefined)
|
||||||
const workflowVariableBlockNode = $createWorkflowVariableBlockNode(variables, workflowNodesMap, getVarType)
|
const workflowVariableBlockNode = $createWorkflowVariableBlockNode(variables, workflowNodesMap, getVarType, originalVariables?.find(o => o.nodeId === 'env')?.vars || [], originalVariables?.find(o => o.nodeId === 'conversation')?.vars || [], ragVariables, isMemorySupported)
|
||||||
|
|
||||||
$insertNodes([workflowVariableBlockNode])
|
$insertNodes([workflowVariableBlockNode])
|
||||||
if (onInsert)
|
if (onInsert)
|
||||||
|
|||||||
@ -13,8 +13,8 @@ export type SerializedNode = SerializedLexicalNode & {
|
|||||||
getVarType?: GetVarType
|
getVarType?: GetVarType
|
||||||
environmentVariables?: Var[]
|
environmentVariables?: Var[]
|
||||||
conversationVariables?: Var[]
|
conversationVariables?: Var[]
|
||||||
memoryVariables?: Var[]
|
|
||||||
ragVariables?: Var[]
|
ragVariables?: Var[]
|
||||||
|
isMemorySupported?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element> {
|
export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element> {
|
||||||
@ -23,8 +23,8 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
|
|||||||
__getVarType?: GetVarType
|
__getVarType?: GetVarType
|
||||||
__environmentVariables?: Var[]
|
__environmentVariables?: Var[]
|
||||||
__conversationVariables?: Var[]
|
__conversationVariables?: Var[]
|
||||||
__memoryVariables?: Var[]
|
|
||||||
__ragVariables?: Var[]
|
__ragVariables?: Var[]
|
||||||
|
__isMemorySupported?: boolean
|
||||||
|
|
||||||
static getType(): string {
|
static getType(): string {
|
||||||
return 'workflow-variable-block'
|
return 'workflow-variable-block'
|
||||||
@ -45,8 +45,8 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
|
|||||||
key?: NodeKey,
|
key?: NodeKey,
|
||||||
environmentVariables?: Var[],
|
environmentVariables?: Var[],
|
||||||
conversationVariables?: Var[],
|
conversationVariables?: Var[],
|
||||||
memoryVariables?: Var[],
|
|
||||||
ragVariables?: Var[],
|
ragVariables?: Var[],
|
||||||
|
isMemorySupported?: boolean,
|
||||||
) {
|
) {
|
||||||
super(key)
|
super(key)
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
|
|||||||
this.__getVarType = getVarType
|
this.__getVarType = getVarType
|
||||||
this.__environmentVariables = environmentVariables
|
this.__environmentVariables = environmentVariables
|
||||||
this.__conversationVariables = conversationVariables
|
this.__conversationVariables = conversationVariables
|
||||||
this.__memoryVariables = memoryVariables
|
|
||||||
this.__ragVariables = ragVariables
|
this.__ragVariables = ragVariables
|
||||||
|
this.__isMemorySupported = isMemorySupported
|
||||||
}
|
}
|
||||||
|
|
||||||
createDOM(): HTMLElement {
|
createDOM(): HTMLElement {
|
||||||
@ -78,14 +78,14 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
|
|||||||
getVarType={this.__getVarType!}
|
getVarType={this.__getVarType!}
|
||||||
environmentVariables={this.__environmentVariables}
|
environmentVariables={this.__environmentVariables}
|
||||||
conversationVariables={this.__conversationVariables}
|
conversationVariables={this.__conversationVariables}
|
||||||
memoryVariables={this.__memoryVariables}
|
|
||||||
ragVariables={this.__ragVariables}
|
ragVariables={this.__ragVariables}
|
||||||
|
isMemorySupported={this.__isMemorySupported}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
static importJSON(serializedNode: SerializedNode): WorkflowVariableBlockNode {
|
static importJSON(serializedNode: SerializedNode): WorkflowVariableBlockNode {
|
||||||
const node = $createWorkflowVariableBlockNode(serializedNode.variables, serializedNode.workflowNodesMap, serializedNode.getVarType, serializedNode.environmentVariables, serializedNode.conversationVariables, serializedNode.ragVariables)
|
const node = $createWorkflowVariableBlockNode(serializedNode.variables, serializedNode.workflowNodesMap, serializedNode.getVarType, serializedNode.environmentVariables, serializedNode.conversationVariables, serializedNode.ragVariables, serializedNode.isMemorySupported)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
@ -99,7 +99,6 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
|
|||||||
getVarType: this.getVarType(),
|
getVarType: this.getVarType(),
|
||||||
environmentVariables: this.getEnvironmentVariables(),
|
environmentVariables: this.getEnvironmentVariables(),
|
||||||
conversationVariables: this.getConversationVariables(),
|
conversationVariables: this.getConversationVariables(),
|
||||||
memoryVariables: this.getMemoryVariables(),
|
|
||||||
ragVariables: this.getRagVariables(),
|
ragVariables: this.getRagVariables(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,22 +128,22 @@ export class WorkflowVariableBlockNode extends DecoratorNode<React.JSX.Element>
|
|||||||
return self.__conversationVariables
|
return self.__conversationVariables
|
||||||
}
|
}
|
||||||
|
|
||||||
getMemoryVariables(): any {
|
|
||||||
const self = this.getLatest()
|
|
||||||
return self.__memoryVariables
|
|
||||||
}
|
|
||||||
|
|
||||||
getRagVariables(): any {
|
getRagVariables(): any {
|
||||||
const self = this.getLatest()
|
const self = this.getLatest()
|
||||||
return self.__ragVariables
|
return self.__ragVariables
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIsMemorySupported() {
|
||||||
|
const self = this.getLatest()
|
||||||
|
return self.__isMemorySupported
|
||||||
|
}
|
||||||
|
|
||||||
getTextContent(): string {
|
getTextContent(): string {
|
||||||
return `{{#${this.getVariables().join('.')}#}}`
|
return `{{#${this.getVariables().join('.')}#}}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function $createWorkflowVariableBlockNode(variables: string[], workflowNodesMap: WorkflowNodesMap, getVarType?: GetVarType, environmentVariables?: Var[], conversationVariables?: Var[], memoryVariables?: Var[], ragVariables?: Var[]): WorkflowVariableBlockNode {
|
export function $createWorkflowVariableBlockNode(variables: string[], workflowNodesMap: WorkflowNodesMap, getVarType?: GetVarType, environmentVariables?: Var[], conversationVariables?: Var[], ragVariables?: Var[], isMemorySupported?: boolean): WorkflowVariableBlockNode {
|
||||||
return new WorkflowVariableBlockNode(variables, workflowNodesMap, getVarType, undefined, environmentVariables, conversationVariables, memoryVariables, ragVariables)
|
return new WorkflowVariableBlockNode(variables, workflowNodesMap, getVarType, undefined, environmentVariables, conversationVariables, ragVariables, isMemorySupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $isWorkflowVariableBlockNode(
|
export function $isWorkflowVariableBlockNode(
|
||||||
|
|||||||
@ -19,6 +19,7 @@ const WorkflowVariableBlockReplacementBlock = ({
|
|||||||
getVarType,
|
getVarType,
|
||||||
onInsert,
|
onInsert,
|
||||||
variables,
|
variables,
|
||||||
|
isMemorySupported,
|
||||||
}: WorkflowVariableBlockType) => {
|
}: WorkflowVariableBlockType) => {
|
||||||
const [editor] = useLexicalComposerContext()
|
const [editor] = useLexicalComposerContext()
|
||||||
const ragVariables = variables?.reduce<any[]>((acc, curr) => {
|
const ragVariables = variables?.reduce<any[]>((acc, curr) => {
|
||||||
@ -28,7 +29,6 @@ const WorkflowVariableBlockReplacementBlock = ({
|
|||||||
acc.push(...curr.vars.filter(v => v.isRagVariable))
|
acc.push(...curr.vars.filter(v => v.isRagVariable))
|
||||||
return acc
|
return acc
|
||||||
}, [])
|
}, [])
|
||||||
const memoryVariables = variables?.find(variable => variable.nodeId === 'memory_block')?.vars || []
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor.hasNodes([WorkflowVariableBlockNode]))
|
if (!editor.hasNodes([WorkflowVariableBlockNode]))
|
||||||
@ -40,7 +40,7 @@ const WorkflowVariableBlockReplacementBlock = ({
|
|||||||
onInsert()
|
onInsert()
|
||||||
|
|
||||||
const nodePathString = textNode.getTextContent().slice(3, -3)
|
const nodePathString = textNode.getTextContent().slice(3, -3)
|
||||||
return $applyNodeReplacement($createWorkflowVariableBlockNode(nodePathString.split('.'), workflowNodesMap, getVarType, variables?.find(o => o.nodeId === 'env')?.vars || [], variables?.find(o => o.nodeId === 'conversation')?.vars || [], memoryVariables, ragVariables))
|
return $applyNodeReplacement($createWorkflowVariableBlockNode(nodePathString.split('.'), workflowNodesMap, getVarType, variables?.find(o => o.nodeId === 'env')?.vars || [], variables?.find(o => o.nodeId === 'conversation')?.vars || [], ragVariables, isMemorySupported))
|
||||||
}, [onInsert, workflowNodesMap, getVarType, variables])
|
}, [onInsert, workflowNodesMap, getVarType, variables])
|
||||||
|
|
||||||
const getMatch = useCallback((text: string) => {
|
const getMatch = useCallback((text: string) => {
|
||||||
|
|||||||
@ -71,6 +71,7 @@ export type WorkflowVariableBlockType = {
|
|||||||
getVarType?: GetVarType
|
getVarType?: GetVarType
|
||||||
showManageInputField?: boolean
|
showManageInputField?: boolean
|
||||||
onManageInputField?: () => void
|
onManageInputField?: () => void
|
||||||
|
isMemorySupported?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MenuTextMatch = {
|
export type MenuTextMatch = {
|
||||||
|
|||||||
@ -297,13 +297,13 @@ const Editor: FC<Props> = ({
|
|||||||
}, {} as any),
|
}, {} as any),
|
||||||
showManageInputField: !!pipelineId,
|
showManageInputField: !!pipelineId,
|
||||||
onManageInputField: () => setShowInputFieldPanel?.(true),
|
onManageInputField: () => setShowInputFieldPanel?.(true),
|
||||||
|
isMemorySupported,
|
||||||
}}
|
}}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onBlur={setBlur}
|
onBlur={setBlur}
|
||||||
onFocus={setFocus}
|
onFocus={setFocus}
|
||||||
editable={!readOnly}
|
editable={!readOnly}
|
||||||
isSupportFileVar={isSupportFileVar}
|
isSupportFileVar={isSupportFileVar}
|
||||||
isMemorySupported
|
|
||||||
/>
|
/>
|
||||||
{/* to patch Editor not support dynamic change editable status */}
|
{/* to patch Editor not support dynamic change editable status */}
|
||||||
{readOnly && <div className='absolute inset-0 z-10'></div>}
|
{readOnly && <div className='absolute inset-0 z-10'></div>}
|
||||||
|
|||||||
@ -39,6 +39,7 @@ type Props = {
|
|||||||
varList: Variable[]
|
varList: Variable[]
|
||||||
handleAddVariable: (payload: any) => void
|
handleAddVariable: (payload: any) => void
|
||||||
modelConfig?: ModelConfig
|
modelConfig?: ModelConfig
|
||||||
|
isMemorySupported?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const roleOptions = [
|
const roleOptions = [
|
||||||
@ -81,6 +82,7 @@ const ConfigPromptItem: FC<Props> = ({
|
|||||||
varList,
|
varList,
|
||||||
handleAddVariable,
|
handleAddVariable,
|
||||||
modelConfig,
|
modelConfig,
|
||||||
|
isMemorySupported,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
@ -156,7 +158,7 @@ const ConfigPromptItem: FC<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
isMemorySupported
|
isMemorySupported={isMemorySupported}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,7 @@ type Props = {
|
|||||||
varList?: Variable[]
|
varList?: Variable[]
|
||||||
handleAddVariable: (payload: any) => void
|
handleAddVariable: (payload: any) => void
|
||||||
modelConfig: ModelConfig
|
modelConfig: ModelConfig
|
||||||
|
isMemorySupported?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConfigPrompt: FC<Props> = ({
|
const ConfigPrompt: FC<Props> = ({
|
||||||
@ -49,6 +50,7 @@ const ConfigPrompt: FC<Props> = ({
|
|||||||
varList = [],
|
varList = [],
|
||||||
handleAddVariable,
|
handleAddVariable,
|
||||||
modelConfig,
|
modelConfig,
|
||||||
|
isMemorySupported,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
@ -205,6 +207,7 @@ const ConfigPrompt: FC<Props> = ({
|
|||||||
varList={varList}
|
varList={varList}
|
||||||
handleAddVariable={handleAddVariable}
|
handleAddVariable={handleAddVariable}
|
||||||
modelConfig={modelConfig}
|
modelConfig={modelConfig}
|
||||||
|
isMemorySupported={isMemorySupported}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@ -241,6 +244,7 @@ const ConfigPrompt: FC<Props> = ({
|
|||||||
handleAddVariable={handleAddVariable}
|
handleAddVariable={handleAddVariable}
|
||||||
onGenerated={handleGenerated}
|
onGenerated={handleGenerated}
|
||||||
modelConfig={modelConfig}
|
modelConfig={modelConfig}
|
||||||
|
isMemorySupported={isMemorySupported}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -155,6 +155,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||||||
varList={inputs.prompt_config?.jinja2_variables || []}
|
varList={inputs.prompt_config?.jinja2_variables || []}
|
||||||
handleAddVariable={handleAddVariable}
|
handleAddVariable={handleAddVariable}
|
||||||
modelConfig={model}
|
modelConfig={model}
|
||||||
|
isMemorySupported={memoryType === MemoryMode.block}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -213,6 +214,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||||||
availableNodes={availableNodesWithParent}
|
availableNodes={availableNodesWithParent}
|
||||||
isSupportFileVar
|
isSupportFileVar
|
||||||
instanceId={`${id}-chat-workflow-llm-prompt-editor-user`}
|
instanceId={`${id}-chat-workflow-llm-prompt-editor-user`}
|
||||||
|
isMemorySupported={memoryType === MemoryMode.block}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{inputs.memory?.query_prompt_template && !inputs.memory.query_prompt_template.includes('{{#sys.query#}}') && (
|
{inputs.memory?.query_prompt_template && !inputs.memory.query_prompt_template.includes('{{#sys.query#}}') && (
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { memo, useState } from 'react'
|
import { memo, useMemo, useState } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
import { capitalize } from 'lodash-es'
|
import { capitalize } from 'lodash-es'
|
||||||
import { RiDeleteBinLine, RiEditLine } from '@remixicon/react'
|
import { RiDeleteBinLine, RiEditLine } from '@remixicon/react'
|
||||||
import {
|
import {
|
||||||
@ -27,7 +28,13 @@ const VariableItem = ({
|
|||||||
term,
|
term,
|
||||||
currentVarId,
|
currentVarId,
|
||||||
}: VariableItemProps) => {
|
}: VariableItemProps) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
const [destructive, setDestructive] = useState(false)
|
const [destructive, setDestructive] = useState(false)
|
||||||
|
const valueType = useMemo(() => {
|
||||||
|
if (item.value_type === ChatVarType.Memory)
|
||||||
|
return 'memory'
|
||||||
|
return item.value_type
|
||||||
|
}, [item.value_type])
|
||||||
return (
|
return (
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
'radius-md mb-1 border border-components-panel-border-subtle bg-components-panel-on-panel-item-bg px-2.5 py-2 shadow-xs hover:bg-components-panel-on-panel-item-bg-hover',
|
'radius-md mb-1 border border-components-panel-border-subtle bg-components-panel-on-panel-item-bg px-2.5 py-2 shadow-xs hover:bg-components-panel-on-panel-item-bg-hover',
|
||||||
@ -46,7 +53,7 @@ const VariableItem = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
<div className='system-sm-medium text-text-primary'>{item.name}</div>
|
<div className='system-sm-medium text-text-primary'>{item.name}</div>
|
||||||
<div className='system-xs-medium text-text-tertiary'>{capitalize(item.value_type)}</div>
|
<div className='system-xs-medium text-text-tertiary'>{capitalize(valueType)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex shrink-0 items-center gap-1 text-text-tertiary'>
|
<div className='flex shrink-0 items-center gap-1 text-text-tertiary'>
|
||||||
<div className={cn('radius-md hidden cursor-pointer p-1 hover:bg-state-base-hover hover:text-text-secondary group-hover:block', currentVarId === item.id && 'block bg-state-base-hover text-text-secondary')}>
|
<div className={cn('radius-md hidden cursor-pointer p-1 hover:bg-state-base-hover hover:text-text-secondary group-hover:block', currentVarId === item.id && 'block bg-state-base-hover text-text-secondary')}>
|
||||||
@ -60,7 +67,7 @@ const VariableItem = ({
|
|||||||
<RiDeleteBinLine className='h-4 w-4' onClick={() => onDelete(item)}/>
|
<RiDeleteBinLine className='h-4 w-4' onClick={() => onDelete(item)}/>
|
||||||
</div>
|
</div>
|
||||||
<div className={cn('flex h-6 items-center gap-0.5 group-hover:hidden', currentVarId === item.id && 'hidden')}>
|
<div className={cn('flex h-6 items-center gap-0.5 group-hover:hidden', currentVarId === item.id && 'hidden')}>
|
||||||
{scope && <Badge text={scope} />}
|
{scope === 'app' && <Badge text={'conv'} />}
|
||||||
{term && <Badge text={term} />}
|
{term && <Badge text={term} />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -70,6 +77,11 @@ const VariableItem = ({
|
|||||||
<div className='system-xs-regular truncate text-text-tertiary'>{item.description}</div>
|
<div className='system-xs-regular truncate text-text-tertiary'>{item.description}</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
scope === 'app' && (
|
||||||
|
<div className='system-xs-regular truncate text-text-tertiary'>{t('workflow.chatVariable.appScopeText')}</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -236,7 +236,7 @@ const ChatVariablePanel = () => {
|
|||||||
onEdit={handleEdit}
|
onEdit={handleEdit}
|
||||||
onDelete={deleteCheck}
|
onDelete={deleteCheck}
|
||||||
term={memoryVariable.term}
|
term={memoryVariable.term}
|
||||||
scope='conv'
|
scope='app'
|
||||||
currentVarId={currentVar?.id}
|
currentVarId={currentVar?.id}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
|
|||||||
@ -311,7 +311,7 @@ Thought: {{agent_scratchpad}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const VAR_REGEX
|
export const VAR_REGEX
|
||||||
= /\{\{(#[a-zA-Z0-9_-]{1,50}(\.\d+)?(\.[a-zA-Z_]\w{0,29}){1,10}#)\}\}/gi
|
= /\{\{(#[\w-]{1,50}(?:\.\w+(?:\.[a-zA-Z_]\w{0,29}){0,10}|\.[a-zA-Z_]\w{0,29}(?:\.[a-zA-Z_]\w{0,29}){0,9})#)\}\}/gi
|
||||||
|
|
||||||
export const resetReg = () => (VAR_REGEX.lastIndex = 0)
|
export const resetReg = () => (VAR_REGEX.lastIndex = 0)
|
||||||
|
|
||||||
|
|||||||
@ -150,6 +150,7 @@ const translation = {
|
|||||||
docLink: 'Visit our docs to learn more.',
|
docLink: 'Visit our docs to learn more.',
|
||||||
button: 'Add Variable',
|
button: 'Add Variable',
|
||||||
nodeScopeMemory: 'Node Scope Memory',
|
nodeScopeMemory: 'Node Scope Memory',
|
||||||
|
appScopeText: 'Conversation History',
|
||||||
modal: {
|
modal: {
|
||||||
title: 'Add Conversation Variable',
|
title: 'Add Conversation Variable',
|
||||||
editTitle: 'Edit Conversation Variable',
|
editTitle: 'Edit Conversation Variable',
|
||||||
|
|||||||
@ -150,6 +150,7 @@ const translation = {
|
|||||||
docLink: '查看文档了解更多。',
|
docLink: '查看文档了解更多。',
|
||||||
button: '添加变量',
|
button: '添加变量',
|
||||||
nodeScopeMemory: '节点范围记忆',
|
nodeScopeMemory: '节点范围记忆',
|
||||||
|
appScopeText: '会话历史',
|
||||||
modal: {
|
modal: {
|
||||||
title: '添加会话变量',
|
title: '添加会话变量',
|
||||||
editTitle: '编辑会话变量',
|
editTitle: '编辑会话变量',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user