@@ -117,6 +117,7 @@ export const Panel = memo(function Panel() {
117117 const router = useRouter ( )
118118 const params = useParams ( )
119119 const workspaceId = params . workspaceId as string
120+ const routeWorkflowId = params . workflowId as string
120121
121122 const posthog = usePostHog ( )
122123 const posthogRef = useRef ( posthog )
@@ -396,6 +397,7 @@ export const Panel = memo(function Panel() {
396397 } ,
397398 } )
398399 )
400+ const copilotDraftScopeKey = `${ workspaceId } :workflow-copilot:${ routeWorkflowId } `
399401
400402 const handleCopilotNewChat = useCallback ( ( ) => {
401403 if ( ! activeWorkflowId || ! workspaceId ) return
@@ -482,7 +484,7 @@ export const Panel = memo(function Panel() {
482484 * skip the caller's own fallback.
483485 */
484486 useEffect ( ( ) => {
485- if ( ! isCopilotTabAvailable ) return
487+ if ( ! isCopilotTabAvailable || activeWorkflowId !== routeWorkflowId ) return
486488
487489 const handler = ( e : Event ) => {
488490 const detail = ( e as CustomEvent < MothershipSendMessageDetail > ) . detail
@@ -495,7 +497,7 @@ export const Panel = memo(function Panel() {
495497 }
496498 window . addEventListener ( MOTHERSHIP_SEND_MESSAGE_EVENT , handler )
497499 return ( ) => window . removeEventListener ( MOTHERSHIP_SEND_MESSAGE_EVENT , handler )
498- } , [ isCopilotTabAvailable , setActiveTab , copilotSendMessage ] )
500+ } , [ isCopilotTabAvailable , activeWorkflowId , routeWorkflowId , setActiveTab , copilotSendMessage ] )
499501
500502 useEffect ( ( ) => {
501503 if ( activeTab !== 'copilot' ) return
@@ -847,7 +849,7 @@ export const Panel = memo(function Panel() {
847849
848850 { /* Tab Content - Keep all tabs mounted but hidden to preserve state */ }
849851 < div className = 'flex-1 overflow-hidden pt-3' >
850- { isCopilotTabAvailable && (
852+ { isCopilotTabAvailable && activeWorkflowId === routeWorkflowId && (
851853 < div
852854 className = {
853855 _hasHydrated && activeTab === 'copilot'
@@ -943,6 +945,7 @@ export const Panel = memo(function Panel() {
943945 onCancelQueueEdit = { copilotCancelQueueEdit }
944946 userId = { session ?. user ?. id }
945947 chatId = { copilotResolvedChatId }
948+ draftScopeKey = { copilotDraftScopeKey }
946949 layout = 'copilot-view'
947950 />
948951 </ div >
0 commit comments