From fc425b8163e6234dca01c38b1d45855ad056d0bb Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 17:50:39 -0700 Subject: [PATCH 01/13] feat(agent): mount the agent panel from ComfyUI's agent feature Off cloud, ComfyUI run with --enable-agent publishes an `agent` server feature {state, url, reason} and pushes agent_status on every change. Fold the pushes into the server feature map, register the panel extension in every non-cloud build, and enable it once the agent is ready. While it is starting or failed, the entry button says so, disabled, with the reason. The event socket opens at the flag's url. --- src/components/topbar/AgentEntryButton.vue | 23 ++++++++++++++-- src/components/topbar/WorkflowTabs.test.ts | 27 +++++++++++++++++++ src/components/topbar/WorkflowTabs.vue | 8 +++++- src/extensions/core/agentPanel.test.ts | 25 +++++++++++++++++ src/extensions/core/agentPanel.ts | 11 ++++++-- src/extensions/core/index.ts | 5 ++-- src/locales/en/main.json | 3 +++ .../remote/comfyui/execution/types.ts | 6 +++++ src/scripts/api.featureFlags.test.ts | 19 +++++++++++++ src/scripts/api.ts | 8 ++++++ .../extensions/agent/AgentPanelRoot.vue | 2 +- src/workbench/extensions/agent/README.md | 10 ++++--- .../composables/useAgentDockMount.test.ts | 11 +------- .../agent/composables/useAgentDockMount.ts | 17 +++--------- .../stores/agent/agentPanelStore.test.ts | 18 +++++++++++++ .../agent/stores/agent/agentPanelStore.ts | 16 +++++++++++ 16 files changed, 174 insertions(+), 35 deletions(-) diff --git a/src/components/topbar/AgentEntryButton.vue b/src/components/topbar/AgentEntryButton.vue index c8ed174f4e9..2effffcfaab 100644 --- a/src/components/topbar/AgentEntryButton.vue +++ b/src/components/topbar/AgentEntryButton.vue @@ -10,6 +10,12 @@ ) " :aria-pressed="active" + :disabled="comfyAgent !== undefined" + :title=" + comfyAgent?.state === 'failed' + ? $t('agent.entryFailedReason', { reason: comfyAgent.reason }) + : undefined + " > - {{ $t('agent.entryButton') }} + {{ + comfyAgent?.state === 'starting' + ? $t('agent.entryStarting') + : comfyAgent?.state === 'failed' + ? $t('agent.entryFailed') + : $t('agent.entryButton') + }} @@ -27,10 +39,17 @@ import { cn } from '@comfyorg/tailwind-utils' import Button from '@/components/ui/button/Button.vue' +import type { AgentStatusWsMessage } from '@/platform/remote/comfyui/execution/types' -const { active = false, inviting = false } = defineProps<{ +const { + active = false, + inviting = false, + comfyAgent +} = defineProps<{ active?: boolean /** Draw attention to the button for a user who has never opened the panel. */ inviting?: boolean + /** ComfyUI's agent while it is not ready: shown, but not clickable. */ + comfyAgent?: AgentStatusWsMessage }>() diff --git a/src/components/topbar/WorkflowTabs.test.ts b/src/components/topbar/WorkflowTabs.test.ts index 01f19f592c4..f6b178c8287 100644 --- a/src/components/topbar/WorkflowTabs.test.ts +++ b/src/components/topbar/WorkflowTabs.test.ts @@ -240,6 +240,33 @@ describe('WorkflowTabs agent entry button', () => { // The separator divides the button off from the avatar, so it must leave // with it rather than trailing the icon group. + it("shows ComfyUI's agent starting, then failed with its reason, without opening", async () => { + const store = useAgentPanelStore() + store.enabled = false + api.serverFeatureFlags.value = { + agent: { state: 'starting', url: null, reason: null } + } + renderComponent() + + expect( + screen.getByRole('button', { name: enMessages.agent.entryStarting }) + ).toBeDisabled() + + api.serverFeatureFlags.value = { + agent: { state: 'failed', url: null, reason: 'not_found' } + } + await nextTick() + const failed = screen.getByRole('button', { + name: enMessages.agent.entryFailed + }) + expect(failed).toBeDisabled() + expect(failed).toHaveAttribute( + 'title', + 'ComfyUI could not start the agent: not_found' + ) + api.serverFeatureFlags.value = {} + }) + it('takes the separator away with the button when the flag is off', () => { useAgentPanelStore().enabled = false renderComponent() diff --git a/src/components/topbar/WorkflowTabs.vue b/src/components/topbar/WorkflowTabs.vue index 19d97d8e83e..69ded6df731 100644 --- a/src/components/topbar/WorkflowTabs.vue +++ b/src/components/topbar/WorkflowTabs.vue @@ -93,6 +93,7 @@ @@ -161,8 +162,13 @@ const { withConsent, isChecking } = useAgentConsent() const isOpeningAgent = ref(false) const { isLoggedIn } = useCurrentUser() +const comfyAgentNotReady = computed(() => + agentPanelStore.enabled ? undefined : agentPanelStore.comfyAgent +) const showAgentEntry = computed( - () => agentPanelStore.enabled && !(agentPanelStore.isOpen && isChecking.value) + () => + (agentPanelStore.enabled || comfyAgentNotReady.value !== undefined) && + !(agentPanelStore.isOpen && isChecking.value) ) async function onAgentEntryClick(): Promise { diff --git a/src/extensions/core/agentPanel.test.ts b/src/extensions/core/agentPanel.test.ts index b6b74d0cba4..fd40b632e21 100644 --- a/src/extensions/core/agentPanel.test.ts +++ b/src/extensions/core/agentPanel.test.ts @@ -233,6 +233,7 @@ describe('AgentPanel extension flag gate', () => { workflowStore = useWorkflowStore() agentStore.close.mockClear() agentStore.enabled = false + agentStore.comfyAgent = undefined agentStore.isOpen = true agentFlagEnabled.value = false releaseFirstRunScreen() @@ -1584,6 +1585,7 @@ describe('AgentPanel extension flag gate', () => { it('forces the panel on in development even while the flag is false', async () => { vi.stubEnv('MODE', 'development') + vi.stubEnv('VITE_AGENT_STANDALONE', 'true') agentFlagEnabled.value = false await loadEntryAndSetup() @@ -1592,6 +1594,29 @@ describe('AgentPanel extension flag gate', () => { expect(consentStore.load).toHaveBeenCalledOnce() }) + it("leaves a development build off cloud to ComfyUI's agent", async () => { + vi.stubEnv('MODE', 'development') + + await loadEntryAndSetup() + + expect(agentStore.enabled).toBe(false) + }) + + it('enables the panel once ComfyUI reports its agent ready', async () => { + agentStore.comfyAgent = { state: 'starting', url: null, reason: null } + + await loadEntryAndSetup() + expect(agentStore.enabled).toBe(false) + + agentStore.comfyAgent = { state: 'ready', url: '/api/agent', reason: null } + await nextTick() + expect(agentStore.enabled).toBe(true) + + agentStore.comfyAgent = { state: 'failed', url: null, reason: 'unknown' } + await nextTick() + expect(agentStore.enabled).toBe(false) + }) + it('leaves the panel disabled while the flag is undefined', async () => { await loadEntryAndSetup() expect(agentStore.enabled).toBe(false) diff --git a/src/extensions/core/agentPanel.ts b/src/extensions/core/agentPanel.ts index a913e575ade..c04db1d34d4 100644 --- a/src/extensions/core/agentPanel.ts +++ b/src/extensions/core/agentPanel.ts @@ -4,6 +4,7 @@ import { computed, ref, watch } from 'vue' import { useCurrentUser } from '@/composables/auth/useCurrentUser' import { useFeatureFlags } from '@/composables/useFeatureFlags' +import { isCloud } from '@/platform/distribution/types' import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore' import { authenticatedRemoteConfigState, @@ -555,12 +556,18 @@ function setupFlagGate( ): void { const agentPanelStore = useAgentPanelStore() const { flags } = useFeatureFlags() + // Off cloud ComfyUI's agent flag enables the panel, so a dev server forces + // it on only on cloud or the standalone harness. + const devForcedOn = + import.meta.env.MODE === 'development' && + (isCloud || import.meta.env.VITE_AGENT_STANDALONE === 'true') watch( () => [ - import.meta.env.MODE === 'development' || - flags.agentInAppExperienceEnabled, + devForcedOn || + flags.agentInAppExperienceEnabled || + agentPanelStore.comfyAgent?.state === 'ready', remoteConfigRevision.value ] as const, ([enabled]) => { diff --git a/src/extensions/core/index.ts b/src/extensions/core/index.ts index 54469921a5c..ea617a9a68c 100644 --- a/src/extensions/core/index.ts +++ b/src/extensions/core/index.ts @@ -44,8 +44,9 @@ if (__DISTRIBUTION__ === 'cloud') { registerAgentPanelExtension() await import('./cloudBadges') await import('./cloudSessionCookie') -} else if (import.meta.env.VITE_AGENT_STANDALONE === 'true') { - // The local agent harness mounts the panel in any distribution. +} else { + // Enabled by ComfyUI's `agent` feature, or by the local agent harness + // (VITE_AGENT_STANDALONE). const { registerAgentPanelExtension } = await import('./agentPanel') registerAgentPanelExtension() } diff --git a/src/locales/en/main.json b/src/locales/en/main.json index da1a830ecd7..cd320ea7520 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -5659,6 +5659,9 @@ }, "loadFailed": "The agent panel failed to load.", "entryButton": "Agent", + "entryStarting": "Agent starting…", + "entryFailed": "Agent unavailable", + "entryFailedReason": "ComfyUI could not start the agent: {reason}", "feedbackCaption": "Share feedback", "freeUseNoticeLabel": "Free use notice", "freeUseNotice": "Try your first chat for free!", diff --git a/src/platform/remote/comfyui/execution/types.ts b/src/platform/remote/comfyui/execution/types.ts index e77d260b639..2c5642f0b2a 100644 --- a/src/platform/remote/comfyui/execution/types.ts +++ b/src/platform/remote/comfyui/execution/types.ts @@ -120,6 +120,12 @@ export interface LogsRawResponse { entries: LogEntry[] } export type FeatureFlagsWsMessage = Record +/** ComfyUI's `agent` server feature, pushed again on every change. */ +export interface AgentStatusWsMessage { + state: 'starting' | 'ready' | 'failed' + url: string | null + reason: string | null +} export interface AssetDownloadWsMessage { task_id: string asset_name: string diff --git a/src/scripts/api.featureFlags.test.ts b/src/scripts/api.featureFlags.test.ts index 81341e557df..25ae8787ad8 100644 --- a/src/scripts/api.featureFlags.test.ts +++ b/src/scripts/api.featureFlags.test.ts @@ -124,6 +124,25 @@ describe('API Feature Flags', () => { expect(api.serverFeatureFlagsSettled.value).toBe(true) }) + it("folds ComfyUI's agent_status pushes into the agent feature", () => { + void api.init() + const send = (type: string, data: unknown) => + wsEventHandlers['message']({ data: JSON.stringify({ type, data }) }) + + send('feature_flags', { + api_version: '1.0.0', + agent: { state: 'starting', url: null, reason: null } + }) + send('agent_status', { state: 'ready', url: '/api/agent', reason: null }) + + expect(api.getServerFeature('agent')).toEqual({ + state: 'ready', + url: '/api/agent', + reason: null + }) + expect(api.getServerFeature('api_version')).toBe('1.0.0') + }) + it('settles feature flags immediately when the server delivers an empty map', () => { void api.init() diff --git a/src/scripts/api.ts b/src/scripts/api.ts index b0b77ca91d8..23a5f339cf1 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -38,6 +38,7 @@ import { useTelemetry } from '@/platform/telemetry' import { reportError } from '@/platform/telemetry/reportError' import type { components as ManagerComponents } from '@/workbench/extensions/manager/types/generatedManagerTypes' import type { + AgentStatusWsMessage, AssetDownloadWsMessage, AssetExportWsMessage, AssetSeedCompletedWsMessage, @@ -268,6 +269,7 @@ interface BackendApiCalls { progress_text: ProgressTextWsMessage progress_state: ProgressStateWsMessage feature_flags: FeatureFlagsWsMessage + agent_status: AgentStatusWsMessage asset_download: AssetDownloadWsMessage asset_export: AssetExportWsMessage 'assets.seed.completed': AssetSeedCompletedWsMessage @@ -1117,6 +1119,12 @@ export class ComfyApi extends EventTarget { this.serverFeatureFlagsSettled.value = true this.dispatchCustomEvent('feature_flags', msg.data) break + case 'agent_status': + this.serverFeatureFlags.value = { + ...this.serverFeatureFlags.value, + agent: msg.data + } + break default: if (this._registered.has(msg.type)) { // Fallback for custom types - calls super direct. diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index bd1fd5a1f31..8c615ed583f 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -218,7 +218,7 @@ const userName = computed( const rest = createAgentRestClient() const events = createAgentEventSource({ - endpoint: api.apiURL('/agent/events'), + endpoint: useAgentPanelStore().agentEventsUrl, getAuthParams: agentSocketAuthParams }) diff --git a/src/workbench/extensions/agent/README.md b/src/workbench/extensions/agent/README.md index c114dba4429..87c5deba6a7 100644 --- a/src/workbench/extensions/agent/README.md +++ b/src/workbench/extensions/agent/README.md @@ -46,10 +46,12 @@ Acceptance is stored through the hosted Global Settings API under Agent opens after the save succeeds. Skip, Escape and outside clicks dismiss without saving; failed loads or saves keep the panel closed and allow retry. Switching user or workspace invalidates the cached acceptance and loads the new -scope. Desktop/Local sign-in continuation authenticates before saving; this -branch mounts the Agent extension in Cloud builds and in builds with -`VITE_AGENT_STANDALONE=true` (the local agent harness, in any distribution); -FE-1931 owns the remaining Local and Desktop product entry points. +scope. Desktop/Local sign-in continuation authenticates before saving. On +Cloud the remote-config flag enables the panel. Elsewhere it is enabled by +ComfyUI's `agent` server feature (`--enable-agent`) once its `state` is +`ready`, following the `agent_status` pushes; while it is `starting` or +`failed` the entry button shows that, disabled. Builds with +`VITE_AGENT_STANDALONE=true` (the local agent harness) keep their own path. ## First-use tour diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts index 3bf08ea744d..55ff115de4d 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts @@ -149,17 +149,8 @@ describe('useAgentDockMount', () => { ) }) - it('returns an inert mount on non-cloud distributions', () => { + it('docks only once the gate enables and the panel opens, off cloud too', async () => { vi.stubGlobal('__DISTRIBUTION__', 'localhost') - - const { docked, DockedAgentPanel } = useAgentDockMount() - - expect(docked.value).toBe(false) - expect(DockedAgentPanel).toBeNull() - }) - - it('docks only once the gate enables and the panel opens on cloud', async () => { - vi.stubGlobal('__DISTRIBUTION__', 'cloud') const store = useAgentPanelStore() const { docked, DockedAgentPanel } = useAgentDockMount() diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.ts index 91ec7ff7800..c2d6d670f92 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.ts @@ -8,24 +8,15 @@ import { useBillingIdentity } from './useBillingIdentity' interface AgentDockMount { docked: ComputedRef - DockedAgentPanel: Component | null + DockedAgentPanel: Component } /** - * The one distribution seam for the dock mounts. The literal comparison is - * what dead-code-eliminates the store and both panel component chunks from - * OSS builds; on cloud the async component is only requested once the gate - * enables and opens the panel, so a flag-off session fetches no agent chunk. + * The dock mounts for the graph and linear hosts. The async component is only + * requested once the gate enables and opens the panel, so a flag-off session + * (on cloud, or a ComfyUI without its agent) fetches no agent chunk. */ export function useAgentDockMount(): AgentDockMount { - // The local agent harness (VITE_AGENT_STANDALONE) mounts the panel in any - // distribution; production keeps it cloud-only. - if ( - __DISTRIBUTION__ !== 'cloud' && - import.meta.env.VITE_AGENT_STANDALONE !== 'true' - ) { - return { docked: computed(() => false), DockedAgentPanel: null } - } const agentPanelStore = useAgentPanelStore() const { subscription } = useBillingContext() diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts index d7e71bcde9c..7cf731b780d 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts @@ -33,6 +33,24 @@ describe('agentPanelStore engagement telemetry', () => { expect(store.flagsSettled).toBe(true) }) + it("opens the event socket at ComfyUI's agent url, under ComfyUI's base", () => { + const store = useAgentPanelStore() + expect(store.agentEventsUrl).toBe(api.apiURL('/agent/events')) + + api.api_base = '/comfy' + api.serverFeatureFlags.value = { + agent: { state: 'ready', url: '/api/agent', reason: null } + } + expect(store.agentEventsUrl).toBe('/comfy/api/agent/events') + + api.serverFeatureFlags.value = { + agent: { state: 'ready', url: 'http://127.0.0.1:9000/a', reason: null } + } + expect(store.agentEventsUrl).toBe('http://127.0.0.1:9000/a/events') + api.api_base = '' + api.serverFeatureFlags.value = {} + }) + it('emits a restored open only once the rehydrated panel actually docks', async () => { localStorage.setItem(OPEN_STORAGE_KEY, 'true') const store = useConsentedAgentPanelStore() diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index 7dd274b8728..ea0cd39c8f9 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -7,6 +7,8 @@ import { SIDEBAR_MIN_WIDTH, SIDE_TOOLBAR_WIDTH } from '@/constants/splitterConstants' +import type { AgentStatusWsMessage } from '@/platform/remote/comfyui/execution/types' +import { isCloud } from '@/platform/distribution/types' import { useTelemetry } from '@/platform/telemetry' import type { AgentPanelCloseSource, @@ -75,6 +77,18 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { const gateSettled = ref(false) const view = shallowRef({ screen: 'chat' }) const flagsSettled = computed(() => api.serverFeatureFlagsSettled.value) + /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ + const comfyAgent = computed(() => + isCloud + ? undefined + : api.getServerFeature('agent') + ) + /** The agent's event socket: at the flag's url (relative to ComfyUI's base) when set. */ + const agentEventsUrl = computed(() => { + const url = comfyAgent.value?.url + if (!url) return api.apiURL('/agent/events') + return `${URL.canParse(url) ? '' : api.api_base}${url}/events` + }) const maximized = ref(false) const draggedWidth = ref(PANEL_MIN_WIDTH) /** @@ -382,6 +396,8 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { view, interruptHistorySelection, flagsSettled, + comfyAgent, + agentEventsUrl, reportedExhaustionIdentity, reportedFreeUseExposure, reportedFreeUseImpression, From ae92ef45f68914539f481c35f692fa195dfd3ff8 Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 18:31:25 -0700 Subject: [PATCH 02/13] fix(agent): keep ComfyUI's agent status readable and out of the harness The not-ready entry button is aria-disabled with a guarded click, so its title (the failure reason) shows on hover and the button stays focusable. It is hidden, not disabled, when the agent is ready but the panel extension is off. The standalone harness ignores ComfyUI's agent feature and keeps its own proxy. --- src/components/topbar/AgentEntryButton.vue | 11 ++-- src/components/topbar/WorkflowTabs.test.ts | 59 ++++++++++++++----- src/components/topbar/WorkflowTabs.vue | 6 +- src/extensions/core/agentPanel.test.ts | 15 +++-- src/extensions/core/agentPanel.ts | 2 - src/extensions/core/index.ts | 2 - .../stores/agent/agentPanelStore.test.ts | 22 ++++++- .../agent/stores/agent/agentPanelStore.ts | 2 +- 8 files changed, 85 insertions(+), 34 deletions(-) diff --git a/src/components/topbar/AgentEntryButton.vue b/src/components/topbar/AgentEntryButton.vue index 2effffcfaab..968a8836e3c 100644 --- a/src/components/topbar/AgentEntryButton.vue +++ b/src/components/topbar/AgentEntryButton.vue @@ -6,14 +6,17 @@ cn( 'group no-drag shrink-0 gap-1 rounded-lg', active && 'bg-secondary-background-hover', - inviting && !active && 'agent-shimmer-outline' + inviting && !active && !comfyAgent && 'agent-shimmer-outline', + comfyAgent && 'cursor-default opacity-50' ) " :aria-pressed="active" - :disabled="comfyAgent !== undefined" + :aria-disabled="comfyAgent !== undefined || undefined" :title=" comfyAgent?.state === 'failed' - ? $t('agent.entryFailedReason', { reason: comfyAgent.reason }) + ? $t('agent.entryFailedReason', { + reason: comfyAgent.reason ?? 'unknown' + }) : undefined " > @@ -49,7 +52,7 @@ const { active?: boolean /** Draw attention to the button for a user who has never opened the panel. */ inviting?: boolean - /** ComfyUI's agent while it is not ready: shown, but not clickable. */ + /** ComfyUI's agent while it is not ready: shown, but inert. */ comfyAgent?: AgentStatusWsMessage }>() diff --git a/src/components/topbar/WorkflowTabs.test.ts b/src/components/topbar/WorkflowTabs.test.ts index f6b178c8287..719fb719581 100644 --- a/src/components/topbar/WorkflowTabs.test.ts +++ b/src/components/topbar/WorkflowTabs.test.ts @@ -218,6 +218,7 @@ describe('WorkflowTabs agent entry button', () => { beforeEach(() => { useAgentPanelStore().enabled = true api.serverFeatureFlagsSettled.value = false + api.serverFeatureFlags.value = {} }) it('does not render the entry button in the legacy tab bar even with the flag on', () => { @@ -240,17 +241,35 @@ describe('WorkflowTabs agent entry button', () => { // The separator divides the button off from the avatar, so it must leave // with it rather than trailing the icon group. - it("shows ComfyUI's agent starting, then failed with its reason, without opening", async () => { + it('takes the separator away with the button when the flag is off', () => { + useAgentPanelStore().enabled = false + renderComponent() + + expect( + screen.queryByTestId('agent-entry-separator') + ).not.toBeInTheDocument() + }) + + it('divides the button from the avatar while the flag is on', () => { + renderComponent() + + expect(screen.getByTestId('agent-entry-separator')).toBeInTheDocument() + }) + + it("shows ComfyUI's agent starting, then failed with its reason, inert until ready", async () => { const store = useAgentPanelStore() store.enabled = false api.serverFeatureFlags.value = { agent: { state: 'starting', url: null, reason: null } } - renderComponent() + const { user } = renderComponent() - expect( - screen.getByRole('button', { name: enMessages.agent.entryStarting }) - ).toBeDisabled() + const starting = screen.getByRole('button', { + name: enMessages.agent.entryStarting + }) + expect(starting).toHaveAttribute('aria-disabled', 'true') + await user.click(starting) + expect(withConsent).not.toHaveBeenCalled() api.serverFeatureFlags.value = { agent: { state: 'failed', url: null, reason: 'not_found' } @@ -259,27 +278,35 @@ describe('WorkflowTabs agent entry button', () => { const failed = screen.getByRole('button', { name: enMessages.agent.entryFailed }) - expect(failed).toBeDisabled() + expect(failed).toHaveAttribute('aria-disabled', 'true') expect(failed).toHaveAttribute( 'title', 'ComfyUI could not start the agent: not_found' ) - api.serverFeatureFlags.value = {} + + api.serverFeatureFlags.value = { + agent: { state: 'ready', url: '/api/agent', reason: null } + } + store.enabled = true + await nextTick() + const ready = screen.getByRole('button', { + name: enMessages.agent.entryButton + }) + expect(ready).not.toHaveAttribute('aria-disabled') + await user.click(ready) + expect(withConsent).toHaveBeenCalledOnce() }) - it('takes the separator away with the button when the flag is off', () => { + it('hides the entry button when the agent is ready but the panel extension is off', () => { useAgentPanelStore().enabled = false + api.serverFeatureFlags.value = { + agent: { state: 'ready', url: '/api/agent', reason: null } + } renderComponent() expect( - screen.queryByTestId('agent-entry-separator') - ).not.toBeInTheDocument() - }) - - it('divides the button from the avatar while the flag is on', () => { - renderComponent() - - expect(screen.getByTestId('agent-entry-separator')).toBeInTheDocument() + screen.queryByRole('button', { name: enMessages.agent.entryButton }) + ).toBeNull() }) // Two entry controls once shipped side by side after a merge, which broke diff --git a/src/components/topbar/WorkflowTabs.vue b/src/components/topbar/WorkflowTabs.vue index 69ded6df731..9bb42fe68e3 100644 --- a/src/components/topbar/WorkflowTabs.vue +++ b/src/components/topbar/WorkflowTabs.vue @@ -163,7 +163,9 @@ const isOpeningAgent = ref(false) const { isLoggedIn } = useCurrentUser() const comfyAgentNotReady = computed(() => - agentPanelStore.enabled ? undefined : agentPanelStore.comfyAgent + agentPanelStore.enabled || agentPanelStore.comfyAgent?.state === 'ready' + ? undefined + : agentPanelStore.comfyAgent ) const showAgentEntry = computed( () => @@ -172,7 +174,7 @@ const showAgentEntry = computed( ) async function onAgentEntryClick(): Promise { - if (isOpeningAgent.value) return + if (isOpeningAgent.value || comfyAgentNotReady.value) return isOpeningAgent.value = true try { diff --git a/src/extensions/core/agentPanel.test.ts b/src/extensions/core/agentPanel.test.ts index fd40b632e21..e68a307bdc8 100644 --- a/src/extensions/core/agentPanel.test.ts +++ b/src/extensions/core/agentPanel.test.ts @@ -233,7 +233,7 @@ describe('AgentPanel extension flag gate', () => { workflowStore = useWorkflowStore() agentStore.close.mockClear() agentStore.enabled = false - agentStore.comfyAgent = undefined + Object.assign(agentStore, { comfyAgent: undefined }) agentStore.isOpen = true agentFlagEnabled.value = false releaseFirstRunScreen() @@ -1596,6 +1596,7 @@ describe('AgentPanel extension flag gate', () => { it("leaves a development build off cloud to ComfyUI's agent", async () => { vi.stubEnv('MODE', 'development') + vi.stubEnv('VITE_AGENT_STANDALONE', '') await loadEntryAndSetup() @@ -1603,16 +1604,22 @@ describe('AgentPanel extension flag gate', () => { }) it('enables the panel once ComfyUI reports its agent ready', async () => { - agentStore.comfyAgent = { state: 'starting', url: null, reason: null } + Object.assign(agentStore, { + comfyAgent: { state: 'starting', url: null, reason: null } + }) await loadEntryAndSetup() expect(agentStore.enabled).toBe(false) - agentStore.comfyAgent = { state: 'ready', url: '/api/agent', reason: null } + Object.assign(agentStore, { + comfyAgent: { state: 'ready', url: '/api/agent', reason: null } + }) await nextTick() expect(agentStore.enabled).toBe(true) - agentStore.comfyAgent = { state: 'failed', url: null, reason: 'unknown' } + Object.assign(agentStore, { + comfyAgent: { state: 'failed', url: null, reason: 'unknown' } + }) await nextTick() expect(agentStore.enabled).toBe(false) }) diff --git a/src/extensions/core/agentPanel.ts b/src/extensions/core/agentPanel.ts index c04db1d34d4..897cd3bfe0d 100644 --- a/src/extensions/core/agentPanel.ts +++ b/src/extensions/core/agentPanel.ts @@ -556,8 +556,6 @@ function setupFlagGate( ): void { const agentPanelStore = useAgentPanelStore() const { flags } = useFeatureFlags() - // Off cloud ComfyUI's agent flag enables the panel, so a dev server forces - // it on only on cloud or the standalone harness. const devForcedOn = import.meta.env.MODE === 'development' && (isCloud || import.meta.env.VITE_AGENT_STANDALONE === 'true') diff --git a/src/extensions/core/index.ts b/src/extensions/core/index.ts index ea617a9a68c..08662358562 100644 --- a/src/extensions/core/index.ts +++ b/src/extensions/core/index.ts @@ -45,8 +45,6 @@ if (__DISTRIBUTION__ === 'cloud') { await import('./cloudBadges') await import('./cloudSessionCookie') } else { - // Enabled by ComfyUI's `agent` feature, or by the local agent harness - // (VITE_AGENT_STANDALONE). const { registerAgentPanelExtension } = await import('./agentPanel') registerAgentPanelExtension() } diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts index 7cf731b780d..627b5ae7eee 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest' import { nextTick } from 'vue' import { useTelemetry } from '@/platform/telemetry' @@ -34,6 +34,10 @@ describe('agentPanelStore engagement telemetry', () => { }) it("opens the event socket at ComfyUI's agent url, under ComfyUI's base", () => { + onTestFinished(() => { + api.api_base = '' + api.serverFeatureFlags.value = {} + }) const store = useAgentPanelStore() expect(store.agentEventsUrl).toBe(api.apiURL('/agent/events')) @@ -47,8 +51,20 @@ describe('agentPanelStore engagement telemetry', () => { agent: { state: 'ready', url: 'http://127.0.0.1:9000/a', reason: null } } expect(store.agentEventsUrl).toBe('http://127.0.0.1:9000/a/events') - api.api_base = '' - api.serverFeatureFlags.value = {} + }) + + it("leaves the standalone harness on its own agent, not ComfyUI's", () => { + onTestFinished(() => { + api.serverFeatureFlags.value = {} + }) + vi.stubEnv('VITE_AGENT_STANDALONE', 'true') + api.serverFeatureFlags.value = { + agent: { state: 'ready', url: 'http://127.0.0.1:9000/a', reason: null } + } + const store = useAgentPanelStore() + + expect(store.comfyAgent).toBeUndefined() + expect(store.agentEventsUrl).toBe(api.apiURL('/agent/events')) }) it('emits a restored open only once the rehydrated panel actually docks', async () => { diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index ea0cd39c8f9..2097019e9d2 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -79,7 +79,7 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { const flagsSettled = computed(() => api.serverFeatureFlagsSettled.value) /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ const comfyAgent = computed(() => - isCloud + isCloud || import.meta.env.VITE_AGENT_STANDALONE === 'true' ? undefined : api.getServerFeature('agent') ) From 91798a5c87f8775445ef472d6a98169aaa1be0b0 Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 20:54:50 -0700 Subject: [PATCH 03/13] refactor(agent): mount the panel from the server's agent feature alone Cloud and ComfyUI publish the same `agent` server feature, so the gate no longer branches on the distribution or reads the cloud remote-config flag: the panel registers in every build and enables once the feature reports ready (or in the standalone harness's dev mode). The gate settles with the server feature flags. Cloud e2e boots seed the feature the way ingest publishes it to users the agent gate admits. --- .../fixtures/helpers/FeatureFlagHelper.ts | 5 +- .../fixtures/utils/cloudBootMocks.ts | 6 + src/extensions/core/agentPanel.test.ts | 265 ++++++------------ src/extensions/core/agentPanel.ts | 60 +--- src/extensions/core/index.ts | 8 +- .../remote/comfyui/execution/types.ts | 2 +- src/workbench/extensions/agent/README.md | 19 +- .../agent/composables/useAgentDockMount.ts | 5 - .../agent/stores/agent/agentPanelStore.ts | 3 +- 9 files changed, 118 insertions(+), 255 deletions(-) diff --git a/browser_tests/fixtures/helpers/FeatureFlagHelper.ts b/browser_tests/fixtures/helpers/FeatureFlagHelper.ts index b646f807805..028a5a2632a 100644 --- a/browser_tests/fixtures/helpers/FeatureFlagHelper.ts +++ b/browser_tests/fixtures/helpers/FeatureFlagHelper.ts @@ -114,15 +114,18 @@ export class FeatureFlagHelper { * later `feature_flags` handshake, as `setServerFlagsPersistent()` does. * * Must be called before `page.goto()`; init scripts persist for the page - * lifetime and cannot be removed. + * lifetime and cannot be removed. Repeated calls compose: each seed chains to + * the accessor an earlier one installed. */ async seedServerFlags(flags: Record): Promise { await this.page.addInitScript((flagMap: Record) => { + const earlier = Object.getOwnPropertyDescriptor(window, 'app') let comfyApp: Window['app'] Object.defineProperty(window, 'app', { configurable: true, get: () => comfyApp, set: (value: Window['app']) => { + earlier?.set?.(value) comfyApp = value const api = value?.api if (!api) return diff --git a/browser_tests/fixtures/utils/cloudBootMocks.ts b/browser_tests/fixtures/utils/cloudBootMocks.ts index c607eaa3cbc..6f5995b387b 100644 --- a/browser_tests/fixtures/utils/cloudBootMocks.ts +++ b/browser_tests/fixtures/utils/cloudBootMocks.ts @@ -5,6 +5,7 @@ import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' import { mockSystemStats } from '@e2e/fixtures/data/systemStats' import { CloudAuthHelper } from '@e2e/fixtures/helpers/CloudAuthHelper' +import { FeatureFlagHelper } from '@e2e/fixtures/helpers/FeatureFlagHelper' import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' import { mockDeploymentRolloutRefusal, @@ -32,6 +33,11 @@ export async function mockCloudBootRoutes( ) { await mockDeploymentRolloutRefusal(page) await page.route('**/api/features', (r) => r.fulfill(jsonRoute(features))) + // Cloud publishes the `agent` server feature to users its agent gate admits. + if (features['agent-in-app-experience'] === true) + await new FeatureFlagHelper(page).seedServerFlags({ + agent: { state: 'ready', url: '/api/agent' } + }) await page.route('**/api/system_stats', (r) => r.fulfill(jsonRoute(mockSystemStats)) ) diff --git a/src/extensions/core/agentPanel.test.ts b/src/extensions/core/agentPanel.test.ts index e68a307bdc8..b8772e9c05a 100644 --- a/src/extensions/core/agentPanel.test.ts +++ b/src/extensions/core/agentPanel.test.ts @@ -10,14 +10,7 @@ import { vi } from 'vitest' import type { Mocked } from 'vitest' -import { - computed, - defineComponent, - effectScope, - nextTick, - reactive, - ref -} from 'vue' +import { computed, defineComponent, effectScope, nextTick, ref } from 'vue' import type { EffectScope } from 'vue' import { useCurrentUser } from '@/composables/auth/useCurrentUser' let setupScope: EffectScope @@ -43,7 +36,6 @@ import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' import { useAgentComposerStore } from '@/workbench/extensions/agent/stores/agent/agentComposerStore' import { useDialogStore } from '@/stores/dialogStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' -import type { useFeatureFlags } from '@/composables/useFeatureFlags' import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore' import { createMockLoadedWorkflow } from '@/utils/__tests__/litegraphTestUtils' import { @@ -142,18 +134,13 @@ vi.mock( }) ) -const agentFlagEnabled = ref(false) +const READY_AGENT = { state: 'ready', url: '/api/agent', reason: null } as const -vi.mock(import('@/composables/useFeatureFlags'), () => ({ - useFeatureFlags: () => - fromPartial>({ - flags: reactive({ - get agentInAppExperienceEnabled() { - return agentFlagEnabled.value - } - }) - }) -})) +function setAgentReady(ready: boolean): void { + Object.assign(agentStore, { + comfyAgent: ready ? { ...READY_AGENT } : undefined + }) +} const { registerAgentPanelExtension } = await import('./agentPanel') const importRegistrationCount = mocks.capturedExtensions.length @@ -186,15 +173,6 @@ async function loadEntryAndSetup(): Promise { await nextTick() } -async function setRemoteConfigState( - state: 'unloaded' | 'loading' | 'authenticated' | 'error' -): Promise { - const { authenticatedRemoteConfigState } = - await import('@/platform/remoteConfig/remoteConfig') - authenticatedRemoteConfigState.value = state - await nextTick() -} - const DESKTOP_APPROVAL_KEY = 'global-desktop-login-confirm' const EmptyDialog = defineComponent(() => () => null) @@ -235,7 +213,7 @@ describe('AgentPanel extension flag gate', () => { agentStore.enabled = false Object.assign(agentStore, { comfyAgent: undefined }) agentStore.isOpen = true - agentFlagEnabled.value = false + setAgentReady(false) releaseFirstRunScreen() activeTour.value = null startupDecision = Promise.resolve(true) @@ -251,7 +229,7 @@ describe('AgentPanel extension flag gate', () => { }) it('attributes automatic acceptance with a restored open preference to the consent card', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(useAgentConsent().withConsent).mockImplementationOnce( async (_trigger, onAccept, hooks) => { @@ -281,7 +259,7 @@ describe('AgentPanel extension flag gate', () => { { session: 'cloud logged in without consent', user: { id: 'account-a' } }, { session: 'local logged out', user: null } ])('opens after startup for $session', async ({ user }) => { - agentFlagEnabled.value = true + setAgentReady(true) currentUser.value = user Object.assign(consentStore, { accepted: false, isChecking: false }) agentStore.isOpen = false @@ -302,7 +280,7 @@ describe('AgentPanel extension flag gate', () => { }) it('waits for the general onboarding decision before activation', async () => { - agentFlagEnabled.value = true + setAgentReady(true) agentStore.isOpen = false let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -320,7 +298,7 @@ describe('AgentPanel extension flag gate', () => { it('opens again on the second visit and completes the discovery window', async () => { localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '1') - agentFlagEnabled.value = true + setAgentReady(true) agentStore.isOpen = false await loadEntryAndSetup() @@ -333,7 +311,7 @@ describe('AgentPanel extension flag gate', () => { it('counts a visit when the persisted panel is already open', async () => { localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '1') - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: true, isChecking: false }) agentStore.isOpen = true @@ -347,7 +325,7 @@ describe('AgentPanel extension flag gate', () => { it('preserves a closed preference after the two-visit discovery window', async () => { localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '2') - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) agentStore.isOpen = false let finishConsentRead = (_: boolean) => {} @@ -380,7 +358,7 @@ describe('AgentPanel extension flag gate', () => { it('keeps a second-visit panel closed when consent finishes after dismissal', async () => { localStorage.setItem(ACTIVATION_VISITS_STORAGE_KEY, '1') - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) agentStore.isOpen = true let accept = () => {} @@ -413,7 +391,7 @@ describe('AgentPanel extension flag gate', () => { }) it('does not reopen a dismissed activation panel after flag synchronization', async () => { - agentFlagEnabled.value = true + setAgentReady(true) agentStore.isOpen = false await loadEntryAndSetup() @@ -422,9 +400,9 @@ describe('AgentPanel extension flag gate', () => { ) agentStore.close('close_button') - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() - agentFlagEnabled.value = true + setAgentReady(true) await flush() expect(agentStore.isOpen).toBe(false) @@ -432,7 +410,7 @@ describe('AgentPanel extension flag gate', () => { }) it('keeps the panel closed if the feature is disabled before acceptance', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let accept = () => {} let finish = () => {} @@ -450,7 +428,7 @@ describe('AgentPanel extension flag gate', () => { await vi.waitFor(() => expect(useAgentConsent().withConsent).toHaveBeenCalledOnce() ) - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() accept() finish() @@ -460,7 +438,7 @@ describe('AgentPanel extension flag gate', () => { }) it('records the automatic offer only after the card is displayed', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) const key = 'Comfy.AgentConsent.AutoShown.account-a.workspace-a' let show = () => {} @@ -496,7 +474,7 @@ describe('AgentPanel extension flag gate', () => { await loadEntryAndSetup() expect(useAgentConsent().withConsent).not.toHaveBeenCalled() - agentFlagEnabled.value = true + setAgentReady(true) await nextTick() await vi.waitFor(() => @@ -523,7 +501,7 @@ describe('AgentPanel extension flag gate', () => { ])( 'withholds the automatic offer while $surface, leaving the auto-shown key untouched', async ({ arrange }) => { - agentFlagEnabled.value = true + setAgentReady(true) arrange() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -539,7 +517,7 @@ describe('AgentPanel extension flag gate', () => { ) it('offers in the same session once the Getting Started screen closes', async () => { - agentFlagEnabled.value = true + setAgentReady(true) showFirstRunScreen() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -559,7 +537,7 @@ describe('AgentPanel extension flag gate', () => { }) it('keeps waiting when Getting Started closes straight into the first-run tour', async () => { - agentFlagEnabled.value = true + setAgentReady(true) showFirstRunScreen() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -582,7 +560,7 @@ describe('AgentPanel extension flag gate', () => { }) it('offers when neither Getting Started took the screen nor a tour is active', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) await loadEntryAndSetup() @@ -595,7 +573,7 @@ describe('AgentPanel extension flag gate', () => { }) it('waits for the startup decision before offering', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -614,7 +592,7 @@ describe('AgentPanel extension flag gate', () => { }) it('skips the automatic offer for the session when the boot never reports', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) startupDecision = Promise.resolve(false) @@ -628,7 +606,7 @@ describe('AgentPanel extension flag gate', () => { }) it('offers once the tour that held it ends', async () => { - agentFlagEnabled.value = true + setAgentReady(true) activeTour.value = 'appMode' Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -645,7 +623,7 @@ describe('AgentPanel extension flag gate', () => { }) it('waits for the startup decision before re-offering after a tour ends', async () => { - agentFlagEnabled.value = true + setAgentReady(true) activeTour.value = 'appMode' Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} @@ -667,7 +645,7 @@ describe('AgentPanel extension flag gate', () => { }) it('does not re-offer while an offer is still in flight', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let finish = () => {} const pending = new Promise((resolve) => { @@ -694,7 +672,7 @@ describe('AgentPanel extension flag gate', () => { }) it('withholds a card whose tour started while the offer was in flight, then re-offers', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(useAgentConsent().withConsent).mockImplementationOnce( async (_trigger, _onAccept, hooks) => { @@ -722,7 +700,7 @@ describe('AgentPanel extension flag gate', () => { }) it('stays silent after a tour ends when the saved consent cannot be read', async () => { - agentFlagEnabled.value = true + setAgentReady(true) activeTour.value = 'appMode' Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(consentStore.load).mockRejectedValue(new Error('offline')) @@ -763,7 +741,7 @@ describe('AgentPanel extension flag gate', () => { ] as const)( 'reports $reason once however often the offer re-runs', async ({ reason, arrange }) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) arrange() @@ -771,9 +749,9 @@ describe('AgentPanel extension flag gate', () => { await nextTick() await flush() - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() - agentFlagEnabled.value = true + setAgentReady(true) await nextTick() await flush() @@ -792,7 +770,7 @@ describe('AgentPanel extension flag gate', () => { { name: 'the panel was switched off', change: async () => { - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() } }, @@ -805,7 +783,7 @@ describe('AgentPanel extension flag gate', () => { ])( 'stays quiet about an undecided boot when $name meanwhile', async ({ change }) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -823,7 +801,7 @@ describe('AgentPanel extension flag gate', () => { ) it('reports the first-run screen over a dialog sitting on top of it', async () => { - agentFlagEnabled.value = true + setAgentReady(true) showFirstRunScreen() openDialog() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -839,7 +817,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reports an in-flight tour against the workspace the offer was made for', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) localStorage.setItem( 'Comfy.AgentConsent.AutoShown.account-a.workspace-b', @@ -866,7 +844,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reports a reason again for a second workspace', async () => { - agentFlagEnabled.value = true + setAgentReady(true) activeTour.value = 'appMode' Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -896,7 +874,7 @@ describe('AgentPanel extension flag gate', () => { } } ])('reports nothing for a held offer when $name', async ({ arrange }) => { - agentFlagEnabled.value = true + setAgentReady(true) activeTour.value = 'appMode' Object.assign(consentStore, { accepted: false, isChecking: false }) arrange() @@ -911,9 +889,9 @@ describe('AgentPanel extension flag gate', () => { describe('names the exit when the offer ends without naming a surface', () => { const rerunFlagGate = async (): Promise => { - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() - agentFlagEnabled.value = true + setAgentReady(true) await nextTick() } @@ -953,7 +931,7 @@ describe('AgentPanel extension flag gate', () => { ] as const)( 'reports $exit once however often the offer re-runs', async ({ exit, arrange }) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) arrange() @@ -972,7 +950,7 @@ describe('AgentPanel extension flag gate', () => { ) it('reports a signed-out offer separately from an unresolved account', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) const { useCurrentUser } = await import('@/composables/auth/useCurrentUser') @@ -992,7 +970,7 @@ describe('AgentPanel extension flag gate', () => { // `isLoggedIn` true with no resolved id is the API-key rail before its // user is known - the only way these two conditions come apart, and the // reason they are separate values rather than one. - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) const { useCurrentUser } = await import('@/composables/auth/useCurrentUser') @@ -1016,7 +994,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reports an offer refused because another attempt is still in flight', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let finish = () => {} const pending = new Promise((resolve) => { @@ -1045,7 +1023,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reports an offer skipped because the card has already been on screen', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) await loadEntryAndSetup() @@ -1091,7 +1069,7 @@ describe('AgentPanel extension flag gate', () => { ] as const)( 'reports $exit at the $stage stage', async ({ exit, stage, arrange }) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) arrange() @@ -1109,7 +1087,7 @@ describe('AgentPanel extension flag gate', () => { it('reports why an undecided boot was also ineligible', async () => { // `boot_undecided` is gated on eligibility, so this combination used to // forfeit the offer and report nothing at all. - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -1136,7 +1114,7 @@ describe('AgentPanel extension flag gate', () => { // the offer was gone for the page load; after it the hold survives - and // either way the only telemetry was a first `dialog_open`, because the // reason is deduplicated per page load. - agentFlagEnabled.value = true + setAgentReady(true) openDialog() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -1161,7 +1139,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reports the same exit again when its retry state changes', async () => { - agentFlagEnabled.value = true + setAgentReady(true) openDialog() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -1201,7 +1179,7 @@ describe('AgentPanel extension flag gate', () => { // `loadConsentIfEligible` returns on an off flag before reaching any // reported exit. That is the whole mechanism keeping this event off the // population outside the rollout, so it is asserted rather than assumed. - agentFlagEnabled.value = false + setAgentReady(false) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(consentStore.load).mockRejectedValue(new Error('offline')) @@ -1216,7 +1194,7 @@ describe('AgentPanel extension flag gate', () => { // The flag was on when the offer started, so this attempt is already // under way and its ending is real. A reporter gated on the current flag // value would hide exactly this case, which is why it is not. - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let fail = (_: Error) => {} vi.mocked(consentStore.load).mockReturnValueOnce( @@ -1227,7 +1205,7 @@ describe('AgentPanel extension flag gate', () => { await loadEntryAndSetup() await vi.waitFor(() => expect(consentStore.load).toHaveBeenCalled()) - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() await flush() fail(new Error('offline')) @@ -1243,7 +1221,7 @@ describe('AgentPanel extension flag gate', () => { }) it('offers in the same session once the dialog that held it closes', async () => { - agentFlagEnabled.value = true + setAgentReady(true) openDialog() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -1260,7 +1238,7 @@ describe('AgentPanel extension flag gate', () => { }) it('keeps the held offer when the retry cannot be made, and offers on the next clear screen', async () => { - agentFlagEnabled.value = true + setAgentReady(true) openDialog() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -1295,7 +1273,7 @@ describe('AgentPanel extension flag gate', () => { }) it('keeps waiting when a tour ends while a dialog is still open', async () => { - agentFlagEnabled.value = true + setAgentReady(true) activeTour.value = 'appMode' openDialog() Object.assign(consentStore, { accepted: false, isChecking: false }) @@ -1314,7 +1292,7 @@ describe('AgentPanel extension flag gate', () => { }) it('withholds a card whose dialog opened while the offer was in flight, then re-offers', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(useAgentConsent().withConsent).mockImplementationOnce( async (_trigger, _onAccept, hooks) => { @@ -1341,7 +1319,7 @@ describe('AgentPanel extension flag gate', () => { }) it('re-offers after a withheld in-flight offer settles on a clear screen', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let settleOffer = () => {} const pendingOffer = new Promise((resolve) => { @@ -1373,7 +1351,7 @@ describe('AgentPanel extension flag gate', () => { }) it('does not re-offer after the user declines a manually opened card', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -1393,7 +1371,7 @@ describe('AgentPanel extension flag gate', () => { }) it('skips the automatic offer for the session once the user has seen the card', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -1411,7 +1389,7 @@ describe('AgentPanel extension flag gate', () => { }) it('remembers a seen card per workspace across a switch away and back', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let decide = (_: boolean) => {} startupDecision = new Promise((resolve) => { @@ -1440,7 +1418,7 @@ describe('AgentPanel extension flag gate', () => { }) it('does not re-read consent on every dialog close while the read keeps failing', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(consentStore.load).mockRejectedValue(new Error('offline')) @@ -1458,7 +1436,7 @@ describe('AgentPanel extension flag gate', () => { }) it('stays silent when the account already accepted', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: true, isChecking: false }) vi.mocked(consentStore.load).mockResolvedValue(true) @@ -1484,7 +1462,7 @@ describe('AgentPanel extension flag gate', () => { ])( 'rechecks a missed account change once when the next consent load $outcome', async ({ load, offers, shown }) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) let finish = () => {} const pending = new Promise((resolve) => { @@ -1521,7 +1499,7 @@ describe('AgentPanel extension flag gate', () => { ])( 'offers independently for $userId / $workspaceId', async ({ userId, workspaceId }) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(useAgentConsent().withConsent).mockImplementationOnce( async (_trigger, _onAccept, hooks) => { @@ -1555,7 +1533,7 @@ describe('AgentPanel extension flag gate', () => { it.for(['getItem', 'setItem'] as const)( 'skips the automatic offer when storage %s fails', async (method) => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.spyOn(localStorage, method).mockImplementation(() => { throw new Error('Storage unavailable') @@ -1572,7 +1550,7 @@ describe('AgentPanel extension flag gate', () => { ) it('stays silent when the saved consent cannot be read', async () => { - agentFlagEnabled.value = true + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) vi.mocked(consentStore.load).mockRejectedValue(new Error('offline')) @@ -1586,7 +1564,7 @@ describe('AgentPanel extension flag gate', () => { it('forces the panel on in development even while the flag is false', async () => { vi.stubEnv('MODE', 'development') vi.stubEnv('VITE_AGENT_STANDALONE', 'true') - agentFlagEnabled.value = false + setAgentReady(false) await loadEntryAndSetup() @@ -1641,7 +1619,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reloads consent when the resolved account changes', async () => { - agentFlagEnabled.value = true + setAgentReady(true) await loadEntryAndSetup() expect(consentStore.load).toHaveBeenCalledOnce() currentUser.value = { id: 'account-b' } @@ -1650,7 +1628,7 @@ describe('AgentPanel extension flag gate', () => { }) it('reloads consent when the same user changes workspace scope', async () => { - agentFlagEnabled.value = true + setAgentReady(true) await loadEntryAndSetup() expect(consentStore.load).toHaveBeenCalledOnce() Object.assign(consentStore, { identity: 'account-a/workspace-b' }) @@ -1674,102 +1652,29 @@ describe('AgentPanel extension flag gate', () => { it('enables the panel when the flag turns true', async () => { await loadEntryAndSetup() - agentFlagEnabled.value = true + setAgentReady(true) await nextTick() expect(agentStore.enabled).toBe(true) }) - it('leaves the gate unsettled while only the anonymous config has landed', async () => { - await setRemoteConfigState('unloaded') - - await loadEntryAndSetup() - - expect(agentStore.gateSettled).toBe(false) - }) - - it('settles the gate once the authenticated config lands', async () => { - await loadEntryAndSetup() - expect(agentStore.gateSettled).toBe(false) - - await setRemoteConfigState('authenticated') - - expect(agentStore.gateSettled).toBe(true) - }) - - it('settles the gate when the config load fails rather than waiting forever', async () => { - await loadEntryAndSetup() - - await setRemoteConfigState('error') - - expect(agentStore.gateSettled).toBe(true) - }) - - it('settles the gate on the fallback when no authenticated config ever lands', async () => { - currentUser.value = null - await setRemoteConfigState('unloaded') - await loadEntryAndSetup() - expect(agentStore.gateSettled).toBe(false) - - const { GATE_SETTLE_TIMEOUT_MS } = await import('./agentPanel') - await vi.advanceTimersByTimeAsync(GATE_SETTLE_TIMEOUT_MS) - - expect(agentStore.gateSettled).toBe(true) - }) - - it('does not settle a signed-in gate while authenticated config is slow', async () => { - await setRemoteConfigState('loading') - await loadEntryAndSetup() - - const { GATE_SETTLE_TIMEOUT_MS } = await import('./agentPanel') - await vi.advanceTimersByTimeAsync(GATE_SETTLE_TIMEOUT_MS) - - expect(agentStore.gateSettled).toBe(false) - }) - - it('does not treat unresolved auth as signed out', async () => { - currentUser.value = null - isAuthInitialized.value = false - await setRemoteConfigState('unloaded') + it('settles the gate once the server feature flags land', async () => { + Object.assign(agentStore, { flagsSettled: false }) await loadEntryAndSetup() - - const { GATE_SETTLE_TIMEOUT_MS } = await import('./agentPanel') - await vi.advanceTimersByTimeAsync(GATE_SETTLE_TIMEOUT_MS) - expect(agentStore.gateSettled).toBe(false) - }) - - it('re-arms the signed-out fallback after an identity change', async () => { - await setRemoteConfigState('authenticated') - await loadEntryAndSetup() - expect(agentStore.gateSettled).toBe(true) - - currentUser.value = null - await setRemoteConfigState('unloaded') - const { GATE_SETTLE_TIMEOUT_MS } = await import('./agentPanel') - await vi.advanceTimersByTimeAsync(GATE_SETTLE_TIMEOUT_MS) - expect(agentStore.gateSettled).toBe(true) - }) + Object.assign(agentStore, { flagsSettled: true }) + await nextTick() - it('returns the gate to unsettled when authenticated config reloads', async () => { - await setRemoteConfigState('authenticated') - await loadEntryAndSetup() expect(agentStore.gateSettled).toBe(true) - - await setRemoteConfigState('loading') - - expect(agentStore.gateSettled).toBe(false) }) - it('retries consent after a completed refresh with the same flag value', async () => { - agentFlagEnabled.value = true + it('retries consent after a fresh feature push with the same agent state', async () => { + setAgentReady(true) Object.assign(consentStore, { accepted: false, isChecking: false }) await loadEntryAndSetup() vi.mocked(consentStore.load).mockClear() - const { remoteConfigRevision } = - await import('@/platform/remoteConfig/remoteConfig') - remoteConfigRevision.value++ + setAgentReady(true) await nextTick() expect(consentStore.load).toHaveBeenCalledOnce() @@ -1777,9 +1682,9 @@ describe('AgentPanel extension flag gate', () => { it('disables the panel without closing it when the flag flips back to false', async () => { await loadEntryAndSetup() - agentFlagEnabled.value = true + setAgentReady(true) await nextTick() - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() expect(agentStore.enabled).toBe(false) @@ -1789,12 +1694,12 @@ describe('AgentPanel extension flag gate', () => { it('stops node picking when the flag is disabled', async () => { await loadEntryAndSetup() - agentFlagEnabled.value = true + setAgentReady(true) await nextTick() const canvasStore = useCanvasStore() canvasStore.isPickingNodes = true - agentFlagEnabled.value = false + setAgentReady(false) await nextTick() expect(canvasStore.isPickingNodes).toBe(false) diff --git a/src/extensions/core/agentPanel.ts b/src/extensions/core/agentPanel.ts index 897cd3bfe0d..f5e1354951b 100644 --- a/src/extensions/core/agentPanel.ts +++ b/src/extensions/core/agentPanel.ts @@ -3,13 +3,7 @@ import { storeToRefs } from 'pinia' import { computed, ref, watch } from 'vue' import { useCurrentUser } from '@/composables/auth/useCurrentUser' -import { useFeatureFlags } from '@/composables/useFeatureFlags' -import { isCloud } from '@/platform/distribution/types' import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore' -import { - authenticatedRemoteConfigState, - remoteConfigRevision -} from '@/platform/remoteConfig/remoteConfig' import { useTelemetry } from '@/platform/telemetry' import { reportError } from '@/platform/telemetry/reportError' import type { @@ -40,8 +34,6 @@ import { useDialogStore } from '@/stores/dialogStore' import { getNodeByLocatorId } from '@/utils/graphTraversalUtil' /** Upper bound on how long readiness consumers wait for a gate decision. */ -export const GATE_SETTLE_TIMEOUT_MS = 5_000 - const CONSENT_AUTO_SHOWN_PREFIX = 'Comfy.AgentConsent.AutoShown' const ACTIVATION_VISITS_STORAGE_KEY = 'Comfy.AgentPanel.activationVisits' const AUTOMATIC_ACTIVATION_VISITS = 2 @@ -169,8 +161,7 @@ export function registerAgentPanelExtension(): void { const consentStore = useAgentConsentStore() const { enabled } = storeToRefs(agentPanelStore) const workspaceStore = useTeamWorkspaceStore() - const { isAuthInitialized, resolvedUserInfo, isLoggedIn } = - useCurrentUser() + const { resolvedUserInfo, isLoggedIn } = useCurrentUser() const { withConsent } = useAgentConsent() const { firstRunHoldsScreen, whenStartupDecided } = useFirstRunEntry() const onboardingTourStore = useOnboardingTourStore() @@ -540,33 +531,25 @@ export function registerAgentPanelExtension(): void { loadConsentIfEligible() } ) - setupFlagGate( - loadConsentIfEligible, - openWhenStartupDecided, - () => isAuthInitialized.value && resolvedUserInfo.value === null - ) + setupFlagGate(loadConsentIfEligible, openWhenStartupDecided) } }) } function setupFlagGate( loadConsentIfEligible: () => void, - openWhenStartupDecided: () => void, - isSignedOut: () => boolean + openWhenStartupDecided: () => void ): void { const agentPanelStore = useAgentPanelStore() - const { flags } = useFeatureFlags() const devForcedOn = import.meta.env.MODE === 'development' && - (isCloud || import.meta.env.VITE_AGENT_STANDALONE === 'true') + import.meta.env.VITE_AGENT_STANDALONE === 'true' watch( () => [ - devForcedOn || - flags.agentInAppExperienceEnabled || - agentPanelStore.comfyAgent?.state === 'ready', - remoteConfigRevision.value + devForcedOn || agentPanelStore.comfyAgent?.state === 'ready', + agentPanelStore.comfyAgent ] as const, ([enabled]) => { agentPanelStore.enabled = enabled @@ -576,37 +559,12 @@ function setupFlagGate( }, { immediate: true } ) - - const settle = (): void => { - agentPanelStore.gateSettled = true - } - let settleTimer: ReturnType | undefined - const clearSettleTimer = (): void => { - clearTimeout(settleTimer) - settleTimer = undefined - } - const scheduleSignedOutFallback = (): void => { - clearSettleTimer() - settleTimer = setTimeout(() => { - if (isSignedOut()) settle() - }, GATE_SETTLE_TIMEOUT_MS) - } watch( () => - [ - import.meta.env.MODE === 'development' || - authenticatedRemoteConfigState.value === 'authenticated' || - authenticatedRemoteConfigState.value === 'error', - isSignedOut() - ] as const, - ([decided, signedOut]) => { - agentPanelStore.gateSettled = decided - clearSettleTimer() - if (!decided && signedOut) scheduleSignedOutFallback() + import.meta.env.MODE === 'development' || agentPanelStore.flagsSettled, + (settled) => { + agentPanelStore.gateSettled = settled }, { immediate: true } ) - // A signed-out session never runs the authenticated /features refresh - // (WorkspaceAuthGate returns early with no user), so the watch above never - // reaches a decided state for it. } diff --git a/src/extensions/core/index.ts b/src/extensions/core/index.ts index 08662358562..7a464034e64 100644 --- a/src/extensions/core/index.ts +++ b/src/extensions/core/index.ts @@ -40,15 +40,13 @@ import './widgetInputs' // dead-code-eliminates this block from OSS builds. if (__DISTRIBUTION__ === 'cloud') { await import('./cloudRemoteConfig') - const { registerAgentPanelExtension } = await import('./agentPanel') - registerAgentPanelExtension() await import('./cloudBadges') await import('./cloudSessionCookie') -} else { - const { registerAgentPanelExtension } = await import('./agentPanel') - registerAgentPanelExtension() } +const { registerAgentPanelExtension } = await import('./agentPanel') +registerAgentPanelExtension() + // Feedback button for cloud and nightly builds if (isCloud || isNightly) { await import('./cloudFeedbackTopbarButton') diff --git a/src/platform/remote/comfyui/execution/types.ts b/src/platform/remote/comfyui/execution/types.ts index 2c5642f0b2a..379e53bffd1 100644 --- a/src/platform/remote/comfyui/execution/types.ts +++ b/src/platform/remote/comfyui/execution/types.ts @@ -124,7 +124,7 @@ export type FeatureFlagsWsMessage = Record export interface AgentStatusWsMessage { state: 'starting' | 'ready' | 'failed' url: string | null - reason: string | null + reason?: string | null } export interface AssetDownloadWsMessage { task_id: string diff --git a/src/workbench/extensions/agent/README.md b/src/workbench/extensions/agent/README.md index 87c5deba6a7..350040a4426 100644 --- a/src/workbench/extensions/agent/README.md +++ b/src/workbench/extensions/agent/README.md @@ -35,10 +35,14 @@ The panel speaks one contract on the cloud and on the local agent: ## Activation and consent -The dock is visible only when the `agent-in-app-experience` feature flag is -enabled, the panel has an open intent, and the current user and workspace have -accepted Agent consent. Development mode enables the feature flag; consent is -still required. A restored open intent cannot bypass consent. +The dock is visible only when the server's `agent` feature reports +`state: "ready"`, the panel has an open intent, and the current user and +workspace have accepted Agent consent. Cloud and ComfyUI (`--enable-agent`) +publish the same feature, and ComfyUI pushes `agent_status` when it changes; +while it is `starting` or `failed` the entry button shows that, inert. Builds +with `VITE_AGENT_STANDALONE=true` (the local agent harness) ignore the feature +and, in development mode, force the panel on; consent is still required. A +restored open intent cannot bypass consent. On first use, click **Agent**, then **Start using Comfy Agent**. Acceptance is stored through the hosted Global Settings API under @@ -46,12 +50,7 @@ Acceptance is stored through the hosted Global Settings API under Agent opens after the save succeeds. Skip, Escape and outside clicks dismiss without saving; failed loads or saves keep the panel closed and allow retry. Switching user or workspace invalidates the cached acceptance and loads the new -scope. Desktop/Local sign-in continuation authenticates before saving. On -Cloud the remote-config flag enables the panel. Elsewhere it is enabled by -ComfyUI's `agent` server feature (`--enable-agent`) once its `state` is -`ready`, following the `agent_status` pushes; while it is `starting` or -`failed` the entry button shows that, disabled. Builds with -`VITE_AGENT_STANDALONE=true` (the local agent harness) keep their own path. +scope. Desktop/Local sign-in continuation authenticates before saving. ## First-use tour diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.ts index c2d6d670f92..1d6d1e7fcf3 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.ts @@ -11,11 +11,6 @@ interface AgentDockMount { DockedAgentPanel: Component } -/** - * The dock mounts for the graph and linear hosts. The async component is only - * requested once the gate enables and opens the panel, so a flag-off session - * (on cloud, or a ComfyUI without its agent) fetches no agent chunk. - */ export function useAgentDockMount(): AgentDockMount { const agentPanelStore = useAgentPanelStore() const { subscription } = useBillingContext() diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index 2097019e9d2..81069cdbef7 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -8,7 +8,6 @@ import { SIDE_TOOLBAR_WIDTH } from '@/constants/splitterConstants' import type { AgentStatusWsMessage } from '@/platform/remote/comfyui/execution/types' -import { isCloud } from '@/platform/distribution/types' import { useTelemetry } from '@/platform/telemetry' import type { AgentPanelCloseSource, @@ -79,7 +78,7 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { const flagsSettled = computed(() => api.serverFeatureFlagsSettled.value) /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ const comfyAgent = computed(() => - isCloud || import.meta.env.VITE_AGENT_STANDALONE === 'true' + import.meta.env.VITE_AGENT_STANDALONE === 'true' ? undefined : api.getServerFeature('agent') ) From fdd776919d9eb2ff399e2b2a5b6b7ed8e76179b5 Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 21:08:51 -0700 Subject: [PATCH 04/13] fix(agent): show a starting agent's reason, drop a fixture comment --- browser_tests/fixtures/utils/cloudBootMocks.ts | 1 - src/components/topbar/AgentEntryButton.vue | 4 +++- src/components/topbar/WorkflowTabs.test.ts | 9 +++++++++ src/locales/en/main.json | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/browser_tests/fixtures/utils/cloudBootMocks.ts b/browser_tests/fixtures/utils/cloudBootMocks.ts index 6f5995b387b..71899108f0d 100644 --- a/browser_tests/fixtures/utils/cloudBootMocks.ts +++ b/browser_tests/fixtures/utils/cloudBootMocks.ts @@ -33,7 +33,6 @@ export async function mockCloudBootRoutes( ) { await mockDeploymentRolloutRefusal(page) await page.route('**/api/features', (r) => r.fulfill(jsonRoute(features))) - // Cloud publishes the `agent` server feature to users its agent gate admits. if (features['agent-in-app-experience'] === true) await new FeatureFlagHelper(page).seedServerFlags({ agent: { state: 'ready', url: '/api/agent' } diff --git a/src/components/topbar/AgentEntryButton.vue b/src/components/topbar/AgentEntryButton.vue index 968a8836e3c..d6b1e99dd92 100644 --- a/src/components/topbar/AgentEntryButton.vue +++ b/src/components/topbar/AgentEntryButton.vue @@ -17,7 +17,9 @@ ? $t('agent.entryFailedReason', { reason: comfyAgent.reason ?? 'unknown' }) - : undefined + : comfyAgent?.reason + ? $t('agent.entryStartingReason', { reason: comfyAgent.reason }) + : undefined " > { name: enMessages.agent.entryStarting }) expect(starting).toHaveAttribute('aria-disabled', 'true') + expect(starting).not.toHaveAttribute('title') await user.click(starting) expect(withConsent).not.toHaveBeenCalled() @@ -284,6 +285,14 @@ describe('WorkflowTabs agent entry button', () => { 'ComfyUI could not start the agent: not_found' ) + api.serverFeatureFlags.value = { + agent: { state: 'starting', url: null, reason: 'crashed' } + } + await nextTick() + expect( + screen.getByRole('button', { name: enMessages.agent.entryStarting }) + ).toHaveAttribute('title', 'ComfyUI is starting the agent: crashed') + api.serverFeatureFlags.value = { agent: { state: 'ready', url: '/api/agent', reason: null } } diff --git a/src/locales/en/main.json b/src/locales/en/main.json index cd320ea7520..d2fc4ca65af 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -5662,6 +5662,7 @@ "entryStarting": "Agent starting…", "entryFailed": "Agent unavailable", "entryFailedReason": "ComfyUI could not start the agent: {reason}", + "entryStartingReason": "ComfyUI is starting the agent: {reason}", "feedbackCaption": "Share feedback", "freeUseNoticeLabel": "Free use notice", "freeUseNotice": "Try your first chat for free!", From 49ca2a672d1e60fb2b5bacabc81408a80db629bf Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 21:09:26 -0700 Subject: [PATCH 05/13] chore(agent): drop a doc comment left by the removed settle timeout --- src/extensions/core/agentPanel.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extensions/core/agentPanel.ts b/src/extensions/core/agentPanel.ts index f5e1354951b..bfbe489ed5d 100644 --- a/src/extensions/core/agentPanel.ts +++ b/src/extensions/core/agentPanel.ts @@ -33,7 +33,6 @@ import { selectedNodeKey } from '@/workbench/extensions/agent/composables/agent/ import { useDialogStore } from '@/stores/dialogStore' import { getNodeByLocatorId } from '@/utils/graphTraversalUtil' -/** Upper bound on how long readiness consumers wait for a gate decision. */ const CONSENT_AUTO_SHOWN_PREFIX = 'Comfy.AgentConsent.AutoShown' const ACTIVATION_VISITS_STORAGE_KEY = 'Comfy.AgentPanel.activationVisits' const AUTOMATIC_ACTIVATION_VISITS = 2 From 89f812fd7ae2feeb80ed98b5e60f1dc6ffb9eafa Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 21:25:23 -0700 Subject: [PATCH 06/13] test(agent): a failed agent's entry button stays inert on click --- src/components/topbar/WorkflowTabs.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/topbar/WorkflowTabs.test.ts b/src/components/topbar/WorkflowTabs.test.ts index 256312727e9..2897e5be303 100644 --- a/src/components/topbar/WorkflowTabs.test.ts +++ b/src/components/topbar/WorkflowTabs.test.ts @@ -280,6 +280,8 @@ describe('WorkflowTabs agent entry button', () => { name: enMessages.agent.entryFailed }) expect(failed).toHaveAttribute('aria-disabled', 'true') + await user.click(failed) + expect(withConsent).not.toHaveBeenCalled() expect(failed).toHaveAttribute( 'title', 'ComfyUI could not start the agent: not_found' From 18ce2c219173588d49c0d5a56bb6a6458b17013a Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 13 Oct 2026 21:40:37 -0700 Subject: [PATCH 07/13] refactor(agent): always reach the agent at /api/agent; harden the agent feature ComfyUI proxies the agent, so the feature carries only {state, reason}: drop the socket-only url override. Ignore an agent feature that is not an object, dispatch agent_status to listeners, drop the previous account's agent feature on an identity reset, and settle the gate early only when the harness forces it on. --- .../fixtures/utils/cloudBootMocks.ts | 2 +- src/components/topbar/WorkflowTabs.test.ts | 10 +++--- src/extensions/core/agentPanel.test.ts | 10 +++--- src/extensions/core/agentPanel.ts | 3 +- .../remote/comfyui/execution/types.ts | 1 - src/scripts/api.featureFlags.test.ts | 25 +++++++++++++-- src/scripts/api.ts | 3 ++ .../extensions/agent/AgentPanelRoot.vue | 2 +- .../stores/agent/agentPanelStore.test.ts | 31 +++++++------------ .../agent/stores/agent/agentPanelStore.ts | 17 ++++------ 10 files changed, 56 insertions(+), 48 deletions(-) diff --git a/browser_tests/fixtures/utils/cloudBootMocks.ts b/browser_tests/fixtures/utils/cloudBootMocks.ts index 71899108f0d..36b147f6be9 100644 --- a/browser_tests/fixtures/utils/cloudBootMocks.ts +++ b/browser_tests/fixtures/utils/cloudBootMocks.ts @@ -35,7 +35,7 @@ export async function mockCloudBootRoutes( await page.route('**/api/features', (r) => r.fulfill(jsonRoute(features))) if (features['agent-in-app-experience'] === true) await new FeatureFlagHelper(page).seedServerFlags({ - agent: { state: 'ready', url: '/api/agent' } + agent: { state: 'ready' } }) await page.route('**/api/system_stats', (r) => r.fulfill(jsonRoute(mockSystemStats)) diff --git a/src/components/topbar/WorkflowTabs.test.ts b/src/components/topbar/WorkflowTabs.test.ts index 2897e5be303..0ad7eb5b45b 100644 --- a/src/components/topbar/WorkflowTabs.test.ts +++ b/src/components/topbar/WorkflowTabs.test.ts @@ -260,7 +260,7 @@ describe('WorkflowTabs agent entry button', () => { const store = useAgentPanelStore() store.enabled = false api.serverFeatureFlags.value = { - agent: { state: 'starting', url: null, reason: null } + agent: { state: 'starting', reason: null } } const { user } = renderComponent() @@ -273,7 +273,7 @@ describe('WorkflowTabs agent entry button', () => { expect(withConsent).not.toHaveBeenCalled() api.serverFeatureFlags.value = { - agent: { state: 'failed', url: null, reason: 'not_found' } + agent: { state: 'failed', reason: 'not_found' } } await nextTick() const failed = screen.getByRole('button', { @@ -288,7 +288,7 @@ describe('WorkflowTabs agent entry button', () => { ) api.serverFeatureFlags.value = { - agent: { state: 'starting', url: null, reason: 'crashed' } + agent: { state: 'starting', reason: 'crashed' } } await nextTick() expect( @@ -296,7 +296,7 @@ describe('WorkflowTabs agent entry button', () => { ).toHaveAttribute('title', 'ComfyUI is starting the agent: crashed') api.serverFeatureFlags.value = { - agent: { state: 'ready', url: '/api/agent', reason: null } + agent: { state: 'ready', reason: null } } store.enabled = true await nextTick() @@ -311,7 +311,7 @@ describe('WorkflowTabs agent entry button', () => { it('hides the entry button when the agent is ready but the panel extension is off', () => { useAgentPanelStore().enabled = false api.serverFeatureFlags.value = { - agent: { state: 'ready', url: '/api/agent', reason: null } + agent: { state: 'ready', reason: null } } renderComponent() diff --git a/src/extensions/core/agentPanel.test.ts b/src/extensions/core/agentPanel.test.ts index b8772e9c05a..607c9afbf6e 100644 --- a/src/extensions/core/agentPanel.test.ts +++ b/src/extensions/core/agentPanel.test.ts @@ -134,7 +134,7 @@ vi.mock( }) ) -const READY_AGENT = { state: 'ready', url: '/api/agent', reason: null } as const +const READY_AGENT = { state: 'ready', reason: null } as const function setAgentReady(ready: boolean): void { Object.assign(agentStore, { @@ -1575,28 +1575,30 @@ describe('AgentPanel extension flag gate', () => { it("leaves a development build off cloud to ComfyUI's agent", async () => { vi.stubEnv('MODE', 'development') vi.stubEnv('VITE_AGENT_STANDALONE', '') + Object.assign(agentStore, { flagsSettled: false }) await loadEntryAndSetup() expect(agentStore.enabled).toBe(false) + expect(agentStore.gateSettled).toBe(false) }) it('enables the panel once ComfyUI reports its agent ready', async () => { Object.assign(agentStore, { - comfyAgent: { state: 'starting', url: null, reason: null } + comfyAgent: { state: 'starting', reason: null } }) await loadEntryAndSetup() expect(agentStore.enabled).toBe(false) Object.assign(agentStore, { - comfyAgent: { state: 'ready', url: '/api/agent', reason: null } + comfyAgent: { state: 'ready', reason: null } }) await nextTick() expect(agentStore.enabled).toBe(true) Object.assign(agentStore, { - comfyAgent: { state: 'failed', url: null, reason: 'unknown' } + comfyAgent: { state: 'failed', reason: 'unknown' } }) await nextTick() expect(agentStore.enabled).toBe(false) diff --git a/src/extensions/core/agentPanel.ts b/src/extensions/core/agentPanel.ts index bfbe489ed5d..6bf4b7a0bae 100644 --- a/src/extensions/core/agentPanel.ts +++ b/src/extensions/core/agentPanel.ts @@ -559,8 +559,7 @@ function setupFlagGate( { immediate: true } ) watch( - () => - import.meta.env.MODE === 'development' || agentPanelStore.flagsSettled, + () => devForcedOn || agentPanelStore.flagsSettled, (settled) => { agentPanelStore.gateSettled = settled }, diff --git a/src/platform/remote/comfyui/execution/types.ts b/src/platform/remote/comfyui/execution/types.ts index 379e53bffd1..89c2177b6e1 100644 --- a/src/platform/remote/comfyui/execution/types.ts +++ b/src/platform/remote/comfyui/execution/types.ts @@ -123,7 +123,6 @@ export type FeatureFlagsWsMessage = Record /** ComfyUI's `agent` server feature, pushed again on every change. */ export interface AgentStatusWsMessage { state: 'starting' | 'ready' | 'failed' - url: string | null reason?: string | null } export interface AssetDownloadWsMessage { diff --git a/src/scripts/api.featureFlags.test.ts b/src/scripts/api.featureFlags.test.ts index 25ae8787ad8..a03ab2322f4 100644 --- a/src/scripts/api.featureFlags.test.ts +++ b/src/scripts/api.featureFlags.test.ts @@ -51,6 +51,21 @@ describe('API Feature Flags', () => { }) describe('Feature flags negotiation', () => { + it("drops the previous account's agent feature when resetting the socket identity", async () => { + const resettingApi = new ComfyApi() + resettingApi.serverFeatureFlags.value = { + account_a_feature: true, + agent: { state: 'ready' } + } + + const resetPromise = resettingApi.resetSocket() + + expect(resettingApi.serverFeatureFlags.value).toEqual({ + account_a_feature: true + }) + await resetPromise + }) + it('marks feature flags stale without clearing them when resetting the socket identity', async () => { const resettingApi = new ComfyApi() resettingApi.serverFeatureFlags.value = { account_a_feature: true } @@ -131,13 +146,17 @@ describe('API Feature Flags', () => { send('feature_flags', { api_version: '1.0.0', - agent: { state: 'starting', url: null, reason: null } + agent: { state: 'starting', reason: null } }) - send('agent_status', { state: 'ready', url: '/api/agent', reason: null }) + const onStatus = vi.fn() + api.addEventListener('agent_status', onStatus) + onTestFinished(() => api.removeEventListener('agent_status', onStatus)) + send('agent_status', { state: 'ready', reason: null }) + + expect(onStatus).toHaveBeenCalledOnce() expect(api.getServerFeature('agent')).toEqual({ state: 'ready', - url: '/api/agent', reason: null }) expect(api.getServerFeature('api_version')).toBe('1.0.0') diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 23a5f339cf1..a012e3b89a6 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -1124,6 +1124,7 @@ export class ComfyApi extends EventTarget { ...this.serverFeatureFlags.value, agent: msg.data } + this.dispatchCustomEvent('agent_status', msg.data) break default: if (this._registered.has(msg.type)) { @@ -1163,6 +1164,8 @@ export class ComfyApi extends EventTarget { this.clientId = undefined window.name = '' sessionStorage.removeItem('clientId') + const { agent: _previousAgent, ...features } = this.serverFeatureFlags.value + this.serverFeatureFlags.value = features await this.replaceSocket() } diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 8c615ed583f..bd1fd5a1f31 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -218,7 +218,7 @@ const userName = computed( const rest = createAgentRestClient() const events = createAgentEventSource({ - endpoint: useAgentPanelStore().agentEventsUrl, + endpoint: api.apiURL('/agent/events'), getAuthParams: agentSocketAuthParams }) diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts index 627b5ae7eee..c1c90bdbbc2 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts @@ -33,25 +33,17 @@ describe('agentPanelStore engagement telemetry', () => { expect(store.flagsSettled).toBe(true) }) - it("opens the event socket at ComfyUI's agent url, under ComfyUI's base", () => { - onTestFinished(() => { - api.api_base = '' - api.serverFeatureFlags.value = {} - }) - const store = useAgentPanelStore() - expect(store.agentEventsUrl).toBe(api.apiURL('/agent/events')) - - api.api_base = '/comfy' - api.serverFeatureFlags.value = { - agent: { state: 'ready', url: '/api/agent', reason: null } + it.for([null, false, ''])( + 'ignores an agent feature that is not an object: %j', + (agent) => { + onTestFinished(() => { + api.serverFeatureFlags.value = {} + }) + api.serverFeatureFlags.value = { agent } + + expect(useAgentPanelStore().comfyAgent).toBeUndefined() } - expect(store.agentEventsUrl).toBe('/comfy/api/agent/events') - - api.serverFeatureFlags.value = { - agent: { state: 'ready', url: 'http://127.0.0.1:9000/a', reason: null } - } - expect(store.agentEventsUrl).toBe('http://127.0.0.1:9000/a/events') - }) + ) it("leaves the standalone harness on its own agent, not ComfyUI's", () => { onTestFinished(() => { @@ -59,12 +51,11 @@ describe('agentPanelStore engagement telemetry', () => { }) vi.stubEnv('VITE_AGENT_STANDALONE', 'true') api.serverFeatureFlags.value = { - agent: { state: 'ready', url: 'http://127.0.0.1:9000/a', reason: null } + agent: { state: 'ready' } } const store = useAgentPanelStore() expect(store.comfyAgent).toBeUndefined() - expect(store.agentEventsUrl).toBe(api.apiURL('/agent/events')) }) it('emits a restored open only once the rehydrated panel actually docks', async () => { diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index 81069cdbef7..b2212190c10 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -77,16 +77,12 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { const view = shallowRef({ screen: 'chat' }) const flagsSettled = computed(() => api.serverFeatureFlagsSettled.value) /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ - const comfyAgent = computed(() => - import.meta.env.VITE_AGENT_STANDALONE === 'true' - ? undefined - : api.getServerFeature('agent') - ) - /** The agent's event socket: at the flag's url (relative to ComfyUI's base) when set. */ - const agentEventsUrl = computed(() => { - const url = comfyAgent.value?.url - if (!url) return api.apiURL('/agent/events') - return `${URL.canParse(url) ? '' : api.api_base}${url}/events` + const comfyAgent = computed(() => { + if (import.meta.env.VITE_AGENT_STANDALONE === 'true') return undefined + const agent = api.getServerFeature('agent') + return typeof agent === 'object' && agent !== null + ? (agent as AgentStatusWsMessage) + : undefined }) const maximized = ref(false) const draggedWidth = ref(PANEL_MIN_WIDTH) @@ -396,7 +392,6 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { interruptHistorySelection, flagsSettled, comfyAgent, - agentEventsUrl, reportedExhaustionIdentity, reportedFreeUseExposure, reportedFreeUseImpression, From 6ade15009dfc0d988ca0ea7bef9d9973dbe21de8 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 14 Oct 2026 04:45:02 +0000 Subject: [PATCH 08/13] [automated] Apply ESLint and Oxfmt fixes --- src/workbench/extensions/agent/stores/agent/agentPanelStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index b2212190c10..b26c3e2c560 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -79,7 +79,7 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ const comfyAgent = computed(() => { if (import.meta.env.VITE_AGENT_STANDALONE === 'true') return undefined - const agent = api.getServerFeature('agent') + const agent = api.getServerFeature('agent') return typeof agent === 'object' && agent !== null ? (agent as AgentStatusWsMessage) : undefined From cc655a32dee256ba198de8eb4ab61099b2f5d85d Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Wed, 14 Oct 2026 09:59:49 -0700 Subject: [PATCH 09/13] test(agent): drop narration added to the seedServerFlags JSDoc --- browser_tests/fixtures/helpers/FeatureFlagHelper.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/browser_tests/fixtures/helpers/FeatureFlagHelper.ts b/browser_tests/fixtures/helpers/FeatureFlagHelper.ts index 028a5a2632a..df4dbf0abd4 100644 --- a/browser_tests/fixtures/helpers/FeatureFlagHelper.ts +++ b/browser_tests/fixtures/helpers/FeatureFlagHelper.ts @@ -114,8 +114,7 @@ export class FeatureFlagHelper { * later `feature_flags` handshake, as `setServerFlagsPersistent()` does. * * Must be called before `page.goto()`; init scripts persist for the page - * lifetime and cannot be removed. Repeated calls compose: each seed chains to - * the accessor an earlier one installed. + * lifetime and cannot be removed. */ async seedServerFlags(flags: Record): Promise { await this.page.addInitScript((flagMap: Record) => { From 6a7b62cdad162e34b34f703c43a0b7d058aa4947 Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Wed, 14 Oct 2026 10:13:21 -0700 Subject: [PATCH 10/13] fix(agent): ignore an agent feature without a known state; drop seed composition A malformed agent feature ({} or an unknown state) no longer shows an inert Agent button. seedServerFlags goes back to its single accessor: no spec seeds agent and billing flags together. --- browser_tests/fixtures/helpers/FeatureFlagHelper.ts | 2 -- .../extensions/agent/stores/agent/agentPanelStore.test.ts | 4 ++-- .../extensions/agent/stores/agent/agentPanelStore.ts | 6 ++++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/browser_tests/fixtures/helpers/FeatureFlagHelper.ts b/browser_tests/fixtures/helpers/FeatureFlagHelper.ts index df4dbf0abd4..b646f807805 100644 --- a/browser_tests/fixtures/helpers/FeatureFlagHelper.ts +++ b/browser_tests/fixtures/helpers/FeatureFlagHelper.ts @@ -118,13 +118,11 @@ export class FeatureFlagHelper { */ async seedServerFlags(flags: Record): Promise { await this.page.addInitScript((flagMap: Record) => { - const earlier = Object.getOwnPropertyDescriptor(window, 'app') let comfyApp: Window['app'] Object.defineProperty(window, 'app', { configurable: true, get: () => comfyApp, set: (value: Window['app']) => { - earlier?.set?.(value) comfyApp = value const api = value?.api if (!api) return diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts index c1c90bdbbc2..495060c45dc 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.test.ts @@ -33,8 +33,8 @@ describe('agentPanelStore engagement telemetry', () => { expect(store.flagsSettled).toBe(true) }) - it.for([null, false, ''])( - 'ignores an agent feature that is not an object: %j', + it.for([null, false, '', {}, { state: 'unknown' }])( + 'ignores an agent feature without a known state: %j', (agent) => { onTestFinished(() => { api.serverFeatureFlags.value = {} diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index b26c3e2c560..790b589cfae 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -79,8 +79,10 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ const comfyAgent = computed(() => { if (import.meta.env.VITE_AGENT_STANDALONE === 'true') return undefined - const agent = api.getServerFeature('agent') - return typeof agent === 'object' && agent !== null + const agent = api.getServerFeature<{ state?: unknown } | null>('agent') + return agent?.state === 'starting' || + agent?.state === 'ready' || + agent?.state === 'failed' ? (agent as AgentStatusWsMessage) : undefined }) From ef532c1a4b35e5df8b6201f8a757d4e237fa5bff Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Thu, 15 Oct 2026 00:05:02 -0700 Subject: [PATCH 11/13] docs(agent): note resetSocket drops agent; plain pnpm dev needs the feature --- src/scripts/api.ts | 5 +++-- src/workbench/extensions/agent/README.md | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index a012e3b89a6..0db427c7ab6 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -1180,8 +1180,9 @@ export class ComfyApi extends EventTarget { private async replaceSocket(): Promise { const previous = this.socket - // serverFeatureFlags deliberately keeps the previous map: clearing it would - // downgrade every serverSupportsFeature() caller until the next delivery. + // serverFeatureFlags deliberately keeps the previous map (resetSocket drops + // only `agent`): clearing it would downgrade every serverSupportsFeature() + // caller until the next delivery. this.serverFeatureFlagsSettled.value = false // Detach before closing so the previous socket's close handler sees it is // no longer the active socket and does not start a competing reconnect. diff --git a/src/workbench/extensions/agent/README.md b/src/workbench/extensions/agent/README.md index 350040a4426..d4e8dec86f5 100644 --- a/src/workbench/extensions/agent/README.md +++ b/src/workbench/extensions/agent/README.md @@ -42,7 +42,8 @@ publish the same feature, and ComfyUI pushes `agent_status` when it changes; while it is `starting` or `failed` the entry button shows that, inert. Builds with `VITE_AGENT_STANDALONE=true` (the local agent harness) ignore the feature and, in development mode, force the panel on; consent is still required. A -restored open intent cannot bypass consent. +plain `pnpm dev` shows the panel only when the ComfyUI it proxies publishes the +feature. A restored open intent cannot bypass consent. On first use, click **Agent**, then **Start using Comfy Agent**. Acceptance is stored through the hosted Global Settings API under From f050e1eea792322c530bd8f34c347a39ee775b8b Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Sat, 17 Oct 2026 13:01:49 -0700 Subject: [PATCH 12/13] refactor(agent): type the agent feature in the agent domain The panel store and the entry button imported the status type from the comfyui-api zone, which their boundary zones do not allow. Also correct the comfyAgent JSDoc: cloud publishes the same feature, so it is not only the local agent's. --- src/components/topbar/AgentEntryButton.vue | 4 ++-- src/workbench/extensions/agent/schemas/agentApiSchema.ts | 6 ++++++ .../extensions/agent/stores/agent/agentPanelStore.ts | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/topbar/AgentEntryButton.vue b/src/components/topbar/AgentEntryButton.vue index d6b1e99dd92..6467e715c48 100644 --- a/src/components/topbar/AgentEntryButton.vue +++ b/src/components/topbar/AgentEntryButton.vue @@ -44,7 +44,7 @@ import { cn } from '@comfyorg/tailwind-utils' import Button from '@/components/ui/button/Button.vue' -import type { AgentStatusWsMessage } from '@/platform/remote/comfyui/execution/types' +import type { AgentServerFeature } from '@/workbench/extensions/agent/schemas/agentApiSchema' const { active = false, @@ -55,6 +55,6 @@ const { /** Draw attention to the button for a user who has never opened the panel. */ inviting?: boolean /** ComfyUI's agent while it is not ready: shown, but inert. */ - comfyAgent?: AgentStatusWsMessage + comfyAgent?: AgentServerFeature }>() diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.ts index 8e20bf9ee0c..d3e8ec70017 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.ts @@ -373,3 +373,9 @@ export function parseAgentWsEvent( export const zAgentIdentity = zGeneratedAgentIdentity.extend({ user_id: z.string().min(1) }) + +/** The server's `agent` feature, pushed again on every change. */ +export interface AgentServerFeature { + state: 'starting' | 'ready' | 'failed' + reason?: string | null +} diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts index 790b589cfae..bff2b367ab0 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStore.ts @@ -7,7 +7,6 @@ import { SIDEBAR_MIN_WIDTH, SIDE_TOOLBAR_WIDTH } from '@/constants/splitterConstants' -import type { AgentStatusWsMessage } from '@/platform/remote/comfyui/execution/types' import { useTelemetry } from '@/platform/telemetry' import type { AgentPanelCloseSource, @@ -16,6 +15,7 @@ import type { import type { ComfyWorkflow } from '@/platform/workflow/management/stores/comfyWorkflow' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { api } from '@/scripts/api' +import type { AgentServerFeature } from '@/workbench/extensions/agent/schemas/agentApiSchema' import type { CreditTransitionNoticeEvent, @@ -76,14 +76,14 @@ export const useAgentPanelStore = defineStore('agentPanel', () => { const gateSettled = ref(false) const view = shallowRef({ screen: 'chat' }) const flagsSettled = computed(() => api.serverFeatureFlagsSettled.value) - /** The local agent ComfyUI runs with `--enable-agent`; absent otherwise. */ + /** The server's `agent` feature; undefined unless its state is known. */ const comfyAgent = computed(() => { if (import.meta.env.VITE_AGENT_STANDALONE === 'true') return undefined const agent = api.getServerFeature<{ state?: unknown } | null>('agent') return agent?.state === 'starting' || agent?.state === 'ready' || agent?.state === 'failed' - ? (agent as AgentStatusWsMessage) + ? (agent as AgentServerFeature) : undefined }) const maximized = ref(false) From aa3ac101027d1a7651bb6f6597d5d5b8b2b6e132 Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Sat, 17 Oct 2026 13:01:49 -0700 Subject: [PATCH 13/13] test(api): pin that a handshake reply after an agent_status push sets the agent feature --- src/scripts/api.featureFlags.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/scripts/api.featureFlags.test.ts b/src/scripts/api.featureFlags.test.ts index a03ab2322f4..bccf88af795 100644 --- a/src/scripts/api.featureFlags.test.ts +++ b/src/scripts/api.featureFlags.test.ts @@ -162,6 +162,26 @@ describe('API Feature Flags', () => { expect(api.getServerFeature('api_version')).toBe('1.0.0') }) + it('takes the agent feature from a handshake reply that follows an earlier agent_status push', () => { + void api.init() + const send = (type: string, data: unknown) => + wsEventHandlers['message']({ data: JSON.stringify({ type, data }) }) + + send('agent_status', { state: 'starting', reason: null }) + expect(api.serverFeatureFlagsSettled.value).toBe(false) + + send('feature_flags', { + api_version: '1.0.0', + agent: { state: 'ready', reason: null } + }) + + expect(api.getServerFeature('agent')).toEqual({ + state: 'ready', + reason: null + }) + expect(api.serverFeatureFlagsSettled.value).toBe(true) + }) + it('settles feature flags immediately when the server delivers an empty map', () => { void api.init()