From 99dad4b212ea2335a8243947a6d837133deba696 Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 2 Nov 2026 00:39:26 +0000 Subject: [PATCH] refactor(agent): move tab-title and tab-activity wiring into a composable AgentPanelRoot wired the agent's turns onto the workflow tab dots and the browser tab title inline. useAgentTabSignals now owns that wiring and the clear on panel teardown, so the panel root only calls it. --- .../extensions/agent/AgentPanelRoot.vue | 18 ++-------- .../composables/agent/useAgentTabSignals.ts | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 src/workbench/extensions/agent/composables/agent/useAgentTabSignals.ts diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 16fde958728..23f38036398 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -132,6 +132,7 @@ import type { TurnOrigin, WorkflowTurnContext } from './composables/agent/useAgentSession' +import { useAgentTabSignals } from './composables/agent/useAgentTabSignals' import type { CoachStep } from './composables/agent/useOnboarding' import { useBillingIdentity } from './composables/useBillingIdentity' import { useAgentConsent } from './composables/agent/useAgentConsent' @@ -151,7 +152,6 @@ import { describeAgentRequestFailure } from './services/agent/agentRequestFailure' import { createAgentRestClient } from './services/agent/agentRestClient' -import { setAgentTabTitlePrefix } from './services/agent/agentTabTitlePrefix' import { useAgentChatHistoryRefresh } from './composables/agent/useAgentChatHistoryRefresh' import { useAgentWorkflowChatFollow } from './composables/agent/useAgentWorkflowChatFollow' import { @@ -1360,18 +1360,7 @@ async function restoreThreadWorkflow( } conversationStore.setTurnTabResolver(turnTab) -conversationStore.onTurnCompleted((path) => tabActivity.markModified(path)) -watch( - () => conversationStore.turnTabs, - (tabs) => tabActivity.setAgentTurnTabs(tabs), - { immediate: true, flush: 'sync' } -) -watch( - () => - conversationStore.awaitingApproval ? t('g.agentInputNeededShort') : null, - setAgentTabTitlePrefix, - { immediate: true, flush: 'sync' } -) +const { clearTurnSignals } = useAgentTabSignals() const boundCanvasNodeCount = ref(0) function readBoundCanvasNodeCount(): void { @@ -1768,8 +1757,7 @@ onBeforeUnmount(() => { ++activeTabGeneration }, clearAgentTurnTabs: () => { - tabActivity.setAgentTurnTabs([]) - setAgentTabTitlePrefix(null) + clearTurnSignals() }, resetTurnTabResolver: () => { conversationStore.setTurnTabResolver(() => ({ status: 'unknown' })) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentTabSignals.ts b/src/workbench/extensions/agent/composables/agent/useAgentTabSignals.ts new file mode 100644 index 00000000000..5c015f818b4 --- /dev/null +++ b/src/workbench/extensions/agent/composables/agent/useAgentTabSignals.ts @@ -0,0 +1,33 @@ +import { watch } from 'vue' +import { useI18n } from 'vue-i18n' + +import { useWorkflowTabActivityStore } from '@/stores/workflowTabActivityStore' +import { setAgentTabTitlePrefix } from '@/workbench/extensions/agent/services/agent/agentTabTitlePrefix' +import { useAgentConversationStore } from '@/workbench/extensions/agent/stores/agent/agentConversationStore' + +/** Mirrors the agent's turns onto the workflow tabs and the browser tab title. */ +export function useAgentTabSignals() { + const { t } = useI18n() + const conversationStore = useAgentConversationStore() + const tabActivity = useWorkflowTabActivityStore() + + conversationStore.onTurnCompleted((path) => tabActivity.markModified(path)) + watch( + () => conversationStore.turnTabs, + (tabs) => tabActivity.setAgentTurnTabs(tabs), + { immediate: true, flush: 'sync' } + ) + watch( + () => + conversationStore.awaitingApproval ? t('g.agentInputNeededShort') : null, + setAgentTabTitlePrefix, + { immediate: true, flush: 'sync' } + ) + + function clearTurnSignals(): void { + tabActivity.setAgentTurnTabs([]) + setAgentTabTitlePrefix(null) + } + + return { clearTurnSignals } +}