refactor(trigger): rename trigger references to event for consistency

- Updated variable names and types from 'trigger' to 'event' across multiple files to enhance clarity and maintain consistency in the codebase.
- Adjusted related data structures and API responses to reflect the new naming convention.
- Improved type annotations and error handling in the workflow trigger run API and associated services.
This commit is contained in:
Harry
2025-10-09 03:12:35 +08:00
parent a33d04d1ac
commit 91318d3d04
22 changed files with 114 additions and 96 deletions

View File

@ -102,7 +102,7 @@ export type TriggerParameter = {
}
// Action
export type Trigger = {
export type Event = {
name: string
author: string
label: TypeWithI18N

View File

@ -50,11 +50,11 @@ const getTriggerPluginNodeData = (
provider_id: triggerConfig.provider_id,
provider_type: triggerConfig.provider_type,
provider_name: triggerConfig.provider_name,
trigger_name: triggerConfig.trigger_name,
trigger_label: triggerConfig.trigger_label,
trigger_description: triggerConfig.trigger_description,
title: triggerConfig.trigger_label || triggerConfig.title || fallbackTitle,
desc: triggerConfig.trigger_description || fallbackDesc,
event_name: triggerConfig.event_name,
event_label: triggerConfig.event_label,
event_description: triggerConfig.event_description,
title: triggerConfig.event_label || triggerConfig.title || fallbackTitle,
desc: triggerConfig.event_description || fallbackDesc,
output_schema: { ...(triggerConfig.output_schema || {}) },
parameters_schema: triggerConfig.paramSchemas ? [...triggerConfig.paramSchemas] : [],
config: { ...(triggerConfig.params || {}) },

View File

@ -2,7 +2,7 @@
import type { FC } from 'react'
import React from 'react'
import type { TriggerWithProvider } from '../types'
import type { Trigger } from '@/app/components/tools/types'
import type { Event } from '@/app/components/tools/types'
import { BlockEnum } from '../../types'
import type { TriggerDefaultValue } from '../types'
import Tooltip from '@/app/components/base/tooltip'
@ -13,7 +13,7 @@ import { useTranslation } from 'react-i18next'
type Props = {
provider: TriggerWithProvider
payload: Trigger
payload: Event
disabled?: boolean
isAdded?: boolean
onSelect: (type: BlockEnum, trigger?: TriggerDefaultValue) => void
@ -63,9 +63,9 @@ const TriggerPluginActionItem: FC<Props> = ({
provider_id: provider.id,
provider_type: provider.type as string,
provider_name: provider.name,
trigger_name: payload.name,
trigger_label: payload.label[language],
trigger_description: payload.description[language],
event_name: payload.name,
event_label: payload.label[language],
event_description: payload.description[language],
plugin_unique_identifier: provider.plugin_unique_identifier,
title: payload.label[language],
is_team_authorization: provider.is_team_authorization,

View File

@ -27,7 +27,7 @@ const TriggerPluginItem: FC<Props> = ({
const { t } = useTranslation()
const language = useGetLanguage()
const notShowProvider = payload.type === CollectionType.workflow
const actions = payload.triggers
const actions = payload.events
const hasAction = !notShowProvider
const [isFold, setFold] = React.useState<boolean>(true)
const ref = useRef(null)
@ -71,10 +71,10 @@ const TriggerPluginItem: FC<Props> = ({
return
}
const trigger = actions[0]
const event = actions[0]
const params: Record<string, string> = {}
if (trigger.parameters) {
trigger.parameters.forEach((item) => {
if (event.parameters) {
event.parameters.forEach((item: any) => {
params[item.name] = ''
})
}
@ -82,14 +82,14 @@ const TriggerPluginItem: FC<Props> = ({
provider_id: payload.id,
provider_type: payload.type,
provider_name: payload.name,
trigger_name: trigger.name,
trigger_label: trigger.label[language],
trigger_description: trigger.description[language],
title: trigger.label[language],
event_name: event.name,
event_label: event.label[language],
event_description: event.description[language],
title: event.label[language],
plugin_unique_identifier: payload.plugin_unique_identifier,
is_team_authorization: payload.is_team_authorization,
output_schema: trigger.output_schema || {},
paramSchemas: trigger.parameters,
output_schema: event.output_schema || {},
paramSchemas: event.parameters,
params,
})
}}

View File

@ -1,6 +1,6 @@
import type { TypeWithI18N } from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { PluginMeta, SupportedCreationMethods } from '../../plugins/types'
import type { Collection, Trigger } from '../../tools/types'
import type { Collection, Event } from '../../tools/types'
export enum TabsEnum {
Start = 'start',
@ -32,9 +32,9 @@ type PluginCommonDefaultValue = {
}
export type TriggerDefaultValue = PluginCommonDefaultValue & {
trigger_name: string
trigger_label: string
trigger_description: string
event_name: string
event_label: string
event_description: string
title: string
plugin_unique_identifier: string
is_team_authorization: boolean
@ -207,7 +207,7 @@ export type TriggerProviderApiEntity = {
// Frontend types - compatible with ToolWithProvider
export type TriggerWithProvider = Collection & {
triggers: Trigger[]
events: Event[]
meta: PluginMeta
plugin_unique_identifier: string
credentials_schema?: TriggerCredentialField[]

View File

@ -27,7 +27,7 @@ import cn from '@/utils/classnames'
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/react'
import { ChevronDownIcon } from '@heroicons/react/20/solid'
import { RiCheckLine, RiLoader4Line } from '@remixicon/react'
import type { Trigger } from '@/app/components/tools/types'
import type { Event } from '@/app/components/tools/types'
type Props = {
readOnly: boolean
@ -36,7 +36,7 @@ type Props = {
value: ResourceVarInputs
onChange: (value: any) => void
inPanel?: boolean
currentTool?: Tool | Trigger
currentTool?: Tool | Event
currentProvider?: ToolWithProvider | TriggerWithProvider
showManageInputField?: boolean
onManageInputField?: () => void

View File

@ -3,7 +3,7 @@ import type { FC } from 'react'
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import type { TriggerWithProvider } from '@/app/components/workflow/block-selector/types'
import type { Trigger } from '@/app/components/tools/types'
import type { Event } from '@/app/components/tools/types'
import { toolCredentialToFormSchemas, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
import TriggerForm from './trigger-form'
import Button from '@/app/components/base/button'
@ -11,7 +11,7 @@ import Input from '@/app/components/base/input'
type ParametersFormProps = {
provider: TriggerWithProvider
trigger?: Trigger
trigger?: Event
builderId: string
parametersValue: Record<string, any>
propertiesValue: Record<string, any>

View File

@ -1,6 +1,6 @@
'use client'
import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { Trigger } from '@/app/components/tools/types'
import type { Event } from '@/app/components/tools/types'
import type { FC } from 'react'
import type { PluginTriggerVarInputs } from '@/app/components/workflow/nodes/trigger-plugin/types'
import TriggerFormItem from './item'
@ -14,7 +14,7 @@ type Props = {
onChange: (value: PluginTriggerVarInputs) => void
onOpen?: (index: number) => void
inPanel?: boolean
currentTrigger?: Trigger
currentTrigger?: Event
currentProvider?: TriggerWithProvider
extraParams?: Record<string, any>
}

View File

@ -12,7 +12,7 @@ import Tooltip from '@/app/components/base/tooltip'
import FormInputItem from '@/app/components/workflow/nodes/_base/components/form-input-item'
import { useBoolean } from 'ahooks'
import SchemaModal from '@/app/components/plugins/plugin-detail-panel/tool-selector/schema-modal'
import type { Trigger } from '@/app/components/tools/types'
import type { Event } from '@/app/components/tools/types'
import type { TriggerWithProvider } from '@/app/components/workflow/block-selector/types'
type Props = {
@ -22,7 +22,7 @@ type Props = {
value: PluginTriggerVarInputs
onChange: (value: PluginTriggerVarInputs) => void
inPanel?: boolean
currentTrigger?: Trigger
currentTrigger?: Event
currentProvider?: TriggerWithProvider
extraParams?: Record<string, any>
}

View File

@ -13,7 +13,7 @@ const nodeDefault: NodeDefault<PluginTriggerNodeType> = {
metaData,
defaultValue: {
plugin_id: '',
trigger_name: '',
event_name: '',
// event_type: '',
config: {},
},

View File

@ -6,14 +6,14 @@ export type PluginTriggerNodeType = CommonNodeType & {
provider_id: string
provider_type: CollectionType
provider_name: string
trigger_name: string
trigger_label: string
trigger_parameters: PluginTriggerVarInputs
trigger_configurations: Record<string, any>
event_name: string
event_label: string
event_parameters: PluginTriggerVarInputs
event_configurations: Record<string, any>
output_schema: Record<string, any>
parameters_schema?: Record<string, any>[]
version?: string
trigger_node_version?: string
event_node_version?: string
plugin_id?: string
config?: Record<string, any>
}

View File

@ -13,7 +13,7 @@ import {
} 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 { Trigger } from '@/app/components/tools/types'
import type { Event } from '@/app/components/tools/types'
const useConfig = (id: string, payload: PluginTriggerNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
@ -24,7 +24,7 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
payload,
)
const { provider_id, provider_name, trigger_name, config } = inputs
const { provider_id, provider_name, event_name: event_name, config } = inputs
// Construct provider for authentication check
const authProvider = useMemo(() => {
@ -45,11 +45,11 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
)
}, [triggerPlugins, provider_name, provider_id])
const currentTrigger = useMemo<Trigger | undefined>(() => {
return currentProvider?.triggers.find(
trigger => trigger.name === trigger_name,
const currentEvent = useMemo<Event | undefined>(() => {
return currentProvider?.events.find(
event => event.name === event_name,
)
}, [currentProvider, trigger_name])
}, [currentProvider, event_name])
// Dynamic subscription parameters (from subscription_schema.parameters_schema)
const subscriptionParameterSchema = useMemo(() => {
@ -61,9 +61,9 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
// Dynamic trigger parameters (from specific trigger.parameters)
const triggerSpecificParameterSchema = useMemo(() => {
if (!currentTrigger) return []
return toolParametersToFormSchemas(currentTrigger.parameters)
}, [currentTrigger])
if (!currentEvent) return []
return toolParametersToFormSchemas(currentEvent.parameters)
}, [currentEvent])
// Combined parameter schema (subscription + trigger specific)
const triggerParameterSchema = useMemo(() => {
@ -106,8 +106,8 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
// Get output schema
const outputSchema = useMemo(() => {
return currentTrigger?.output_schema || {}
}, [currentTrigger])
return currentEvent?.output_schema || {}
}, [currentEvent])
// Check if trigger has complex output structure
const hasObjectOutput = useMemo(() => {
@ -151,7 +151,7 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
readOnly,
inputs,
currentProvider,
currentTrigger,
currentTrigger: currentEvent,
triggerParameterSchema,
triggerParameterValue,
subscriptionParameterSchema,

View File

@ -33,12 +33,12 @@ const convertToTriggerWithProvider = (provider: TriggerProviderApiEntity): Trigg
labels: provider.tags || [],
plugin_id: provider.plugin_id,
plugin_unique_identifier: provider.plugin_unique_identifier || '',
triggers: provider.events.map(trigger => ({
name: trigger.name,
events: provider.events.map(event => ({
name: event.name,
author: provider.author,
label: trigger.identity.label,
description: trigger.description.llm,
parameters: trigger.parameters.map(param => ({
label: event.identity.label,
description: event.description.llm,
parameters: event.parameters.map(param => ({
name: param.name,
label: param.label,
human_description: param.description || param.label,
@ -54,7 +54,7 @@ const convertToTriggerWithProvider = (provider: TriggerProviderApiEntity): Trigg
multiple: param.multiple || false,
})),
labels: provider.tags || [],
output_schema: trigger.output_schema || {},
output_schema: event.output_schema || {},
})),
// Trigger-specific schema fields