feat(workflow): add disableVariableInsertion prop to form input and trigger components

This commit is contained in:
zhsama 2025-10-15 18:20:13 +08:00
parent c03b790888
commit 729e0e9b1e
6 changed files with 37 additions and 15 deletions

View File

@ -42,6 +42,7 @@ type Props = {
onManageInputField?: () => void
extraParams?: Record<string, any>
providerType?: string
disableVariableInsertion?: boolean
}
const FormInputItem: FC<Props> = ({
@ -57,6 +58,7 @@ const FormInputItem: FC<Props> = ({
onManageInputField,
extraParams,
providerType,
disableVariableInsertion = false,
}) => {
const language = useLanguage()
const [toolsOptions, setToolsOptions] = useState<FormOption[] | null>(null)
@ -286,6 +288,7 @@ const FormInputItem: FC<Props> = ({
availableNodes={availableNodesWithParent}
showManageInputField={showManageInputField}
onManageInputField={onManageInputField}
disableVariableInsertion={disableVariableInsertion}
/>
)}
{isNumber && isConstant && (

View File

@ -20,6 +20,7 @@ type MixedVariableTextInputProps = {
onChange?: (text: string) => void
showManageInputField?: boolean
onManageInputField?: () => void
disableVariableInsertion?: boolean
}
const MixedVariableTextInput = ({
readOnly = false,
@ -29,6 +30,7 @@ const MixedVariableTextInput = ({
onChange,
showManageInputField,
onManageInputField,
disableVariableInsertion = false,
}: MixedVariableTextInputProps) => {
const { t } = useTranslation()
const controlPromptEditorRerenderKey = useStore(s => s.controlPromptEditorRerenderKey)
@ -37,7 +39,7 @@ const MixedVariableTextInput = ({
<PromptEditor
key={controlPromptEditorRerenderKey}
wrapperClassName={cn(
'w-full rounded-lg border border-transparent bg-components-input-bg-normal px-2 py-1',
'min-h-8 w-full rounded-lg border border-transparent bg-components-input-bg-normal px-2 py-1',
'hover:border-components-input-border-hover hover:bg-components-input-bg-hover',
'focus-within:border-components-input-border-active focus-within:bg-components-input-bg-active focus-within:shadow-xs',
)}
@ -45,7 +47,7 @@ const MixedVariableTextInput = ({
editable={!readOnly}
value={value}
workflowVariableBlock={{
show: true,
show: !disableVariableInsertion,
variables: nodesOutputVars || [],
workflowNodesMap: availableNodes.reduce((acc, node) => {
acc[node.id] = {
@ -63,7 +65,7 @@ const MixedVariableTextInput = ({
showManageInputField,
onManageInputField,
}}
placeholder={<Placeholder />}
placeholder={<Placeholder disableVariableInsertion={disableVariableInsertion} />}
onChange={onChange}
/>
)

View File

@ -6,7 +6,11 @@ import { $insertNodes } from 'lexical'
import { CustomTextNode } from '@/app/components/base/prompt-editor/plugins/custom-text/node'
import Badge from '@/app/components/base/badge'
const Placeholder = () => {
type PlaceholderProps = {
disableVariableInsertion?: boolean
}
const Placeholder = ({ disableVariableInsertion = false }: PlaceholderProps) => {
const { t } = useTranslation()
const [editor] = useLexicalComposerContext()
@ -28,17 +32,21 @@ const Placeholder = () => {
>
<div className='flex grow items-center'>
{t('workflow.nodes.tool.insertPlaceholder1')}
<div className='system-kbd mx-0.5 flex h-4 w-4 items-center justify-center rounded bg-components-kbd-bg-gray text-text-placeholder'>/</div>
<div
className='system-sm-regular cursor-pointer text-components-input-text-placeholder underline decoration-dotted decoration-auto underline-offset-auto hover:text-text-tertiary'
onMouseDown={((e) => {
e.preventDefault()
e.stopPropagation()
handleInsert('/')
})}
>
{t('workflow.nodes.tool.insertPlaceholder2')}
</div>
{(!disableVariableInsertion) && (
<>
<div className='system-kbd mx-0.5 flex h-4 w-4 items-center justify-center rounded bg-components-kbd-bg-gray text-text-placeholder'>/</div>
<div
className='system-sm-regular cursor-pointer text-components-input-text-placeholder underline decoration-dotted decoration-auto underline-offset-auto hover:text-text-tertiary'
onMouseDown={((e) => {
e.preventDefault()
e.stopPropagation()
handleInsert('/')
})}
>
{t('workflow.nodes.tool.insertPlaceholder2')}
</div>
</>
)}
</div>
<Badge
className='shrink-0'

View File

@ -17,6 +17,7 @@ type Props = {
currentTrigger?: Event
currentProvider?: TriggerWithProvider
extraParams?: Record<string, any>
disableVariableInsertion?: boolean
}
const TriggerForm: FC<Props> = ({
@ -29,6 +30,7 @@ const TriggerForm: FC<Props> = ({
currentTrigger,
currentProvider,
extraParams,
disableVariableInsertion = false,
}) => {
return (
<div className='space-y-1'>
@ -45,6 +47,7 @@ const TriggerForm: FC<Props> = ({
currentTrigger={currentTrigger}
currentProvider={currentProvider}
extraParams={extraParams}
disableVariableInsertion={disableVariableInsertion}
/>
))
}

View File

@ -25,6 +25,7 @@ type Props = {
currentTrigger?: Event
currentProvider?: TriggerWithProvider
extraParams?: Record<string, any>
disableVariableInsertion?: boolean
}
const TriggerFormItem: FC<Props> = ({
@ -37,6 +38,7 @@ const TriggerFormItem: FC<Props> = ({
currentTrigger,
currentProvider,
extraParams,
disableVariableInsertion = false,
}) => {
const language = useLanguage()
const { name, label, type, required, tooltip, input_schema } = schema
@ -93,6 +95,7 @@ const TriggerFormItem: FC<Props> = ({
currentProvider={currentProvider}
providerType='trigger'
extraParams={extraParams}
disableVariableInsertion={disableVariableInsertion}
/>
{isShowSchema && (

View File

@ -8,6 +8,7 @@ import useConfig from './use-config'
import TriggerForm from './components/trigger-form'
import StructureOutputItem from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show'
import { Type } from '../llm/types'
import { BlockEnum } from '@/app/components/workflow/types'
const Panel: FC<NodePanelProps<PluginTriggerNodeType>> = ({
id,
@ -24,6 +25,7 @@ const Panel: FC<NodePanelProps<PluginTriggerNodeType>> = ({
currentProvider,
currentTrigger,
} = useConfig(id, data)
const disableVariableInsertion = data.type === BlockEnum.TriggerPlugin
// Convert output schema to VarItem format
const outputVars = Object.entries(outputSchema.properties || {}).map(([name, schema]: [string, any]) => ({
@ -46,6 +48,7 @@ const Panel: FC<NodePanelProps<PluginTriggerNodeType>> = ({
onChange={setTriggerParameterValue}
currentProvider={currentProvider}
currentTrigger={currentTrigger}
disableVariableInsertion={disableVariableInsertion}
/>
</div>
<Split />