From 622d12137ae9f8f25af9a57909b872f0dcbad7fe Mon Sep 17 00:00:00 2001 From: yessenia Date: Fri, 10 Oct 2025 20:37:23 +0800 Subject: [PATCH] feat: change subscription field in workflow --- .../subscription-list/create/oauth-client.tsx | 11 +++---- web/app/components/plugins/types.ts | 12 ++++--- .../workflow/block-selector/types.ts | 11 ++++--- .../components/subscription-menu.tsx | 9 ++---- .../nodes/trigger-plugin/use-config.ts | 31 ------------------- web/service/use-triggers.ts | 4 +-- 6 files changed, 23 insertions(+), 55 deletions(-) diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx index 0b5f553e13..9ccb8404fd 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx @@ -17,7 +17,7 @@ import { RiClipboardLine, RiInformation2Fill, } from '@remixicon/react' -import React, { useEffect, useMemo, useState } from 'react' +import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { usePluginStore } from '../store' @@ -48,9 +48,8 @@ export const OAuthClientSettingsModal = ({ oauthConfig, onClose, showOAuthCreate const clientFormRef = React.useRef(null) - const providerName = useMemo(() => !detail ? '' : `${detail?.plugin_id}/${detail?.declaration.name}`, [detail]) - const clientSchema = detail?.declaration.trigger?.oauth_schema?.client_schema || [] - + const oauthClientSchema = detail?.declaration.trigger?.subscription_constructor?.oauth_schema?.client_schema || [] + const providerName = detail?.provider || '' const { mutate: initiateOAuth } = useInitiateTriggerOAuth() const { mutate: verifyBuilder } = useVerifyTriggerSubscriptionBuilder() const { mutate: configureOAuth } = useConfigureTriggerOAuth() @@ -226,9 +225,9 @@ export const OAuthClientSettingsModal = ({ oauthConfig, onClose, showOAuthCreate )} - {clientType === ClientTypeEnum.Custom && clientSchema.length > 0 && ( + {clientType === ClientTypeEnum.Custom && oauthClientSchema.length > 0 && (
diff --git a/web/app/components/plugins/types.ts b/web/app/components/plugins/types.ts index c46cd47092..06c8311f7e 100644 --- a/web/app/components/plugins/types.ts +++ b/web/app/components/plugins/types.ts @@ -88,14 +88,16 @@ export type PluginDeclaration = { trigger: PluginTriggerDefinition } +export type PluginTriggerSubscriptionConstructor = { + credentials_schema: CredentialsSchema[] + oauth_schema: OauthSchema + parameters: ParametersSchema[] +} + export type PluginTriggerDefinition = { events: Trigger[] identity: Identity - subscription_constructor: { - credentials_schema: CredentialsSchema[] - oauth_schema: OauthSchema - parameters: ParametersSchema[] - } + subscription_constructor: PluginTriggerSubscriptionConstructor subscription_schema: ParametersSchema[] } diff --git a/web/app/components/workflow/block-selector/types.ts b/web/app/components/workflow/block-selector/types.ts index 522e4498fc..cb2f278281 100644 --- a/web/app/components/workflow/block-selector/types.ts +++ b/web/app/components/workflow/block-selector/types.ts @@ -1,5 +1,5 @@ import type { TypeWithI18N } from '@/app/components/header/account-setting/model-provider-page/declarations' -import type { PluginMeta, SupportedCreationMethods } from '../../plugins/types' +import type { ParametersSchema, PluginMeta, PluginTriggerSubscriptionConstructor, SupportedCreationMethods } from '../../plugins/types' import type { Collection, Event } from '../../tools/types' export enum TabsEnum { @@ -200,8 +200,8 @@ export type TriggerProviderApiEntity = { plugin_unique_identifier: string supported_creation_methods: SupportedCreationMethods[] credentials_schema: TriggerCredentialField[] - oauth_client_schema: TriggerCredentialField[] - subscription_schema: TriggerSubscriptionSchema + subscription_constructor: PluginTriggerSubscriptionConstructor + subscription_schema: ParametersSchema[] events: TriggerApiEntity[] } @@ -211,8 +211,9 @@ export type TriggerWithProvider = Collection & { meta: PluginMeta plugin_unique_identifier: string credentials_schema?: TriggerCredentialField[] - oauth_client_schema?: TriggerCredentialField[] - subscription_schema?: TriggerSubscriptionSchema + subscription_constructor: PluginTriggerSubscriptionConstructor + subscription_schema?: ParametersSchema[] + supported_creation_methods: SupportedCreationMethods[] } // ===== API Service Types ===== diff --git a/web/app/components/workflow/nodes/trigger-plugin/components/subscription-menu.tsx b/web/app/components/workflow/nodes/trigger-plugin/components/subscription-menu.tsx index 7c0a10a7ff..37abab2be8 100644 --- a/web/app/components/workflow/nodes/trigger-plugin/components/subscription-menu.tsx +++ b/web/app/components/workflow/nodes/trigger-plugin/components/subscription-menu.tsx @@ -22,13 +22,10 @@ export const SubscriptionMenu = memo(({ payload, selectedSubscriptionId, onSubsc provider: currentProvider.name, declaration: { tool: undefined, - endpoint: undefined, + // @ts-expect-error just remain the necessary fields trigger: { - subscription_schema: currentProvider.subscription_schema, - credentials_schema: currentProvider.credentials_schema, - oauth_schema: { - client_schema: currentProvider.oauth_client_schema, - }, + subscription_schema: currentProvider.subscription_schema || [], + subscription_constructor: currentProvider.subscription_constructor, }, }, }) diff --git a/web/app/components/workflow/nodes/trigger-plugin/use-config.ts b/web/app/components/workflow/nodes/trigger-plugin/use-config.ts index a72157551d..115159a992 100644 --- a/web/app/components/workflow/nodes/trigger-plugin/use-config.ts +++ b/web/app/components/workflow/nodes/trigger-plugin/use-config.ts @@ -51,14 +51,6 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => { ) }, [currentProvider, event_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, - ) - }, [currentProvider]) - // Dynamic trigger parameters (from specific trigger.parameters) const triggerSpecificParameterSchema = useMemo(() => { if (!currentEvent) return [] @@ -126,27 +118,6 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => { const showAuthRequired = !isAuthenticated && !!currentProvider - // Check supported authentication methods - const supportedAuthMethods = useMemo(() => { - if (!currentProvider) return [] - - const methods = [] - - if ( - currentProvider.oauth_client_schema - && currentProvider.oauth_client_schema.length > 0 - ) - methods.push('oauth') - - if ( - currentProvider.credentials_schema - && currentProvider.credentials_schema.length > 0 - ) - methods.push('api_key') - - return methods - }, [currentProvider]) - return { readOnly, inputs, @@ -154,14 +125,12 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => { currentTrigger: currentEvent, triggerParameterSchema, triggerParameterValue, - subscriptionParameterSchema, setTriggerParameterValue, setInputVar, outputSchema, hasObjectOutput, isAuthenticated, showAuthRequired, - supportedAuthMethods, } } diff --git a/web/service/use-triggers.ts b/web/service/use-triggers.ts index 6821375659..805bf076a3 100644 --- a/web/service/use-triggers.ts +++ b/web/service/use-triggers.ts @@ -58,9 +58,9 @@ const convertToTriggerWithProvider = (provider: TriggerProviderApiEntity): Trigg })), // Trigger-specific schema fields - credentials_schema: provider.credentials_schema, - oauth_client_schema: provider.oauth_client_schema, + subscription_constructor: provider.subscription_constructor, subscription_schema: provider.subscription_schema, + supported_creation_methods: provider.supported_creation_methods, meta: { version: '1.0',