mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
feat(trigger): enhance plugin and trigger integration with updated naming conventions
- Refactored `PluginFetchDynamicSelectOptionsApi` to replace the `extra` argument with `credential_id`, improving clarity in dynamic option fetching. - Updated `ProviderConfigEncrypter` to rename `mask_tool_credentials` to `mask_credentials` for consistency, and added a new method to maintain backward compatibility. - Enhanced `PluginParameterService` to utilize `credential_id` for fetching subscriptions, improving the handling of trigger credentials. - Adjusted various components and types in the frontend to replace `tool_name` with `trigger_name`, ensuring consistency across the application. - Introduced `multiple` property in `TriggerParameter` to support multi-select functionality. These changes improve the integration of triggers and plugins, enhance code clarity, and align naming conventions across the codebase.
This commit is contained in:
@ -3,27 +3,32 @@ import produce from 'immer'
|
||||
import type { PluginTriggerNodeType } from './types'
|
||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||
import { useNodesReadOnly } from '@/app/components/workflow/hooks'
|
||||
import { useAllTriggerPlugins, useTriggerSubscriptions } from '@/service/use-triggers'
|
||||
import {
|
||||
useAllTriggerPlugins,
|
||||
useTriggerSubscriptions,
|
||||
} from '@/service/use-triggers'
|
||||
import {
|
||||
addDefaultValue,
|
||||
toolParametersToFormSchemas,
|
||||
} from '@/app/components/tools/utils/to-form-schema'
|
||||
import type { InputVar } from '@/app/components/workflow/types'
|
||||
import type { TriggerWithProvider } from '@/app/components/workflow/block-selector/types'
|
||||
import type { Tool } from '@/app/components/tools/types'
|
||||
import type { Trigger } from '@/app/components/tools/types'
|
||||
|
||||
const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||
const { data: triggerPlugins = [] } = useAllTriggerPlugins()
|
||||
|
||||
const { inputs, setInputs: doSetInputs } = useNodeCrud<PluginTriggerNodeType>(id, payload)
|
||||
const { inputs, setInputs: doSetInputs } = useNodeCrud<PluginTriggerNodeType>(
|
||||
id,
|
||||
payload,
|
||||
)
|
||||
|
||||
const { provider_id, provider_name, tool_name, config } = inputs
|
||||
const { provider_id, provider_name, trigger_name, config } = inputs
|
||||
|
||||
// Construct provider for authentication check
|
||||
const authProvider = useMemo(() => {
|
||||
if (provider_id && provider_name)
|
||||
return `${provider_id}/${provider_name}`
|
||||
if (provider_id && provider_name) return `${provider_id}/${provider_name}`
|
||||
return provider_id || ''
|
||||
}, [provider_id, provider_name])
|
||||
|
||||
@ -33,21 +38,26 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
||||
)
|
||||
|
||||
const currentProvider = useMemo<TriggerWithProvider | undefined>(() => {
|
||||
return triggerPlugins.find(provider =>
|
||||
provider.name === provider_name
|
||||
|| provider.id === provider_id
|
||||
|| (provider_id && provider.plugin_id === provider_id),
|
||||
return triggerPlugins.find(
|
||||
provider =>
|
||||
provider.name === provider_name
|
||||
|| provider.id === provider_id
|
||||
|| (provider_id && provider.plugin_id === provider_id),
|
||||
)
|
||||
}, [triggerPlugins, provider_name, provider_id])
|
||||
|
||||
const currentTrigger = useMemo<Tool | undefined>(() => {
|
||||
return currentProvider?.tools.find(tool => tool.name === tool_name)
|
||||
}, [currentProvider, tool_name])
|
||||
const currentTrigger = useMemo<Trigger | undefined>(() => {
|
||||
return currentProvider?.triggers.find(
|
||||
trigger => trigger.name === trigger_name,
|
||||
)
|
||||
}, [currentProvider, trigger_name])
|
||||
|
||||
// Dynamic subscription parameters (from subscription_schema.parameters_schema)
|
||||
const subscriptionParameterSchema = useMemo(() => {
|
||||
if (!currentProvider?.subscription_schema?.parameters_schema) return []
|
||||
return toolParametersToFormSchemas(currentProvider.subscription_schema.parameters_schema as any)
|
||||
return toolParametersToFormSchemas(
|
||||
currentProvider.subscription_schema.parameters_schema as any,
|
||||
)
|
||||
}, [currentProvider])
|
||||
|
||||
// Dynamic trigger parameters (from specific trigger.parameters)
|
||||
@ -66,22 +76,28 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
||||
return addDefaultValue(config || {}, triggerParameterSchema)
|
||||
}, [triggerParameterSchema, config])
|
||||
|
||||
const setTriggerParameterValue = useCallback((value: Record<string, any>) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.config = value
|
||||
})
|
||||
doSetInputs(newInputs)
|
||||
}, [inputs, doSetInputs])
|
||||
const setTriggerParameterValue = useCallback(
|
||||
(value: Record<string, any>) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.config = value
|
||||
})
|
||||
doSetInputs(newInputs)
|
||||
},
|
||||
[inputs, doSetInputs],
|
||||
)
|
||||
|
||||
const setInputVar = useCallback((variable: InputVar, varDetail: InputVar) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.config = {
|
||||
...draft.config,
|
||||
[variable.variable]: varDetail.variable,
|
||||
}
|
||||
})
|
||||
doSetInputs(newInputs)
|
||||
}, [inputs, doSetInputs])
|
||||
const setInputVar = useCallback(
|
||||
(variable: InputVar, varDetail: InputVar) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.config = {
|
||||
...draft.config,
|
||||
[variable.variable]: varDetail.variable,
|
||||
}
|
||||
})
|
||||
doSetInputs(newInputs)
|
||||
},
|
||||
[inputs, doSetInputs],
|
||||
)
|
||||
|
||||
// Get output schema
|
||||
const outputSchema = useMemo(() => {
|
||||
@ -91,7 +107,9 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
||||
// Check if trigger has complex output structure
|
||||
const hasObjectOutput = useMemo(() => {
|
||||
const properties = outputSchema.properties || {}
|
||||
return Object.values(properties).some((prop: any) => prop.type === 'object')
|
||||
return Object.values(properties).some(
|
||||
(prop: any) => prop.type === 'object',
|
||||
)
|
||||
}, [outputSchema])
|
||||
|
||||
// Authentication status check
|
||||
@ -109,10 +127,16 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
||||
|
||||
const methods = []
|
||||
|
||||
if (currentProvider.oauth_client_schema && currentProvider.oauth_client_schema.length > 0)
|
||||
if (
|
||||
currentProvider.oauth_client_schema
|
||||
&& currentProvider.oauth_client_schema.length > 0
|
||||
)
|
||||
methods.push('oauth')
|
||||
|
||||
if (currentProvider.credentials_schema && currentProvider.credentials_schema.length > 0)
|
||||
if (
|
||||
currentProvider.credentials_schema
|
||||
&& currentProvider.credentials_schema.length > 0
|
||||
)
|
||||
methods.push('api_key')
|
||||
|
||||
return methods
|
||||
|
||||
Reference in New Issue
Block a user