From 1857d37faed6b8b503649b843e480c7a49f0214c Mon Sep 17 00:00:00 2001 From: hjlarry Date: Mon, 13 Oct 2025 16:42:17 +0800 Subject: [PATCH] sync app published --- .../components/app/app-publisher/index.tsx | 34 ++++++++++++++++++- .../core/collaboration-manager.ts | 8 +++++ .../collaboration/types/collaboration.ts | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/web/app/components/app/app-publisher/index.tsx b/web/app/components/app/app-publisher/index.tsx index df2618b49c..6f939c5477 100644 --- a/web/app/components/app/app-publisher/index.tsx +++ b/web/app/components/app/app-publisher/index.tsx @@ -47,6 +47,9 @@ import { AccessMode } from '@/models/access-control' import { fetchAppDetail } from '@/service/apps' import { useGlobalPublicStore } from '@/context/global-public-context' import { useFormatTimeFromNow } from '@/hooks/use-format-time-from-now' +import { webSocketClient } from '@/app/components/workflow/collaboration/core/websocket-manager' +import { collaborationManager } from '@/app/components/workflow/collaboration/core/collaboration-manager' +import { useInvalidateAppWorkflow } from '@/service/use-workflow' export type AppPublisherProps = { disabled?: boolean @@ -96,6 +99,7 @@ const AppPublisher = ({ const isChatApp = ['chat', 'agent-chat', 'completion'].includes(appDetail?.mode || '') const { data: userCanAccessApp, isLoading: isGettingUserCanAccessApp, refetch } = useGetUserCanAccessApp({ appId: appDetail?.id, enabled: false }) const { data: appAccessSubjects, isLoading: isGettingAppWhiteListSubjects } = useAppWhiteListSubjects(appDetail?.id, open && systemFeatures.webapp_auth.enabled && appDetail?.access_mode === AccessMode.SPECIFIC_GROUPS_MEMBERS) + const invalidateAppWorkflow = useInvalidateAppWorkflow() useEffect(() => { if (systemFeatures.webapp_auth.enabled && open && appDetail) @@ -120,11 +124,27 @@ const AppPublisher = ({ try { await onPublish?.(params) setPublished(true) + + const appId = appDetail?.id + const socket = appId ? webSocketClient.getSocket(appId) : null + if (appId) + invalidateAppWorkflow(appId) + if (socket) { + const timestamp = Date.now() + socket.emit('collaboration_event', { + type: 'app_publish_update', + data: { + action: 'published', + timestamp, + }, + timestamp, + }) + } } catch { setPublished(false) } - }, [onPublish]) + }, [appDetail?.id, onPublish, invalidateAppWorkflow]) const handleRestore = useCallback(async () => { try { @@ -178,6 +198,18 @@ const AppPublisher = ({ handlePublish() }, { exactMatch: true, useCapture: true }) + useEffect(() => { + const appId = appDetail?.id + if (!appId) return + + const unsubscribe = collaborationManager.onAppPublishUpdate((update: any) => { + if (update?.data?.action === 'published') + invalidateAppWorkflow(appId) + }) + + return unsubscribe + }, [appDetail?.id, invalidateAppWorkflow]) + return ( <> void): () => void { + return this.eventEmitter.on('appPublishUpdate', callback) + } + onAppMetaUpdate(callback: (update: any) => void): () => void { return this.eventEmitter.on('appMetaUpdate', callback) } @@ -820,6 +824,10 @@ export class CollaborationManager { console.log('Processing app_meta_update event:', update) this.eventEmitter.emit('appMetaUpdate', update) } + else if (update.type === 'app_publish_update') { + console.log('Processing app_publish_update event:', update) + this.eventEmitter.emit('appPublishUpdate', update) + } else if (update.type === 'mcp_server_update') { console.log('Processing mcp_server_update event:', update) this.eventEmitter.emit('mcpServerUpdate', update) diff --git a/web/app/components/workflow/collaboration/types/collaboration.ts b/web/app/components/workflow/collaboration/types/collaboration.ts index f76247f295..4e74d8fbda 100644 --- a/web/app/components/workflow/collaboration/types/collaboration.ts +++ b/web/app/components/workflow/collaboration/types/collaboration.ts @@ -50,7 +50,7 @@ export type GraphSyncData = { } export type CollaborationUpdate = { - type: 'mouse_move' | 'vars_and_features_update' | 'sync_request' | 'app_state_update' | 'app_meta_update' | 'mcp_server_update' | 'workflow_update' | 'comments_update' | 'node_panel_presence' + type: 'mouse_move' | 'vars_and_features_update' | 'sync_request' | 'app_state_update' | 'app_meta_update' | 'mcp_server_update' | 'workflow_update' | 'comments_update' | 'node_panel_presence' | 'app_publish_update' userId: string data: any timestamp: number