mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 18:08:07 +08:00
feat: add tools sync config
This commit is contained in:
@ -26,6 +26,8 @@ export type Props = {
|
||||
value?: string | object
|
||||
placeholder?: React.JSX.Element | string
|
||||
onChange?: (value: string) => void
|
||||
onBlur?: () => void
|
||||
onFocus?: () => void
|
||||
title?: string | React.JSX.Element
|
||||
language: CodeLanguage
|
||||
headerRight?: React.JSX.Element
|
||||
@ -55,6 +57,8 @@ const CodeEditor: FC<Props> = ({
|
||||
value = '',
|
||||
placeholder = '',
|
||||
onChange = noop,
|
||||
onBlur,
|
||||
onFocus,
|
||||
title = '',
|
||||
headerRight,
|
||||
language,
|
||||
@ -109,9 +113,11 @@ const CodeEditor: FC<Props> = ({
|
||||
|
||||
editor.onDidFocusEditorText(() => {
|
||||
setIsFocus(true)
|
||||
onFocus?.()
|
||||
})
|
||||
editor.onDidBlurEditorText(() => {
|
||||
setIsFocus(false)
|
||||
onBlur?.()
|
||||
})
|
||||
|
||||
monaco.editor.setTheme(appTheme === Theme.light ? 'light' : 'vs-dark') // Fix: sometimes not load the default theme
|
||||
|
||||
@ -83,6 +83,8 @@ type Props = {
|
||||
placeholderClassName?: string
|
||||
titleClassName?: string
|
||||
required?: boolean
|
||||
onBlur?: () => void
|
||||
onFocus?: () => void
|
||||
}
|
||||
|
||||
const Editor: FC<Props> = ({
|
||||
@ -125,6 +127,8 @@ const Editor: FC<Props> = ({
|
||||
titleClassName,
|
||||
editorContainerClassName,
|
||||
required,
|
||||
onBlur,
|
||||
onFocus,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { eventEmitter } = useEventEmitterContextContext()
|
||||
@ -297,8 +301,14 @@ const Editor: FC<Props> = ({
|
||||
onManageInputField: () => setShowInputFieldPanel?.(true),
|
||||
}}
|
||||
onChange={onChange}
|
||||
onBlur={setBlur}
|
||||
onFocus={setFocus}
|
||||
onBlur={() => {
|
||||
setBlur()
|
||||
onBlur?.()
|
||||
}}
|
||||
onFocus={() => {
|
||||
setFocus()
|
||||
onFocus?.()
|
||||
}}
|
||||
editable={!readOnly}
|
||||
isSupportFileVar={isSupportFileVar}
|
||||
isSupportSandbox={isSupportSandbox}
|
||||
@ -323,6 +333,8 @@ const Editor: FC<Props> = ({
|
||||
noWrapper
|
||||
isExpand={isExpand}
|
||||
className={inputClassName}
|
||||
onBlur={onBlur}
|
||||
onFocus={onFocus}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@ -17,6 +17,7 @@ type Props = {
|
||||
onChange: (enabled: boolean) => void
|
||||
nodeId: string
|
||||
toolSettings?: ToolSetting[]
|
||||
promptTemplateKey: string
|
||||
}
|
||||
|
||||
const ComputerUseConfig: FC<Props> = ({
|
||||
@ -25,6 +26,7 @@ const ComputerUseConfig: FC<Props> = ({
|
||||
onChange,
|
||||
nodeId,
|
||||
toolSettings,
|
||||
promptTemplateKey,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
@ -64,6 +66,7 @@ const ComputerUseConfig: FC<Props> = ({
|
||||
enabled={enabled}
|
||||
nodeId={nodeId}
|
||||
toolSettings={toolSettings}
|
||||
promptTemplateKey={promptTemplateKey}
|
||||
/>
|
||||
</div>
|
||||
</FieldCollapse>
|
||||
|
||||
@ -42,6 +42,7 @@ type Props = {
|
||||
handleAddVariable: (payload: any) => void
|
||||
modelConfig?: ModelConfig
|
||||
isSupportSandbox?: boolean
|
||||
onPromptEditorBlur?: () => void
|
||||
}
|
||||
|
||||
const roleOptions = [
|
||||
@ -86,6 +87,7 @@ const ConfigPromptItem: FC<Props> = ({
|
||||
handleAddVariable,
|
||||
modelConfig,
|
||||
isSupportSandbox,
|
||||
onPromptEditorBlur,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const workflowStore = useWorkflowStore()
|
||||
@ -156,6 +158,7 @@ const ConfigPromptItem: FC<Props> = ({
|
||||
handleAddVariable={handleAddVariable}
|
||||
isSupportFileVar
|
||||
isSupportSandbox={isSupportSandbox}
|
||||
onBlur={onPromptEditorBlur}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@ -65,6 +65,7 @@ type Props = {
|
||||
varList?: Variable[]
|
||||
handleAddVariable: (payload: any) => void
|
||||
modelConfig: ModelConfig
|
||||
onPromptEditorBlur?: () => void
|
||||
}
|
||||
|
||||
const ConfigPrompt: FC<Props> = ({
|
||||
@ -80,6 +81,7 @@ const ConfigPrompt: FC<Props> = ({
|
||||
varList = [],
|
||||
handleAddVariable,
|
||||
modelConfig,
|
||||
onPromptEditorBlur,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const workflowStore = useWorkflowStore()
|
||||
@ -358,6 +360,7 @@ const ConfigPrompt: FC<Props> = ({
|
||||
handleAddVariable={handleAddVariable}
|
||||
modelConfig={modelConfig}
|
||||
isSupportSandbox={isSupportSandbox}
|
||||
onPromptEditorBlur={onPromptEditorBlur}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
@ -434,6 +437,7 @@ const ConfigPrompt: FC<Props> = ({
|
||||
onGenerated={handleGenerated}
|
||||
modelConfig={modelConfig}
|
||||
isSupportSandbox={isSupportSandbox}
|
||||
onBlur={onPromptEditorBlur}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@ -17,6 +17,7 @@ type ReferenceToolConfigProps = {
|
||||
enabled: boolean
|
||||
nodeId: string
|
||||
toolSettings?: ToolSetting[]
|
||||
promptTemplateKey: string
|
||||
}
|
||||
|
||||
type ToolDependency = {
|
||||
@ -35,20 +36,28 @@ const ReferenceToolConfig: FC<ReferenceToolConfigProps> = ({
|
||||
enabled,
|
||||
nodeId,
|
||||
toolSettings,
|
||||
promptTemplateKey,
|
||||
}) => {
|
||||
const isDisabled = readonly || !enabled
|
||||
const appId = useAppStore(s => s.appDetail?.id)
|
||||
const { handleNodeDataUpdate } = useNodeCurdKit<LLMNodeType>(nodeId)
|
||||
|
||||
const { data } = useQuery({
|
||||
queryKey: consoleQuery.workflowDraft.nodeSkills.queryKey({
|
||||
input: {
|
||||
params: {
|
||||
appId: appId ?? '',
|
||||
nodeId,
|
||||
const queryKey = useMemo(() => {
|
||||
return [
|
||||
...consoleQuery.workflowDraft.nodeSkills.queryKey({
|
||||
input: {
|
||||
params: {
|
||||
appId: appId ?? '',
|
||||
nodeId,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
promptTemplateKey,
|
||||
]
|
||||
}, [appId, nodeId, promptTemplateKey])
|
||||
|
||||
const { data } = useQuery({
|
||||
queryKey,
|
||||
queryFn: () => consoleClient.workflowDraft.nodeSkills({
|
||||
params: {
|
||||
appId: appId ?? '',
|
||||
|
||||
@ -2,6 +2,7 @@ import type { FC } from 'react'
|
||||
import type { LLMNodeType } from './types'
|
||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
import { RiAlertFill, RiInformationLine, RiQuestionLine } from '@remixicon/react'
|
||||
import { useDebounceFn } from 'ahooks'
|
||||
import * as React from 'react'
|
||||
import { useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -74,6 +75,22 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
||||
handleComputerUseChange,
|
||||
} = useConfig(id, data)
|
||||
|
||||
const promptTemplateKey = React.useMemo(() => {
|
||||
try {
|
||||
return JSON.stringify(inputs.prompt_template ?? null)
|
||||
}
|
||||
catch {
|
||||
return ''
|
||||
}
|
||||
}, [inputs.prompt_template])
|
||||
const [skillsRefreshKey, setSkillsRefreshKey] = React.useState(promptTemplateKey)
|
||||
const { run: scheduleSkillsRefresh } = useDebounceFn((nextKey: string) => {
|
||||
setSkillsRefreshKey(nextKey)
|
||||
}, { wait: 3000 })
|
||||
const handlePromptEditorBlur = useCallback(() => {
|
||||
scheduleSkillsRefresh(promptTemplateKey)
|
||||
}, [promptTemplateKey, scheduleSkillsRefresh])
|
||||
|
||||
const {
|
||||
handleMaxIterationsChange,
|
||||
} = useNodeTools(id)
|
||||
@ -144,6 +161,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
||||
varList={inputs.prompt_config?.jinja2_variables || []}
|
||||
handleAddVariable={handleAddVariable}
|
||||
modelConfig={model}
|
||||
onPromptEditorBlur={handlePromptEditorBlur}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -234,6 +252,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
||||
onChange={handleComputerUseChange}
|
||||
nodeId={id}
|
||||
toolSettings={inputs.tool_settings}
|
||||
promptTemplateKey={skillsRefreshKey}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user