From 559cf6583fc894c659bcb6842b70908774b8d96f Mon Sep 17 00:00:00 2001 From: hjlarry Date: Thu, 16 Oct 2025 15:33:18 +0800 Subject: [PATCH] fix add candidate webhook node raise error --- .../components/workflow/candidate-node.tsx | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/candidate-node.tsx b/web/app/components/workflow/candidate-node.tsx index 35bcd5c201..6eb96fbc09 100644 --- a/web/app/components/workflow/candidate-node.tsx +++ b/web/app/components/workflow/candidate-node.tsx @@ -1,5 +1,6 @@ import { memo, + useCallback, } from 'react' import produce from 'immer' import { @@ -12,13 +13,15 @@ import { useStore, useWorkflowStore, } from './store' -import { WorkflowHistoryEvent, useNodesInteractions, useWorkflowHistory } from './hooks' +import { WorkflowHistoryEvent, useNodesInteractions, useNodesSyncDraft, useWorkflowHistory } from './hooks' import { CUSTOM_NODE } from './constants' import { getIterationStartNode, getLoopStartNode } from './utils' import CustomNode from './nodes' import CustomNoteNode from './note-node' import { CUSTOM_NOTE_NODE } from './note-node/constants' import { BlockEnum } from './types' +import { useStore as useAppStore } from '@/app/components/app/store' +import { fetchWebhookUrl } from '@/service/apps' const CandidateNode = () => { const store = useStoreApi() @@ -29,6 +32,35 @@ const CandidateNode = () => { const { zoom } = useViewport() const { handleNodeSelect } = useNodesInteractions() const { saveStateToHistory } = useWorkflowHistory() + const { handleSyncWorkflowDraft } = useNodesSyncDraft() + + const autoGenerateWebhookUrl = useCallback((nodeId: string) => { + const appId = useAppStore.getState().appDetail?.id + if (!appId) + return + + fetchWebhookUrl({ appId, nodeId }).then((response) => { + const { getNodes, setNodes } = store.getState() + let hasUpdated = false + const updatedNodes = produce(getNodes(), (draft) => { + const targetNode = draft.find(n => n.id === nodeId) + if (!targetNode || targetNode.data.type !== BlockEnum.TriggerWebhook) + return + + targetNode.data = { + ...targetNode.data, + webhook_url: response.webhook_url, + webhook_debug_url: response.webhook_debug_url, + } + hasUpdated = true + }) + if (hasUpdated) + setNodes(updatedNodes) + }) + .catch((error: unknown) => { + console.error('Failed to auto-generate webhook URL from candidate placement:', error) + }) + }, [store]) useEventListener('click', (e) => { const { candidateNode, mousePosition } = workflowStore.getState() @@ -70,6 +102,12 @@ const CandidateNode = () => { if (candidateNode.type === CUSTOM_NOTE_NODE) handleNodeSelect(candidateNode.id) + + if (candidateNode.data.type === BlockEnum.TriggerWebhook) { + handleSyncWorkflowDraft(true, true, { + onSuccess: () => autoGenerateWebhookUrl(candidateNode.id), + }) + } } })