mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 18:08:07 +08:00
feat: support choose var in tool config in sandbox prompt editor
This commit is contained in:
@ -267,6 +267,7 @@ const Editor: FC<Props> = ({
|
||||
placeholder={placeholder}
|
||||
placeholderClassName={placeholderClassName}
|
||||
instanceId={instanceId}
|
||||
nodeId={nodeId}
|
||||
compact
|
||||
className={cn('min-h-[56px]', inputClassName)}
|
||||
style={isExpand ? { height: editorExpandHeight - 5 } : {}}
|
||||
|
||||
@ -419,6 +419,7 @@ const ConfigPrompt: FC<Props> = ({
|
||||
<div>
|
||||
<Editor
|
||||
instanceId={`${nodeId}-chat-workflow-llm-prompt-editor`}
|
||||
nodeId={nodeId}
|
||||
title={<span className="capitalize">{t(`${i18nPrefix}.prompt`, { ns: 'workflow' })}</span>}
|
||||
value={((payload as PromptItem).edition_type === EditionType.basic || !(payload as PromptItem).edition_type) ? (payload as PromptItem).text : ((payload as PromptItem).jinja2_text || '')}
|
||||
onChange={handleCompletionPromptChange}
|
||||
|
||||
@ -535,7 +535,10 @@ const ToolBlockComponent = ({
|
||||
currentTool={currentTool}
|
||||
value={toolValue}
|
||||
onChange={handleToolValueChange}
|
||||
nodeId={undefined}
|
||||
nodeId={toolBlockContext?.nodeId}
|
||||
nodesOutputVars={toolBlockContext?.nodesOutputVars}
|
||||
availableNodes={toolBlockContext?.availableNodes}
|
||||
enableVariableReference={useModal}
|
||||
/>
|
||||
{readmeEntrance}
|
||||
</div>
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
import type { Node, NodeOutPutVar } from '@/app/components/workflow/types'
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
type ToolBlockContextValue = {
|
||||
metadata?: Record<string, unknown>
|
||||
onMetadataChange?: (metadata: Record<string, unknown>) => void
|
||||
useModal?: boolean
|
||||
nodeId?: string
|
||||
nodesOutputVars?: NodeOutPutVar[]
|
||||
availableNodes?: Node[]
|
||||
}
|
||||
|
||||
const ToolBlockContext = createContext<ToolBlockContextValue | null>(null)
|
||||
|
||||
@ -611,7 +611,10 @@ const ToolGroupBlockComponent = ({
|
||||
currentTool={currentTool}
|
||||
value={toolValue}
|
||||
onChange={handleToolValueChange}
|
||||
nodeId={undefined}
|
||||
nodeId={toolBlockContext?.nodeId}
|
||||
nodesOutputVars={toolBlockContext?.nodesOutputVars}
|
||||
availableNodes={toolBlockContext?.availableNodes}
|
||||
enableVariableReference={useModal}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import type { Tool } from '@/app/components/tools/types'
|
||||
import type { ToolValue } from '@/app/components/workflow/block-selector/types'
|
||||
import type { ToolWithProvider } from '@/app/components/workflow/types'
|
||||
import type { Node, NodeOutPutVar, ToolWithProvider } from '@/app/components/workflow/types'
|
||||
import * as React from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -34,6 +34,9 @@ type ToolSettingsSectionProps = {
|
||||
currentTool?: Tool
|
||||
value?: ToolValue
|
||||
nodeId?: string
|
||||
nodesOutputVars?: NodeOutPutVar[]
|
||||
availableNodes?: Node[]
|
||||
enableVariableReference?: boolean
|
||||
onChange?: (value: ToolValue) => void
|
||||
}
|
||||
|
||||
@ -42,10 +45,13 @@ const ToolSettingsSection = ({
|
||||
currentTool,
|
||||
value,
|
||||
nodeId,
|
||||
nodesOutputVars,
|
||||
availableNodes,
|
||||
enableVariableReference = false,
|
||||
onChange,
|
||||
}: ToolSettingsSectionProps) => {
|
||||
const { t } = useTranslation()
|
||||
const safeNodeId = nodeId ?? ''
|
||||
const resolvedNodeId = enableVariableReference ? (nodeId || 'workflow') : undefined
|
||||
|
||||
const currentToolSettings = useMemo(() => {
|
||||
if (!currentTool)
|
||||
@ -144,8 +150,10 @@ const ToolSettingsSection = ({
|
||||
value={getSafeConfigValue(value?.settings as ToolConfigValueMap, settingsFormSchemas)}
|
||||
onChange={handleSettingsFormChange}
|
||||
schemas={settingsFormSchemas}
|
||||
nodeId={safeNodeId}
|
||||
disableVariableReference
|
||||
nodeId={resolvedNodeId}
|
||||
nodeOutputVars={nodesOutputVars}
|
||||
availableNodes={availableNodes}
|
||||
disableVariableReference={!enableVariableReference}
|
||||
/>
|
||||
)}
|
||||
{showParamsSection && (
|
||||
@ -153,8 +161,10 @@ const ToolSettingsSection = ({
|
||||
value={getSafeConfigValue(value?.parameters as ToolConfigValueMap, paramsFormSchemas)}
|
||||
onChange={handleParamsFormChange}
|
||||
schemas={paramsFormSchemas}
|
||||
nodeId={safeNodeId}
|
||||
disableVariableReference
|
||||
nodeId={resolvedNodeId}
|
||||
nodeOutputVars={nodesOutputVars}
|
||||
availableNodes={availableNodes}
|
||||
disableVariableReference={!enableVariableReference}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user