Skip to content
Merged
7 changes: 0 additions & 7 deletions code/core/src/builder-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { cp, rm, writeFile } from 'node:fs/promises';

import { stringifyProcessEnvs } from 'storybook/internal/common';
import { logger } from 'storybook/internal/node-logger';
import { getLastEvents, getSessionId } from 'storybook/internal/telemetry';

import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
import { resolveModulePath } from 'exsolve';
Expand Down Expand Up @@ -200,9 +199,6 @@ const starter: StarterFunction = async function* starterGeneratorFn({

// Build additional global values
const globals: Record<string, any> = await buildFrameworkGlobalsFromOptions(options);
// Pass along recent CLI events to customise user onboarding and telemetry after `sb ai` commands.
globals.STORYBOOK_LAST_EVENTS = await getLastEvents();
globals.STORYBOOK_SESSION_ID = await getSessionId();

yield;

Expand Down Expand Up @@ -301,9 +297,6 @@ const builder: BuilderFunction = async function* builderGeneratorFn({ startTime,

// Build additional global values
const globals: Record<string, any> = await buildFrameworkGlobalsFromOptions(options);
// Builds are long-lasting and shouldn't account for CLI events prior to building.
globals.STORYBOOK_LAST_EVENTS = {};
globals.STORYBOOK_SESSION_ID = undefined;

yield;

Expand Down
2 changes: 1 addition & 1 deletion code/core/src/core-server/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const experimental_serverChannel = async (
await setTelemetryEnabled(!coreOptions?.disableTelemetry);

initAIAnalyticsChannel(channel, options, () => storyIndexGeneratorPromise);
initializeChecklist();
initializeChecklist(channel);
initializeWhatsNew(channel, options);
initializeSaveStory(channel, options);
initFileSearchChannel(channel, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ describe('ghostStoriesChannel', () => {
});

expect(mockTelemetry.getLastEvents).toHaveBeenCalled();
// getSessionId is no longer checked by ghost stories — session matching
// was removed to support mid-session ai-setup triggers.
expect(mockTelemetry.getSessionId).not.toHaveBeenCalled();
expect(mockTelemetry.getStorybookMetadata).not.toHaveBeenCalled();
expect(mockStoryGeneration.getComponentCandidates).not.toHaveBeenCalled();
Comment thread
yannbf marked this conversation as resolved.
Expand All @@ -385,7 +387,6 @@ describe('ghostStoriesChannel', () => {
});

expect(mockTelemetry.getLastEvents).toHaveBeenCalled();
expect(mockTelemetry.getSessionId).toHaveBeenCalled();
expect(mockTelemetry.getStorybookMetadata).toHaveBeenCalled();
expect(mockStoryGeneration.getComponentCandidates).not.toHaveBeenCalled();
});
Expand All @@ -411,7 +412,6 @@ describe('ghostStoriesChannel', () => {
});

expect(mockTelemetry.getLastEvents).toHaveBeenCalled();
expect(mockTelemetry.getSessionId).toHaveBeenCalled();
expect(mockTelemetry.getStorybookMetadata).toHaveBeenCalled();
expect(mockStoryGeneration.getComponentCandidates).not.toHaveBeenCalled();
});
Expand Down
17 changes: 4 additions & 13 deletions code/core/src/core-server/server-channel/ghost-stories-channel.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { Channel } from 'storybook/internal/channels';
import { GHOST_STORIES_REQUEST, GHOST_STORIES_RESPONSE } from 'storybook/internal/core-events';
import {
getLastEvents,
getSessionId,
getStorybookMetadata,
telemetry,
} from 'storybook/internal/telemetry';
import { logger } from 'storybook/internal/node-logger';
import { getLastEvents, getStorybookMetadata, telemetry } from 'storybook/internal/telemetry';
import type { Options } from 'storybook/internal/types';

import { getComponentCandidates } from '../utils/ghost-stories/get-candidates.ts';
Expand Down Expand Up @@ -48,11 +42,9 @@ export function initGhostStoriesChannel(channel: Channel, options: Options) {
throw new SkipGhostStoriesTelemetry();
}

const sessionId = await getSessionId();
// We only capture ghost stories in the first ever session since init or ai setup.
if (lastRelevantEvent.body?.sessionId && lastRelevantEvent.body.sessionId !== sessionId) {
throw new SkipGhostStoriesTelemetry();
}
// No session-ID match: `storybook ai setup` runs as a separate CLI
// process, so its sessionId never matches the dev server's. The
// `lastGhostStoriesRun` guard above is enough to enforce once-per-project.

const metadata = await getStorybookMetadata(options.configDir);
const isReactStorybook = metadata?.renderer?.includes('@storybook/react');
Expand All @@ -71,7 +63,6 @@ export function initGhostStoriesChannel(channel: Channel, options: Options) {
// disturb end user activities.
const isIdle = await waitForIdleVitest();
if (!isIdle) {
logger.debug('GHOST_STORIES_REQUEST timed out waiting for vitest to be available.');
return;
}

Expand Down
Loading
Loading