mirror of
https://github.com/langgenius/dify.git
synced 2026-03-13 02:57:41 +08:00
Merge remote-tracking branch 'origin/feat/support-agent-sandbox' into pre-align-hitl-frontend
This commit is contained in:
@ -20,6 +20,7 @@ import type {
|
||||
VariableBlockType,
|
||||
WorkflowVariableBlockType,
|
||||
} from './types'
|
||||
import type { EventPayload } from '@/context/event-emitter'
|
||||
import { CodeNode } from '@lexical/code'
|
||||
import { LexicalComposer } from '@lexical/react/LexicalComposer'
|
||||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||
@ -51,17 +52,18 @@ import { ToolBlockContextProvider } from '@/app/components/workflow/skill/editor
|
||||
import ToolPickerBlock from '@/app/components/workflow/skill/editor/skill-editor/plugins/tool-block/tool-picker-block'
|
||||
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
||||
import { cn } from '@/utils/classnames'
|
||||
import { useWorkflow } from '../../workflow/hooks'
|
||||
import {
|
||||
UPDATE_DATASETS_EVENT_EMITTER,
|
||||
UPDATE_HISTORY_EVENT_EMITTER,
|
||||
} from './constants'
|
||||
|
||||
import ComponentPickerBlock from './plugins/component-picker-block'
|
||||
import {
|
||||
ContextBlock,
|
||||
ContextBlockNode,
|
||||
ContextBlockReplacementBlock,
|
||||
} from './plugins/context-block'
|
||||
|
||||
import {
|
||||
CurrentBlock,
|
||||
CurrentBlockNode,
|
||||
@ -169,6 +171,7 @@ const EnterCommandPlugin: FC<{ onEnter?: (event: KeyboardEvent) => void }> = ({
|
||||
|
||||
export type PromptEditorProps = {
|
||||
instanceId?: string
|
||||
nodeId?: string
|
||||
compact?: boolean
|
||||
wrapperClassName?: string
|
||||
className?: string
|
||||
@ -203,6 +206,7 @@ export type PromptEditorProps = {
|
||||
|
||||
const PromptEditor: FC<PromptEditorProps> = ({
|
||||
instanceId,
|
||||
nodeId,
|
||||
compact,
|
||||
wrapperClassName,
|
||||
className,
|
||||
@ -275,15 +279,21 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
||||
eventEmitter?.emit({
|
||||
type: UPDATE_DATASETS_EVENT_EMITTER,
|
||||
payload: contextBlock?.datasets,
|
||||
} as any)
|
||||
} as EventPayload)
|
||||
}, [eventEmitter, contextBlock?.datasets])
|
||||
useEffect(() => {
|
||||
eventEmitter?.emit({
|
||||
type: UPDATE_HISTORY_EVENT_EMITTER,
|
||||
payload: historyBlock?.history,
|
||||
} as any)
|
||||
} as EventPayload)
|
||||
}, [eventEmitter, historyBlock?.history])
|
||||
|
||||
const { getBeforeNodesInSameBranch } = useWorkflow()
|
||||
const availableNodes = React.useMemo(
|
||||
() => nodeId && isSupportSandbox ? getBeforeNodesInSameBranch(nodeId || '') : [],
|
||||
[getBeforeNodesInSameBranch, isSupportSandbox, nodeId],
|
||||
)
|
||||
|
||||
const toolBlockContextValue = React.useMemo(() => {
|
||||
if (!onToolMetadataChange)
|
||||
return null
|
||||
@ -291,8 +301,11 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
||||
metadata: toolMetadata,
|
||||
onMetadataChange: onToolMetadataChange,
|
||||
useModal: true,
|
||||
nodeId,
|
||||
nodesOutputVars: workflowVariableBlock?.variables,
|
||||
availableNodes,
|
||||
}
|
||||
}, [onToolMetadataChange, toolMetadata])
|
||||
}, [availableNodes, nodeId, onToolMetadataChange, toolMetadata, workflowVariableBlock?.variables])
|
||||
|
||||
const sandboxPlaceHolder = React.useMemo(() => {
|
||||
if (!isSupportSandbox)
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -368,12 +368,12 @@ const ToolBlockComponent = ({
|
||||
className={cn(
|
||||
'hidden size-[14px]',
|
||||
needAuthorization ? 'text-text-warning' : 'text-text-accent',
|
||||
isInteractive && 'group-hover:block',
|
||||
isInteractive && 'group-hover/tool:block',
|
||||
)}
|
||||
/>
|
||||
)
|
||||
const normalIcon = (
|
||||
<span className={cn('flex items-center justify-center', isInteractive && 'group-hover:hidden')}>
|
||||
<span className={cn('flex items-center justify-center', isInteractive && 'group-hover/tool:hidden')}>
|
||||
{iconNode}
|
||||
</span>
|
||||
)
|
||||
@ -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>
|
||||
@ -546,7 +549,7 @@ const ToolBlockComponent = ({
|
||||
<span
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'group inline-flex items-center gap-[2px] rounded-[5px] border py-px pl-px pr-[3px] shadow-xs',
|
||||
'group/tool inline-flex items-center gap-[2px] rounded-[5px] border py-px pl-px pr-[3px] shadow-xs',
|
||||
isInteractive ? 'cursor-pointer' : 'cursor-default',
|
||||
needAuthorization ? 'border-state-warning-active bg-state-warning-hover' : 'border-state-accent-hover-alt bg-state-accent-hover',
|
||||
isSelected && 'border-text-accent',
|
||||
|
||||
@ -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}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
@ -1435,11 +1435,6 @@
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"app/components/base/prompt-editor/index.tsx": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"app/components/base/prompt-editor/plugins/component-picker-block/index.tsx": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 1
|
||||
|
||||
Reference in New Issue
Block a user