Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

[Metabot] Remove dead chart analysis code (#80371)

Sloan Sparger1d961d5cc5ea
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 7e5027bd51e..61d5dc81305 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -1364,7 +1364,6 @@
metabot
{:team "Metabot"
:api #{metabase.metabot.api
- metabase.metabot.api.entity-analysis
metabase.metabot.config
metabase.metabot.core
metabase.metabot.init
diff --git a/.clj-kondo/ratchets.edn b/.clj-kondo/ratchets.edn
index d162cd8fa53..301f12c82a7 100644
--- a/.clj-kondo/ratchets.edn
+++ b/.clj-kondo/ratchets.edn
@@ -24,7 +24,7 @@
:metabase/namespace-name 4
:metabase/prefer-with-dynamic-fn-redefs 28
:metabase/test-helpers-use-non-thread-safe-functions 17
- :metabase/validate-defendpoint-has-response-schema 441
+ :metabase/validate-defendpoint-has-response-schema 440
:metabase/validate-defendpoint-query-params-use-kebab-case 47
:metabase/validate-defendpoint-route-uses-kebab-case 44
:metabase/validate-deftest 9
diff --git a/frontend/src/metabase-types/api/ai-entity-analysis.ts b/frontend/src/metabase-types/api/ai-entity-analysis.ts
deleted file mode 100644
index de5d65faf24..00000000000
--- a/frontend/src/metabase-types/api/ai-entity-analysis.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-export interface AIEntityAnalysisResponse {
- summary: string;
-}
-
-export interface TimelineEventInfo {
- name: string;
- description?: string;
- timestamp: string;
-}
-
-export interface AIQuestionAnalysisParams {
- imageBase64: string;
- name?: string;
- description?: string;
- timelineEvents?: TimelineEventInfo[];
-}
diff --git a/frontend/src/metabase-types/api/index.ts b/frontend/src/metabase-types/api/index.ts
index d367ce804e9..06140abb0d9 100644
--- a/frontend/src/metabase-types/api/index.ts
+++ b/frontend/src/metabase-types/api/index.ts
@@ -3,7 +3,6 @@ export * from "./activity";
export * from "./admin";
export * from "./advanced-config";
export * from "./advanced-permission";
-export * from "./ai-entity-analysis";
export * from "./alert";
export * from "./autocomplete";
export * from "./automagic-dashboards";
diff --git a/frontend/src/metabase/api/ai-entity-analysis.ts b/frontend/src/metabase/api/ai-entity-analysis.ts
deleted file mode 100644
index bd76f300281..00000000000
--- a/frontend/src/metabase/api/ai-entity-analysis.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import type {
- AIEntityAnalysisResponse,
- AIQuestionAnalysisParams,
-} from "metabase-types/api";
-
-import { Api } from "./api";
-
-const DEFAULT_TIMEOUT = 30000;
-
-export const aiEntityAnalysisApi = Api.injectEndpoints({
- endpoints: (builder) => ({
- analyzeChart: builder.mutation<
- AIEntityAnalysisResponse,
- AIQuestionAnalysisParams
- >({
- query: ({ imageBase64, name, description, timelineEvents }) => {
- return {
- url: "/api/ai-entity-analysis/analyze-chart",
- method: "POST",
- body: {
- image_base64: imageBase64,
- name,
- description,
- timeline_events: timelineEvents,
- },
- signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
- };
- },
- }),
- }),
-});
-
-export const { useAnalyzeChartMutation } = aiEntityAnalysisApi;
diff --git a/frontend/src/metabase/api/index.ts b/frontend/src/metabase/api/index.ts
index fce64ed0526..ceadad3425f 100644
--- a/frontend/src/metabase/api/index.ts
+++ b/frontend/src/metabase/api/index.ts
@@ -1,6 +1,5 @@
export * from "./action";
export * from "./activity";
-export * from "./ai-entity-analysis";
export * from "./analytics";
export * from "./api";
export * from "./automagic-dashboards";
diff --git a/frontend/src/metabase/dashboard/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsx b/frontend/src/metabase/dashboard/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsx
deleted file mode 100644
index 044b7dfc966..00000000000
--- a/frontend/src/metabase/dashboard/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import { t } from "ttag";
-
-import { Sidebar } from "metabase/common/components/Sidebar";
-import { AIAnalysisContentWrapper } from "metabase/metabot/components/AIAnalysisContentWrapper/AIAnalysisContentWrapper";
-import { useDashCardAnalysis } from "metabase/metabot/hooks/useDashCardAnalysis";
-import { useSelector } from "metabase/redux";
-
-import { useDashboardContext } from "../../context";
-import { getIsDashCardsLoadingComplete } from "../../selectors";
-
-export function AIDashboardAnalysisSidebar() {
- const { sidebar, closeSidebar } = useDashboardContext();
- const dashcardId = sidebar.props?.dashcardId;
- const isDashCardsLoadingComplete = useSelector(getIsDashCardsLoadingComplete);
-
- const dashcards = useSelector((state) => state.dashboard.dashcards);
- const dashcard = dashcardId ? dashcards[dashcardId] : null;
- const card = dashcard?.card;
-
- const { analysisData, isLoading } = useDashCardAnalysis({
- dashcardId,
- name: card?.name,
- description: card?.description,
- isLoadingComplete: isDashCardsLoadingComplete,
- isEnabled: !!dashcardId,
- });
-
- return (
- <Sidebar data-testid="dashboard-analysis-sidebar">
- <AIAnalysisContentWrapper
- title={t`Explain this chart`}
- explanation={analysisData}
- isLoading={isLoading}
- onClose={closeSidebar}
- />
- </Sidebar>
- );
-}
diff --git a/frontend/src/metabase/dashboard/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.unit.spec.tsx b/frontend/src/metabase/dashboard/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.unit.spec.tsx
deleted file mode 100644
index 002d4ff6844..00000000000
--- a/frontend/src/metabase/dashboard/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.unit.spec.tsx
+++ /dev/null
@@ -1,179 +0,0 @@
-import { screen, waitFor } from "@testing-library/react";
-
-import { setupAnalyzeChartEndpoint } from "__support__/server-mocks";
-import { renderWithProviders } from "__support__/ui";
-import { MockDashboardContext } from "metabase/dashboard/context/mock-context";
-import { createMockDashboardState } from "metabase/redux/store/mocks";
-import type { AIEntityAnalysisResponse, Card } from "metabase-types/api";
-import {
- createMockCard,
- createMockDashboard,
- createMockDashboardCard,
-} from "metabase-types/api/mocks";
-
-import { AIDashboardAnalysisSidebar } from "./AIDashboardAnalysisSidebar";
-
-jest.mock("metabase/visualizations/lib/image-exports", () => ({
- getDashboardImage: () => Promise.resolve("test-base64"),
- getChartImagePngDataUri: () => "test-base64",
- getChartSelector: () => "#chart",
-}));
-
-describe("AIDashboardAnalysisSidebar", () => {
- beforeEach(() => {
- jest.clearAllMocks();
- });
-
- it("should show chart title and analysis when dashcardId is provided", async () => {
- const dashboard = createMockDashboard();
- const dashcardId = 1;
- const mockResponse: AIEntityAnalysisResponse = {
- summary: "Test chart analysis",
- };
-
- setupAnalyzeChartEndpoint(mockResponse);
-
- const mockCard: Card = createMockCard({
- name: "Test Chart",
- description: "Test Description",
- });
-
- const mockDashcard = createMockDashboardCard({
- id: dashcardId,
- dashboard_id: dashboard.id,
- card_id: mockCard.id,
- card: mockCard,
- });
-
- const dashboardState = createMockDashboardState({
- dashboardId: dashboard.id,
- dashboards: {
- [dashboard.id]: {
- ...dashboard,
- dashcards: [dashcardId],
- tabs: [],
- },
- },
- dashcards: {
- [dashcardId]: mockDashcard,
- },
- loadingDashCards: {
- loadingStatus: "complete",
- loadingIds: [],
- startTime: null,
- endTime: null,
- },
- });
-
- renderWithProviders(
- <MockDashboardContext sidebar={{ props: { dashcardId } }}>
- <AIDashboardAnalysisSidebar />
- </MockDashboardContext>,
- {
- storeInitialState: {
- dashboard: dashboardState,
- },
- },
- );
-
- expect(screen.getByText("Explain this chart")).toBeInTheDocument();
-
- await waitFor(() => {
- expect(screen.getByText("Test chart analysis")).toBeInTheDocument();
- });
- });
-
- it("should reload analysis when dashcardId changes", async () => {
- const dashboard = createMockDashboard();
- const firstDashcardId = 1;
- const secondDashcardId = 2;
-
- const firstChartResponse: AIEntityAnalysisResponse = {
- summary: "First chart analysis",
- };
-
- const secondChartResponse: AIEntityAnalysisResponse = {
- summary: "Second chart analysis",
- };
-
- setupAnalyzeChartEndpoint(firstChartResponse);
-
- const firstMockCard = createMockCard({
- id: 10,
- name: "First Chart",
- description: "First Description",
- });
-
- const secondMockCard = createMockCard({
- id: 20,
- name: "Second Chart",
- description: "Second Description",
- });
-
- const firstMockDashcard = createMockDashboardCard({
- id: firstDashcardId,
- dashboard_id: dashboard.id,
- card_id: firstMockCard.id,
- card: firstMockCard,
- });
-
- const secondMockDashcard = createMockDashboardCard({
- id: secondDashcardId,
- dashboard_id: dashboard.id,
- card_id: secondMockCard.id,
- card: secondMockCard,
- });
-
- const dashboardState = createMockDashboardState({
- dashboardId: dashboard.id,
- dashboards: {
- [dashboard.id]: {
- ...dashboard,
- dashcards: [firstDashcardId, secondDashcardId],
- tabs: [],
- },
- },
- dashcards: {
- [firstDashcardId]: firstMockDashcard,
- [secondDashcardId]: secondMockDashcard,
- },
- loadingDashCards: {
- loadingStatus: "complete",
- loadingIds: [],
- startTime: null,
- endTime: null,
- },
- });
-
- const { rerender } = renderWithProviders(
- <MockDashboardContext
- sidebar={{ props: { dashcardId: firstDashcardId } }}
- >
- <AIDashboardAnalysisSidebar />
- </MockDashboardContext>,
- {
- storeInitialState: {
- dashboard: dashboardState,
- },
- },
- );
-
- await waitFor(() => {
- expect(screen.getByText("First chart analysis")).toBeInTheDocument();
- });
-
- setupAnalyzeChartEndpoint(secondChartResponse);
-
- rerender(
- <MockDashboardContext
- sidebar={{ props: { dashcardId: secondDashcardId } }}
- >
- <AIDashboardAnalysisSidebar />
- </MockDashboardContext>,
- );
-
- await waitFor(() => {
- expect(screen.getByText("Second chart analysis")).toBeInTheDocument();
- });
- });
-});
diff --git a/frontend/src/metabase/dashboard/components/DashboardSidebars.tsx b/frontend/src/metabase/dashboard/components/DashboardSidebars.tsx
index f54905b4610..e5a71ccf95b 100644
--- a/frontend/src/metabase/dashboard/components/DashboardSidebars.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardSidebars.tsx
@@ -1,7 +1,6 @@
import { SIDEBAR_NAME } from "metabase/dashboard/constants";
import { useDashboardContext } from "metabase/dashboard/context";
-import { AIDashboardAnalysisSidebar } from "./AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar";
import { ActionSidebar } from "./ActionSidebar";
import { AddCardSidebar } from "./AddCardSidebar";
import { ClickBehaviorSidebar } from "./ClickBehaviorSidebar/ClickBehaviorSidebar";
@@ -33,8 +32,6 @@ export function DashboardSidebars() {
return <DashboardSubscriptionsSidebar />;
case SIDEBAR_NAME.info:
return <DashboardInfoSidebar />;
- case SIDEBAR_NAME.analyze:
- return <AIDashboardAnalysisSidebar />;
default:
return null;
}
diff --git a/frontend/src/metabase/dashboard/constants.ts b/frontend/src/metabase/dashboard/constants.ts
index 725cf51ab36..5ded66c4568 100644
--- a/frontend/src/metabase/dashboard/constants.ts
+++ b/frontend/src/metabase/dashboard/constants.ts
@@ -14,7 +14,6 @@ export const SIDEBAR_NAME: Record<DashboardSidebarName, DashboardSidebarName> =
sharing: "sharing",
settings: "settings",
info: "info",
- analyze: "analyze",
};
export const INITIAL_DASHBOARD_STATE: DashboardState = {
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisContent/AIAnalysisContent.module.css b/frontend/src/metabase/metabot/components/AIAnalysisContent/AIAnalysisContent.module.css
deleted file mode 100644
index 398df5df6d9..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisContent/AIAnalysisContent.module.css
+++ /dev/null
@@ -1,44 +0,0 @@
-.analysisWrapper {
- line-height: 1.5;
-}
-
-.analysisWrapper p {
- margin-bottom: 1rem;
-}
-
-.analysisWrapper h1,
-.analysisWrapper h2,
-.analysisWrapper h3,
-.analysisWrapper h4,
-.analysisWrapper h5,
-.analysisWrapper h6 {
- margin-bottom: 1rem;
-}
-
-.analysisWrapper ul,
-.analysisWrapper ol {
- padding-left: 1.5rem;
- margin-bottom: 1rem;
-}
-
-.analysisWrapper ul {
- list-style-type: disc;
-}
-
-.analysisWrapper ol {
- list-style-type: decimal;
-}
-
-.analysisWrapper li {
- margin-bottom: 0.5rem;
- line-height: 1.5;
-}
-
-.analysisWrapper li p {
- line-height: 1.5;
-}
-
-.analysisWrapper li > ul,
-.analysisWrapper li > ol {
- margin-top: 0.5rem;
-}
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisContent/AIAnalysisContent.tsx b/frontend/src/metabase/metabot/components/AIAnalysisContent/AIAnalysisContent.tsx
deleted file mode 100644
index 36a7f041cd6..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisContent/AIAnalysisContent.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import { Markdown } from "metabase/common/components/Markdown";
-import { Repeat, Skeleton } from "metabase/ui";
-
-import S from "./AIAnalysisContent.module.css";
-
-export interface AIAnalysisContentProps {
- explanation?: string;
- isLoading?: boolean;
-}
-
-export function AIAnalysisContent({
- explanation,
- isLoading,
-}: AIAnalysisContentProps) {
- const shouldShowLoading = isLoading || explanation == null;
-
- return (
- <div>
- {shouldShowLoading ? (
- <Repeat times={8}>
- <Skeleton h="1rem" natural mb="0.5rem" />
- </Repeat>
- ) : (
- <div className={S.analysisWrapper}>
- <Markdown>{explanation}</Markdown>
- </div>
- )}
- </div>
- );
-}
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisContentWrapper/AIAnalysisContentWrapper.tsx b/frontend/src/metabase/metabot/components/AIAnalysisContentWrapper/AIAnalysisContentWrapper.tsx
deleted file mode 100644
index d26d607af82..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisContentWrapper/AIAnalysisContentWrapper.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { t } from "ttag";
-
-import { CopyButton } from "metabase/common/components/CopyButton";
-import { MetabotIcon } from "metabase/metabot/components/MetabotIcon";
-import { Button, Flex, Group, Icon, Stack, Text } from "metabase/ui";
-
-import { AIAnalysisContent } from "../AIAnalysisContent/AIAnalysisContent";
-
-export interface AIAnalysisContentWrapperProps {
- title: string;
- explanation?: string;
- isLoading: boolean;
- onClose?: () => void;
-}
-
-export function AIAnalysisContentWrapper({
- title,
- explanation,
- isLoading,
- onClose,
-}: AIAnalysisContentWrapperProps) {
- return (
- <Stack h="100%" p="lg" style={{ overflowY: "auto" }}>
- <Group justify="space-between" align="center">
- <Flex align="center" gap="xs">
- <MetabotIcon />
- <Text fz="1.17em" ml="xs" fw="bold">
- {title}
- </Text>
- </Flex>
- <Group gap="xs">
- {explanation && (
- <CopyButton
- value={explanation}
- aria-label={t`Copy`}
- style={{ color: "var(--mb-color-text-secondary)" }}
- />
- )}
- {onClose && (
- <Button
- variant="subtle"
- size="compact-sm"
- p={4}
- onClick={onClose}
- aria-label={t`Close`}
- c="text-secondary"
- >
- <Icon name="close" size={16} />
- </Button>
- )}
- </Group>
- </Group>
- <AIAnalysisContent explanation={explanation} isLoading={isLoading} />
- </Stack>
- );
-}
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/AIAnalysisSidebar.tsx b/frontend/src/metabase/metabot/components/AIAnalysisSidebar/AIAnalysisSidebar.tsx
deleted file mode 100644
index d3935e598a4..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/AIAnalysisSidebar.tsx
+++ /dev/null
@@ -1,152 +0,0 @@
-import { useDisclosure } from "@mantine/hooks";
-import { useEffect, useRef } from "react";
-import { usePrevious } from "react-use";
-import { t } from "ttag";
-
-import { useAnalyzeChartMutation } from "metabase/api";
-import { CopyButton } from "metabase/common/components/CopyButton";
-import { SidebarContent } from "metabase/common/components/SidebarContent";
-import { AIAnalysisContent } from "metabase/metabot/components/AIAnalysisContent/AIAnalysisContent";
-import { AIProviderConfigurationModal } from "metabase/metabot/components/AIProviderConfigurationModal";
-import { AIProviderConfigurationNotice } from "metabase/metabot/components/AIProviderConfigurationNotice";
-import { useSetting } from "metabase/settings";
-import { Box } from "metabase/ui";
-import {
- getChartImagePngDataUri,
- getChartSelector,
-} from "metabase/visualizations/lib/image-exports";
-import type Question from "metabase-lib/v1/Question";
-import type { Timeline, TimelineEvent } from "metabase-types/api";
-
-import { getTimelineEventsForAnalysis } from "./utils";
-
-// This is a hack to ensure visualizations have rendered after data loading, as they can render asynchronously.
-const RENDER_DELAY_MS = 100;
-
-export interface AIAnalysisSidebarProps {
- question: Question;
- isLoadingComplete: boolean;
- className?: string;
- onClose?: () => void;
- timelines?: Timeline[];
- visibleTimelineEvents?: TimelineEvent[];
-}
-
-export function AIAnalysisSidebar({
- question,
- isLoadingComplete,
- timelines,
- visibleTimelineEvents,
- className,
- onClose,
-}: AIAnalysisSidebarProps) {
- const previousQuestion = usePrevious(question);
- const [
- isAiProviderConfigurationModalOpen,
- {
- close: closeAiProviderConfigurationModal,
- open: openAiProviderConfigurationModal,
- },
- ] = useDisclosure(false);
- const isConfigured = !!useSetting("llm-metabot-configured?");
- const [analyzeChart, { data: analysisData }] = useAnalyzeChartMutation();
- const pendingAnalysisRef = useRef(false);
- const analysisTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
-
- useEffect(() => {
- const isQueryDirty = previousQuestion
- ? question.isQueryDirtyComparedTo(previousQuestion)
- : true;
-
- if (isQueryDirty) {
- pendingAnalysisRef.current = true;
- }
- }, [previousQuestion, question]);
-
- useEffect(() => {
- if (!isConfigured || !pendingAnalysisRef.current || !isLoadingComplete) {
- return;
- }
-
- const questionCollectionId = question.card().collection_id;
- const timelineEvents =
- questionCollectionId == null
- ? []
- : getTimelineEventsForAnalysis(
- visibleTimelineEvents ?? [],
- timelines ?? [],
- questionCollectionId,
- );
-
- analysisTimeoutRef.current = setTimeout(async () => {
- const imageBase64 = await getChartImagePngDataUri(
- getChartSelector({ cardId: question.id() }),
- );
-
- if (imageBase64) {
- await analyzeChart({
- imageBase64,
- name: question.card().name,
- description: question.card().description ?? undefined,
- timelineEvents,
- });
- }
-
- pendingAnalysisRef.current = false;
- analysisTimeoutRef.current = null;
- }, RENDER_DELAY_MS);
-
- return () => {
- if (analysisTimeoutRef.current) {
- clearTimeout(analysisTimeoutRef.current);
- analysisTimeoutRef.current = null;
- }
- };
- }, [
- analyzeChart,
- isConfigured,
- isLoadingComplete,
- question,
- timelines,
- visibleTimelineEvents,
- ]);
-
- const renderCopyButton = () => {
- if (!isConfigured || !analysisData?.summary) {
- return null;
- }
-
- return (
- <CopyButton
- value={analysisData.summary}
- style={{ color: "var(--mb-color-text-secondary)" }}
- aria-label={t`Copy`}
- />
- );
- };
-
- return (
- <SidebarContent
- className={className}
- title={t`Explain these results`}
- onClose={onClose}
- icon="metabot"
- headerActions={renderCopyButton()}
- >
- <Box px="1.5rem" py="0.5rem">
- {isConfigured ? (
- <AIAnalysisContent explanation={analysisData?.summary} />
- ) : (
- <AIProviderConfigurationNotice
- featureName={t`chart analysis`}
- onConfigureAi={openAiProviderConfigurationModal}
- />
- )}
- <AIProviderConfigurationModal
- opened={isAiProviderConfigurationModalOpen}
- onClose={closeAiProviderConfigurationModal}
- />
- </Box>
- </SidebarContent>
- );
-}
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/AIAnalysisSidebar.unit.spec.tsx b/frontend/src/metabase/metabot/components/AIAnalysisSidebar/AIAnalysisSidebar.unit.spec.tsx
deleted file mode 100644
index 52b96b2c207..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/AIAnalysisSidebar.unit.spec.tsx
+++ /dev/null
@@ -1,193 +0,0 @@
-import { screen, waitFor } from "@testing-library/react";
-import fetchMock from "fetch-mock";
-import _ from "underscore";
-
-import {
- setupAnalyzeChartEndpoint,
- setupUserMetabotPermissionsEndpoint,
-} from "__support__/server-mocks";
-import { mockSettings } from "__support__/settings";
-import { renderWithProviders } from "__support__/ui";
-import Question from "metabase-lib/v1/Question";
-import type { AIEntityAnalysisResponse } from "metabase-types/api";
-import {
- createMockCard,
- createMockTimeline,
- createMockTimelineEvent,
- createMockUser,
-} from "metabase-types/api/mocks";
-
-import { AIAnalysisSidebar } from "./AIAnalysisSidebar";
-
-jest.mock("metabase/visualizations/lib/image-exports", () => ({
- getChartImagePngDataUri: () => Promise.resolve("test-base64"),
- getChartSelector: () => "#chart",
-}));
-
-describe("AIAnalysisSidebar", () => {
- beforeEach(() => {
- jest.clearAllMocks();
- });
-
- it("should fetch trigger analysis when question changes", async () => {
- const question = new Question(createMockCard());
- const mockResponse: AIEntityAnalysisResponse = {
- summary: "Test analysis",
- };
-
- setupAnalyzeChartEndpoint(mockResponse);
-
- renderWithProviders(
- <AIAnalysisSidebar
- question={question}
- isLoadingComplete
- onClose={jest.fn()}
- />,
- {
- storeInitialState: {
- settings: mockSettings({ "llm-metabot-configured?": true }),
- },
- },
- );
-
- await waitFor(() => {
- expect(screen.getByText("Test analysis")).toBeInTheDocument();
- });
-
- const copyButton = await screen.findByLabelText("copy icon");
- expect(copyButton).toBeInTheDocument();
- });
-
- it("should send only visible timeline events with ones from the same collection", async () => {
- const collectionId = 42;
-
- const question = new Question(
- createMockCard({
- collection_id: collectionId,
- }),
- );
-
- const timelineEventSameCollection = createMockTimelineEvent({
- id: 1,
- name: "Release v1",
- description: "Released version 1",
- timestamp: "2024-05-12T00:00:00Z",
- });
- const invisibleTimelineEventSameCollection = createMockTimelineEvent({
- id: 2,
- name: "Beta Release v1",
- description: "Beta release",
- timestamp: "2024-04-12T00:00:00Z",
- });
- const visibleTimelineEventFromAnotherCollection = createMockTimelineEvent({
- id: 3,
- name: "Marketing Launch",
- description: "Rolled out our new website",
- timestamp: "2024-03-12T00:00:00Z",
- });
-
- const timelines = [
- createMockTimeline({
- collection_id: collectionId,
- events: [
- timelineEventSameCollection,
- invisibleTimelineEventSameCollection,
- ],
- }),
- createMockTimeline({
- // Different collection – should be ignored
- collection_id: collectionId + 1,
- events: [
- createMockTimelineEvent({
- id: 4,
- name: "Irrelevant event",
- description: "Should be filtered out",
- timestamp: "2024-05-13T00:00:00Z",
- }),
- visibleTimelineEventFromAnotherCollection,
- ],
- }),
- ];
-
- const visibleTimelineEvents = [
- timelineEventSameCollection,
- visibleTimelineEventFromAnotherCollection,
- ];
-
- const mockResponse: AIEntityAnalysisResponse = {
- summary: "Filtered analysis",
- };
-
- setupAnalyzeChartEndpoint(mockResponse);
-
- renderWithProviders(
- <AIAnalysisSidebar
- question={question}
- isLoadingComplete
- visibleTimelineEvents={visibleTimelineEvents}
- onClose={jest.fn()}
- timelines={timelines}
- />,
- {
- storeInitialState: {
- settings: mockSettings({ "llm-metabot-configured?": true }),
- },
- },
- );
-
- await waitFor(() => {
- expect(screen.getByText("Filtered analysis")).toBeInTheDocument();
- });
-
- const lastCallRequest = fetchMock.callHistory.lastCall(
- "path:/api/ai-entity-analysis/analyze-chart",
- )?.request;
- const body = await lastCallRequest?.json();
-
- const analysisEventsFields = ["name", "description", "timestamp"];
- expect(body.timeline_events).toHaveLength(3);
- expect(body.timeline_events[0]).toMatchObject(
- _.pick(timelineEventSameCollection, analysisEventsFields),
- );
- expect(body.timeline_events[1]).toMatchObject(
- _.pick(invisibleTimelineEventSameCollection, analysisEventsFields),
- );
- expect(body.timeline_events[2]).toMatchObject(
- _.pick(visibleTimelineEventFromAnotherCollection, analysisEventsFields),
- );
- });
-
- it("should show a configuration notice instead of running analysis when AI is not configured", async () => {
- const question = new Question(createMockCard());
-
- setupUserMetabotPermissionsEndpoint();
-
- renderWithProviders(
- <AIAnalysisSidebar
- question={question}
- isLoadingComplete
- onClose={jest.fn()}
- />,
- {
- storeInitialState: {
- currentUser: createMockUser({ is_superuser: true }),
- settings: mockSettings({ "llm-metabot-configured?": false }),
- },
- },
- );
-
- expect(
- await screen.findByText("To use chart analysis, please", {
- exact: false,
- }),
- ).toBeInTheDocument();
- expect(
- screen.getByRole("button", { name: "connect to a model" }),
- ).toBeInTheDocument();
- expect(
- fetchMock.callHistory.called(
- "path:/api/ai-entity-analysis/analyze-chart",
- ),
- ).toBe(false);
- });
-});
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/index.ts b/frontend/src/metabase/metabot/components/AIAnalysisSidebar/index.ts
deleted file mode 100644
index 8a48b01e189..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { AIAnalysisSidebar } from "./AIAnalysisSidebar";
-export type { AIAnalysisSidebarProps } from "./AIAnalysisSidebar";
diff --git a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/utils.ts b/frontend/src/metabase/metabot/components/AIAnalysisSidebar/utils.ts
deleted file mode 100644
index ae43d8e816d..00000000000
--- a/frontend/src/metabase/metabot/components/AIAnalysisSidebar/utils.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import { isNotNull } from "metabase/utils/types";
-import type { CollectionId, Timeline, TimelineEvent } from "metabase-types/api";
-
-export const getTimelineEventsForAnalysis = (
- visibleTimelineEvents: TimelineEvent[],
- timelines: Timeline[],
- questionCollectionId: CollectionId,
-) => {
- const sameCollectionTimelineEvents = timelines
- .filter((timeline) => timeline.collection_id === questionCollectionId)
- .flatMap((timeline) => timeline.events ?? [])
- .filter(isNotNull);
-
- const sameCollectionTimelineEventIds = new Set(
- sameCollectionTimelineEvents.map((e) => e.id),
- );
-
- const visibleEventsFromOtherCollections = visibleTimelineEvents.filter(
- (event) => !sameCollectionTimelineEventIds.has(event.id),
- );
-
- return [
- ...sameCollectionTimelineEvents,
- ...visibleEventsFromOtherCollections,
- ].map((event) => ({
- name: event.name,
- description: event.description ?? undefined,
- timestamp: event.timestamp,
- }));
-};
diff --git a/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx b/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx
index 7d605be7f56..25433be8b5c 100644
--- a/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx
+++ b/frontend/src/metabase/metabot/components/AIMarkdown/AIMarkdown.tsx
@@ -1,5 +1,3 @@
-// TODO: consolidate this component w/ AIAnalysisContent
-
import cx from "classnames";
import {
Children,
diff --git a/frontend/src/metabase/metabot/hooks/index.ts b/frontend/src/metabase/metabot/hooks/index.ts
index 58cd431c9e7..e7725a1d3c9 100644
--- a/frontend/src/metabase/metabot/hooks/index.ts
+++ b/frontend/src/metabase/metabot/hooks/index.ts
@@ -6,5 +6,4 @@ export { useBranchableMessages } from "./use-branchable-messages";
export { useMetabotAgent } from "./use-metabot-agent";
export { useMetabotConversation } from "./use-metabot-conversation";
export { useMetabotAgentsManager } from "./use-metabot-agents-manager";
-export { useDashCardAnalysis } from "./useDashCardAnalysis";
export { useUserMetabotPermissions } from "./use-user-metabot-permissions";
diff --git a/frontend/src/metabase/metabot/hooks/useDashCardAnalysis.ts b/frontend/src/metabase/metabot/hooks/useDashCardAnalysis.ts
deleted file mode 100644
index 49bc39bfae8..00000000000
--- a/frontend/src/metabase/metabot/hooks/useDashCardAnalysis.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import { useEffect, useRef } from "react";
-import { usePrevious } from "react-use";
-
-import { useAnalyzeChartMutation } from "metabase/api";
-import {
- getChartImagePngDataUri,
- getChartSelector,
-} from "metabase/visualizations/lib/image-exports";
-import type { DashCardId } from "metabase-types/api";
-
-// Delay time to ensure visualizations have rendered after data loading
-const RENDER_DELAY_MS = 100;
-
-interface UseDashCardAnalysisOptions {
- dashcardId?: DashCardId;
- name?: string | null;
- description?: string | null;
- isLoadingComplete: boolean;
- isEnabled?: boolean;
-}
-
-export function useDashCardAnalysis({
- dashcardId,
- name,
- description,
- isLoadingComplete,
- isEnabled = true,
-}: UseDashCardAnalysisOptions) {
- const [analyzeChart, { data: analysisData, isLoading }] =
- useAnalyzeChartMutation();
- const pendingAnalysisRef = useRef(true);
- const analysisTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
- const prevDashcardId = usePrevious(dashcardId);
-
- useEffect(() => {
- if (prevDashcardId === dashcardId) {
- return;
- }
-
- if (prevDashcardId != null && prevDashcardId !== dashcardId) {
- pendingAnalysisRef.current = true;
- }
-
- if (!isEnabled || !pendingAnalysisRef.current || !isLoadingComplete) {
- return;
- }
-
- analysisTimeoutRef.current = setTimeout(async () => {
- const imageBase64 = await getChartImagePngDataUri(
- getChartSelector({ dashcardId }),
- );
-
- if (imageBase64) {
- await analyzeChart({
- imageBase64,
- name: name ?? undefined,
- description: description ?? undefined,
- timelineEvents: [],
- });
- }
-
- pendingAnalysisRef.current = false;
- analysisTimeoutRef.current = null;
- }, RENDER_DELAY_MS);
-
- return () => {
- if (analysisTimeoutRef.current) {
- clearTimeout(analysisTimeoutRef.current);
- analysisTimeoutRef.current = null;
- }
- };
- }, [
- analyzeChart,
- dashcardId,
- prevDashcardId,
- isLoadingComplete,
- name,
- description,
- isEnabled,
- ]);
-
- return {
- analysisData: analysisData?.summary,
- isLoading:
- isLoading ||
- (isEnabled && isLoadingComplete && pendingAnalysisRef.current),
- };
-}
diff --git a/frontend/src/metabase/query_builder/components/AIQuestionAnalysisSidebar/AIQuestionAnalysisSidebar.tsx b/frontend/src/metabase/query_builder/components/AIQuestionAnalysisSidebar/AIQuestionAnalysisSidebar.tsx
deleted file mode 100644
index dd140a8317c..00000000000
--- a/frontend/src/metabase/query_builder/components/AIQuestionAnalysisSidebar/AIQuestionAnalysisSidebar.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import {
- AIAnalysisSidebar,
- type AIAnalysisSidebarProps,
-} from "metabase/metabot/components/AIAnalysisSidebar";
-import { getIsLoadingComplete } from "metabase/query_builder/selectors";
-import { useSelector } from "metabase/redux";
-
-export type AIQuestionAnalysisSidebarProps = Omit<
- AIAnalysisSidebarProps,
- "isLoadingComplete"
->;
-
-export function AIQuestionAnalysisSidebar(
- props: AIQuestionAnalysisSidebarProps,
-) {
- const isLoadingComplete = useSelector(getIsLoadingComplete);
- return <AIAnalysisSidebar {...props} isLoadingComplete={isLoadingComplete} />;
-}
diff --git a/frontend/src/metabase/query_builder/components/AIQuestionAnalysisSidebar/index.ts b/frontend/src/metabase/query_builder/components/AIQuestionAnalysisSidebar/index.ts
deleted file mode 100644
index aa50f131a22..00000000000
--- a/frontend/src/metabase/query_builder/components/AIQuestionAnalysisSidebar/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { AIQuestionAnalysisSidebar } from "./AIQuestionAnalysisSidebar";
-export type { AIQuestionAnalysisSidebarProps } from "./AIQuestionAnalysisSidebar";
diff --git a/frontend/src/metabase/query_builder/components/view/View/NativeQueryRightSidebar/NativeQueryRightSidebar.tsx b/frontend/src/metabase/query_builder/components/view/View/NativeQueryRightSidebar/NativeQueryRightSidebar.tsx
index 9133d3321dc..b9a2d388543 100644
--- a/frontend/src/metabase/query_builder/components/view/View/NativeQueryRightSidebar/NativeQueryRightSidebar.tsx
+++ b/frontend/src/metabase/query_builder/components/view/View/NativeQueryRightSidebar/NativeQueryRightSidebar.tsx
@@ -1,7 +1,6 @@
import { match } from "ts-pattern";
import { setTemplateTagConfig } from "metabase/query_builder/actions";
-import { AIQuestionAnalysisSidebar } from "metabase/query_builder/components/AIQuestionAnalysisSidebar";
import { QuestionInfoSidebar } from "metabase/query_builder/components/view/sidebars/QuestionInfoSidebar";
import { QuestionSettingsSidebar } from "metabase/query_builder/components/view/sidebars/QuestionSettingsSidebar";
import { TimelineSidebar } from "metabase/query_builder/components/view/sidebars/TimelineSidebar";
@@ -48,8 +47,6 @@ interface NativeQueryRightSidebarProps {
isShowingTimelineSidebar: boolean;
isShowingQuestionInfoSidebar: boolean;
isShowingQuestionSettingsSidebar: boolean;
- isShowingAIQuestionAnalysisSidebar: boolean;
- onCloseAIQuestionAnalysisSidebar: () => void;
visibleTimelineEventIds: number[];
selectedTimelineEventIds: number[];
setDatasetQuery: (query: NativeDatasetQuery) => void;
@@ -69,8 +66,6 @@ export const NativeQueryRightSidebar = (
) => {
const {
question,
- timelineEvents,
- timelines,
toggleTemplateTagsEditor,
toggleDataReference,
toggleSnippetSidebar,
@@ -86,8 +81,6 @@ export const NativeQueryRightSidebar = (
isShowingTimelineSidebar,
isShowingQuestionInfoSidebar,
isShowingQuestionSettingsSidebar,
- isShowingAIQuestionAnalysisSidebar,
- onCloseAIQuestionAnalysisSidebar,
} = props;
const dispatch = useDispatch();
@@ -100,7 +93,6 @@ export const NativeQueryRightSidebar = (
isShowingTimelineSidebar,
isShowingQuestionInfoSidebar,
isShowingQuestionSettingsSidebar,
- isShowingAIQuestionAnalysisSidebar,
})
.with({ isShowingTemplateTagsEditor: true }, () => {
const query = question.legacyNativeQuery();
@@ -142,13 +134,5 @@ export const NativeQueryRightSidebar = (
.with({ isShowingQuestionSettingsSidebar: true }, () => (
<QuestionSettingsSidebar question={question} />
))
- .with({ isShowingAIQuestionAnalysisSidebar: true }, () => (
- <AIQuestionAnalysisSidebar
- question={question}
- visibleTimelineEvents={timelineEvents}
- timelines={timelines}
- onClose={onCloseAIQuestionAnalysisSidebar}
- />
- ))
.otherwise(() => null);
};
diff --git a/frontend/src/metabase/query_builder/components/view/View/StructuredQueryRightSidebar/StructuredQueryRightSidebar.tsx b/frontend/src/metabase/query_builder/components/view/View/StructuredQueryRightSidebar/StructuredQueryRightSidebar.tsx
index c9ae769c91d..512bff50951 100644
--- a/frontend/src/metabase/query_builder/components/view/View/StructuredQueryRightSidebar/StructuredQueryRightSidebar.tsx
+++ b/frontend/src/metabase/query_builder/components/view/View/StructuredQueryRightSidebar/StructuredQueryRightSidebar.tsx
@@ -1,7 +1,6 @@
import { match } from "ts-pattern";
import type { Dayjs } from "metabase/dayjs";
-import { AIQuestionAnalysisSidebar } from "metabase/query_builder/components/AIQuestionAnalysisSidebar";
import { QuestionInfoSidebar } from "metabase/query_builder/components/view/sidebars/QuestionInfoSidebar";
import { QuestionSettingsSidebar } from "metabase/query_builder/components/view/sidebars/QuestionSettingsSidebar";
import { SummarizeSidebar } from "metabase/query_builder/components/view/sidebars/SummarizeSidebar";
@@ -15,11 +14,9 @@ interface StructuredQueryRightSidebarProps {
hideTimelineEvents: (timelineEvents: TimelineEvent[]) => void;
isShowingQuestionInfoSidebar: boolean;
isShowingQuestionSettingsSidebar: boolean;
- isShowingAIQuestionAnalysisSidebar: boolean;
isShowingSummarySidebar: boolean;
isShowingTimelineSidebar: boolean;
onCloseSummary: () => void;
- onCloseAIQuestionAnalysisSidebar: () => void;
onCloseTimelines: () => void;
onOpenModal: (modal: QueryModalType, modalContext?: unknown) => void;
onSave: (question: Question) => Promise<void>;
@@ -27,7 +24,6 @@ interface StructuredQueryRightSidebarProps {
selectTimelineEvents: (timelineEvents: TimelineEvent[]) => void;
selectedTimelineEventIds: number[];
showTimelineEvents: (timelineEvents: TimelineEvent[]) => void;
- timelineEvents?: TimelineEvent[];
timelines: Timeline[];
updateQuestion: (question: Question, opts?: { run?: boolean }) => void;
visibleTimelineEventIds: number[];
@@ -39,11 +35,9 @@ export const StructuredQueryRightSidebar = ({
hideTimelineEvents,
isShowingQuestionInfoSidebar,
isShowingQuestionSettingsSidebar,
- isShowingAIQuestionAnalysisSidebar,
isShowingSummarySidebar,
isShowingTimelineSidebar,
onCloseSummary,
- onCloseAIQuestionAnalysisSidebar,
onCloseTimelines,
onOpenModal,
onSave,
@@ -51,7 +45,6 @@ export const StructuredQueryRightSidebar = ({
selectTimelineEvents,
selectedTimelineEventIds,
showTimelineEvents,
- timelineEvents,
timelines,
updateQuestion,
visibleTimelineEventIds,
@@ -63,21 +56,7 @@ export const StructuredQueryRightSidebar = ({
isShowingTimelineSidebar,
isShowingQuestionInfoSidebar,
isShowingQuestionSettingsSidebar,
- isShowingAIQuestionAnalysisSidebar,
})
- .with(
- {
- isShowingAIQuestionAnalysisSidebar: true,
- },
- () => (
- <AIQuestionAnalysisSidebar
- question={question}
- visibleTimelineEvents={timelineEvents}
- timelines={timelines}
- onClose={onCloseAIQuestionAnalysisSidebar}
- />
- ),
- )
.with(
{
isShowingSummarySidebar: true,
diff --git a/frontend/src/metabase/query_builder/components/view/View/View/View.tsx b/frontend/src/metabase/query_builder/components/view/View/View/View.tsx
index 9de5152c0e3..eaad6be0079 100644
--- a/frontend/src/metabase/query_builder/components/view/View/View/View.tsx
+++ b/frontend/src/metabase/query_builder/components/view/View/View/View.tsx
@@ -132,7 +132,6 @@ const ViewInner = forwardRef<HTMLDivElement, ViewInnerProps>(
rawSeries,
isShowingNewbModal,
isShowingTimelineSidebar,
- isShowingAIQuestionAnalysisSidebar,
queryBuilderMode,
closeQbNewbModal,
onDismissToast,
@@ -245,7 +244,6 @@ const ViewInner = forwardRef<HTMLDivElement, ViewInnerProps>(
const showLeftSidebar =
isShowingChartSettingsSidebar || isShowingChartTypeSidebar;
const showRightSidebar =
- isShowingAIQuestionAnalysisSidebar ||
isShowingTimelineSidebar ||
isShowingQuestionInfoSidebar ||
isShowingQuestionSettingsSidebar ||
diff --git a/frontend/src/metabase/query_builder/components/view/View/ViewRightSidebarContainer/ViewRightSidebarContainer.tsx b/frontend/src/metabase/query_builder/components/view/View/ViewRightSidebarContainer/ViewRightSidebarContainer.tsx
index d231d9e3a00..669baaa4293 100644
--- a/frontend/src/metabase/query_builder/components/view/View/ViewRightSidebarContainer/ViewRightSidebarContainer.tsx
+++ b/frontend/src/metabase/query_builder/components/view/View/ViewRightSidebarContainer/ViewRightSidebarContainer.tsx
@@ -25,10 +25,8 @@ export const ViewRightSidebarContainer = (
hideTimelineEvents,
isShowingQuestionInfoSidebar,
isShowingQuestionSettingsSidebar,
- isShowingAIQuestionAnalysisSidebar,
isShowingSummarySidebar,
isShowingTimelineSidebar,
- onCloseAIQuestionAnalysisSidebar,
onCloseSummary,
onCloseTimelines,
onOpenModal,
@@ -52,10 +50,8 @@ export const ViewRightSidebarContainer = (
hideTimelineEvents={hideTimelineEvents}
isShowingQuestionInfoSidebar={isShowingQuestionInfoSidebar}
isShowingQuestionSettingsSidebar={isShowingQuestionSettingsSidebar}
- isShowingAIQuestionAnalysisSidebar={isShowingAIQuestionAnalysisSidebar}
isShowingSummarySidebar={isShowingSummarySidebar}
isShowingTimelineSidebar={isShowingTimelineSidebar}
- onCloseAIQuestionAnalysisSidebar={onCloseAIQuestionAnalysisSidebar}
onCloseSummary={onCloseSummary}
onCloseTimelines={onCloseTimelines}
onOpenModal={onOpenModal}
diff --git a/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx b/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx
index 787a8dbe7b1..11e79a45a32 100644
--- a/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx
+++ b/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx
@@ -31,7 +31,6 @@ import {
closeQbNewbModal,
editSummary,
navigateBackToDashboard,
- onCloseAIQuestionAnalysisSidebar,
onCloseChartSettings,
onCloseChartType,
onCloseQuestionInfo,
@@ -39,7 +38,6 @@ import {
onCloseSidebars,
onCloseSummary,
onCloseTimelines,
- onOpenAIQuestionAnalysisSidebar,
onOpenChartSettings,
onOpenChartType,
onOpenQuestionInfo,
@@ -254,7 +252,6 @@ const mapDispatchToProps = {
closeQB,
closeQbNewbModal,
navigateBackToDashboard,
- onCloseAIQuestionAnalysisSidebar,
onCloseChartSettings,
onCloseChartType,
onCloseQuestionInfo,
@@ -263,7 +260,6 @@ const mapDispatchToProps = {
onCloseSummary,
onCloseTimelines,
editSummary,
- onOpenAIQuestionAnalysisSidebar,
onOpenChartSettings,
onOpenChartType,
onOpenQuestionInfo,
diff --git a/frontend/src/metabase/query_builder/defaults.ts b/frontend/src/metabase/query_builder/defaults.ts
index 6127c9638dc..e3ef2f4f14f 100644
--- a/frontend/src/metabase/query_builder/defaults.ts
+++ b/frontend/src/metabase/query_builder/defaults.ts
@@ -17,7 +17,6 @@ export const DEFAULT_UI_CONTROLS: QueryBuilderUIControls = {
isShowingQuestionInfoSidebar: false,
isShowingTimelineSidebar: false,
focusedTimelineEventIds: null,
- isShowingAIQuestionAnalysisSidebar: false,
isNativeEditorOpen: false,
initialChartSetting: {},
isShowingRawTable: false, // table/viz toggle
@@ -57,7 +56,6 @@ export const UI_CONTROLS_SIDEBAR_DEFAULTS: Partial<QueryBuilderUIControls> = {
isShowingSummarySidebar: false,
isShowingChartSettingsSidebar: false,
isShowingChartTypeSidebar: false,
- isShowingAIQuestionAnalysisSidebar: false,
isShowingTimelineSidebar: false,
focusedTimelineEventIds: null,
isShowingQuestionInfoSidebar: false,
diff --git a/frontend/src/metabase/query_builder/reducers.ts b/frontend/src/metabase/query_builder/reducers.ts
index 1db709a816a..2a3f2ee61a2 100644
--- a/frontend/src/metabase/query_builder/reducers.ts
+++ b/frontend/src/metabase/query_builder/reducers.ts
@@ -17,7 +17,6 @@ import {
CANCEL_QUESTION_CHANGES,
CLEAR_OBJECT_DETAIL_FK_REFERENCES,
CLEAR_QUERY_RESULT,
- CLOSE_AI_QUESTION_ANALYSIS_SIDEBAR,
CLOSE_CHART_SETTINGS,
CLOSE_CHART_TYPE,
CLOSE_QB,
@@ -32,7 +31,6 @@ import {
INITIALIZE_QB,
LOAD_OBJECT_DETAIL_FK_REFERENCES,
ON_CLOSE_SUMMARY,
- OPEN_AI_QUESTION_ANALYSIS_SIDEBAR,
OPEN_CHART_SETTINGS,
OPEN_CHART_TYPE,
OPEN_DATA_REFERENCE_AT_QUESTION,
@@ -258,15 +256,6 @@ export const uiControls = createReducer<QueryBuilderUIControls>(
...state,
...UI_CONTROLS_SIDEBAR_DEFAULTS,
}))
- .addCase(OPEN_AI_QUESTION_ANALYSIS_SIDEBAR, (state) => ({
- ...state,
- ...UI_CONTROLS_SIDEBAR_DEFAULTS,
- isShowingAIQuestionAnalysisSidebar: true,
- }))
- .addCase(CLOSE_AI_QUESTION_ANALYSIS_SIDEBAR, (state) => ({
- ...state,
- ...UI_CONTROLS_SIDEBAR_DEFAULTS,
- }))
.addCase<
string,
{
diff --git a/frontend/src/metabase/query_builder/selectors.ts b/frontend/src/metabase/query_builder/selectors.ts
index bb27a8b8e50..e5212f32820 100644
--- a/frontend/src/metabase/query_builder/selectors.ts
+++ b/frontend/src/metabase/query_builder/selectors.ts
@@ -107,7 +107,6 @@ const SIDEBARS = [
"isShowingChartTypeSidebar",
"isShowingChartSettingsSidebar",
"isShowingTimelineSidebar",
- "isShowingAIQuestionAnalysisSidebar",
"isShowingSummarySidebar",
diff --git a/frontend/src/metabase/redux/query-builder.ts b/frontend/src/metabase/redux/query-builder.ts
index 707b2891019..3c765ebf763 100644
--- a/frontend/src/metabase/redux/query-builder.ts
+++ b/frontend/src/metabase/redux/query-builder.ts
@@ -58,18 +58,6 @@ export const editSummary = createAction(EDIT_SUMMARY);
export const ON_CLOSE_SUMMARY = "metabase/qb/ON_CLOSE_SUMMARY";
export const onCloseSummary = createAction(ON_CLOSE_SUMMARY);
-export const OPEN_AI_QUESTION_ANALYSIS_SIDEBAR =
- "metabase/qb/OPEN_AI_QUESTION_ANALYSIS_SIDEBAR";
-export const onOpenAIQuestionAnalysisSidebar = createAction(
- OPEN_AI_QUESTION_ANALYSIS_SIDEBAR,
-);
-
-export const CLOSE_AI_QUESTION_ANALYSIS_SIDEBAR =
- "metabase/qb/CLOSE_AI_QUESTION_ANALYSIS_SIDEBAR";
-export const onCloseAIQuestionAnalysisSidebar = createAction(
- CLOSE_AI_QUESTION_ANALYSIS_SIDEBAR,
-);
-
export const OPEN_CHART_SETTINGS = "metabase/qb/OPEN_CHART_SETTINGS";
export const onOpenChartSettings = createAction(OPEN_CHART_SETTINGS);
diff --git a/frontend/src/metabase/redux/store/dashboard.ts b/frontend/src/metabase/redux/store/dashboard.ts
index 878c389757e..5b1be1915b9 100644
--- a/frontend/src/metabase/redux/store/dashboard.ts
+++ b/frontend/src/metabase/redux/store/dashboard.ts
@@ -18,8 +18,7 @@ export type DashboardSidebarName =
| "editParameter"
| "settings"
| "sharing"
- | "info"
- | "analyze";
+ | "info";
interface BaseSidebarState {
name?: DashboardSidebarName;
diff --git a/frontend/src/metabase/redux/store/mocks/qb.ts b/frontend/src/metabase/redux/store/mocks/qb.ts
index 4a7670e9855..c72ca4f0821 100644
--- a/frontend/src/metabase/redux/store/mocks/qb.ts
+++ b/frontend/src/metabase/redux/store/mocks/qb.ts
@@ -20,7 +20,6 @@ export const createMockQueryBuilderUIControlsState = (
isShowingSnippetSidebar: false,
isShowingTimelineSidebar: false,
focusedTimelineEventIds: null,
- isShowingAIQuestionAnalysisSidebar: false,
initialChartSetting: {},
isShowingRawTable: false,
isNativeEditorOpen: false,
diff --git a/frontend/src/metabase/redux/store/qb.ts b/frontend/src/metabase/redux/store/qb.ts
index 50e5234548a..1aaae1f2c68 100644
--- a/frontend/src/metabase/redux/store/qb.ts
+++ b/frontend/src/metabase/redux/store/qb.ts
@@ -48,7 +48,6 @@ export interface QueryBuilderUIControls {
isShowingTimelineSidebar: boolean;
focusedTimelineEventIds: number[] | null;
isNativeEditorOpen: boolean;
- isShowingAIQuestionAnalysisSidebar: boolean;
initialChartSetting: InitialChartSettingState;
isShowingRawTable: boolean;
queryBuilderMode: QueryBuilderMode;
diff --git a/frontend/src/metabase/visualizations/lib/image-exports.ts b/frontend/src/metabase/visualizations/lib/image-exports.ts
index a6c67598938..db6fee59b7b 100644
--- a/frontend/src/metabase/visualizations/lib/image-exports.ts
+++ b/frontend/src/metabase/visualizations/lib/image-exports.ts
@@ -223,22 +223,3 @@ export const getChartSelector = (
return `[data-card-key='${getCardKey(input.cardId)}']`;
}
};
-
-export const getChartImagePngDataUri = async (
- selector: string,
-): Promise<string | undefined> => {
- const chartRoot = document.querySelector(selector);
-
- if (!chartRoot || !(chartRoot instanceof HTMLElement)) {
- console.warn("No chart element found", selector);
- return undefined;
- }
-
- const canvas = await getDomToCanvas(chartRoot, {
- onclone: (_doc: Document, node: HTMLElement) => {
- node.classList.add(SAVING_DOM_IMAGE_CLASS);
- },
- });
-
- return canvas.toDataURL("image/png");
-};
diff --git a/frontend/test/__support__/server-mocks/ai-entity-analysis.ts b/frontend/test/__support__/server-mocks/ai-entity-analysis.ts
deleted file mode 100644
index 3c4f7896b8c..00000000000
--- a/frontend/test/__support__/server-mocks/ai-entity-analysis.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import fetchMock from "fetch-mock";
-
-import type { AIEntityAnalysisResponse } from "metabase-types/api";
-
-export function setupAnalyzeChartEndpoint(response: AIEntityAnalysisResponse) {
- const name = "ai-analyze-chart";
- fetchMock.removeRoute(name);
- fetchMock.post("path:/api/ai-entity-analysis/analyze-chart", response, {
- name,
- });
-}
diff --git a/frontend/test/__support__/server-mocks/index.ts b/frontend/test/__support__/server-mocks/index.ts
index 40b04d93c62..8d430bd69ba 100644
--- a/frontend/test/__support__/server-mocks/index.ts
+++ b/frontend/test/__support__/server-mocks/index.ts
@@ -1,7 +1,6 @@
export * from "./action";
export * from "./activity";
export * from "./advanced-config";
-export * from "./ai-entity-analysis";
export * from "./alert";
export * from "./api-key";
export * from "./audit";
diff --git a/src/metabase/api_routes/routes.clj b/src/metabase/api_routes/routes.clj
index ad717565164..6af97827aa4 100644
--- a/src/metabase/api_routes/routes.clj
+++ b/src/metabase/api_routes/routes.clj
@@ -41,7 +41,6 @@
[metabase.mcp.callback-api]
[metabase.measures.api]
[metabase.metabot.api]
- [metabase.metabot.api.entity-analysis]
[metabase.metrics.api]
[metabase.model-persistence.api]
[metabase.native-query-snippets.api]
@@ -173,7 +172,6 @@
{"/action" (+auth 'metabase.actions-rest.api)
"/activity" (+auth 'metabase.activity-feed.api)
"/agent" (metabase.agent-api.api/+agent-api-enabled metabase.agent-api.api/routes)
- "/ai-entity-analysis" metabase.metabot.api.entity-analysis/routes
"/alert" (+auth metabase.pulse.api/alert-routes)
"/analytics" (+auth 'metabase.analytics.api)
"/analytics-proxy" (+public-exceptions 'metabase.analytics.api.proxy)
diff --git a/src/metabase/metabot/api/entity_analysis.clj b/src/metabase/metabot/api/entity_analysis.clj
deleted file mode 100644
index c289dfa684d..00000000000
--- a/src/metabase/metabot/api/entity_analysis.clj
+++ /dev/null
@@ -1,40 +0,0 @@
-(ns metabase.metabot.api.entity-analysis
- "`/api/ai-entity-analysis/` routes"
- (:require
- [metabase.api.macros :as api.macros]
- [metabase.api.routes.common :refer [+auth]]
- [metabase.metabot.config :as metabot.config]
- [metabase.metabot.core :as metabot]
- [metabase.metabot.usage :as metabot.usage]))
-
-(set! *warn-on-reflection* true)
-
-;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
-;; use our API + we will need it when we make auto-TypeScript-signature generation happen
-;;
-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}
-(api.macros/defendpoint :post "/analyze-chart"
- "Analyze a chart image using an AI vision model. This function sends the image data to a separate external AI service
- for analysis."
- [_route-params
- _query-params
- {:keys [image_base64 name description timeline_events]} :- [:map
- [:image_base64 :string]
- [:name {:optional true} [:maybe :string]]
- [:description {:optional true} [:maybe :string]]
- [:timeline_events {:optional true} [:maybe [:sequential [:map
- [:name :string]
- [:description {:optional true} [:maybe :string]]
- [:timestamp :string]]]]]]]
- (metabot.config/check-metabot-enabled!)
- (metabot.usage/check-metabase-managed-free-limit!)
- (let [chart-data {:image_base64 image_base64
- :chart {:name name
- :description description}
- :timeline_events timeline_events}
- resp (metabot/analyze-chart chart-data)]
- {:summary (:analysis resp)}))
-
-(def ^{:arglists '([request respond raise])} routes
- "`/api/ai-entity-analysis` routes."
- (api.macros/ns-handler *ns* +auth))
diff --git a/src/metabase/metabot/core.clj b/src/metabase/metabot/core.clj
index 29b10d60023..c3aed989d75 100644
--- a/src/metabase/metabot/core.clj
+++ b/src/metabase/metabot/core.clj
@@ -46,14 +46,3 @@
[metabase.metabot.self
llm-call-available?
llm-call-unavailable-reason])
-
-;; TODO: Port analyze-chart to use the native LLM infrastructure
-;; instead of the deleted `metabase.metabot.client`.
-;; The frontend (`AIQuestionAnalysisSidebar`, `useDashCardAnalysis`) actively calls
-;; `POST /api/ai-entity-analysis/analyze-chart` which hits this function.
-(defn analyze-chart
- "Stub for legacy analyze-chart"
- [_chart-data]
- (throw (ex-info "Legacy Metabot AI-service function is no longer available: analyze-chart"
- {:status-code 501
- :function :analyze-chart})))
diff --git a/test/metabase/metabot/api/entity_analysis_test.clj b/test/metabase/metabot/api/entity_analysis_test.clj
deleted file mode 100644
index c6d471b5728..00000000000
--- a/test/metabase/metabot/api/entity_analysis_test.clj
+++ /dev/null
@@ -1,38 +0,0 @@
-(ns metabase.metabot.api.entity-analysis-test
- (:require
- [clojure.test :refer :all]
- [metabase.metabot.core :as metabot]
- [metabase.metabot.settings :as metabot.settings]
- [metabase.premium-features.core :as premium-features]
- [metabase.test :as mt]))
-
-(deftest analyze-chart-test
- (testing "POST /api/ai-entity-analysis/analyze-chart"
- (mt/with-dynamic-fn-redefs [metabot/analyze-chart (constantly {:analysis "This chart shows a steady increase in sales over time, with a notable peak in Q4."})]
- (let [response (mt/user-http-request :rasta :post 200 "ai-entity-analysis/analyze-chart"
- {:image_base64 "base64encodedimage"
- :name "Sales Trend"
- :description "Quarterly sales data"
- :timeline_events [{:name "Product Launch"
- :description "New product line introduced"
- :timestamp "2023-04-15"}]})]
- (is (= {:summary "This chart shows a steady increase in sales over time, with a notable peak in Q4."}
- response))))))
-
-(deftest analyze-chart-returns-free-trial-limit-error-when-managed-provider-is-locked-test
- (mt/with-temporary-setting-values [metabot.settings/llm-metabot-provider
- "metabase/anthropic/claude-sonnet-4-6"]
- (mt/with-dynamic-fn-redefs [premium-features/token-status
- (constantly {:meters {:anthropic:claude-sonnet-4-6:tokens {:meter-value 1000000
- :is-locked true}}})
- metabot/analyze-chart
- (fn [& _]
- (throw (ex-info "should not call analyze-chart" {})))]
- (let [response (mt/user-http-request :rasta :post 402 "ai-entity-analysis/analyze-chart"
- {:image_base64 "base64encodedimage"
- :name "Sales Trend"
- :description "Quarterly sales data"})]
- (is (= "You've used all of your included AI service tokens. To keep using AI features, end your trial early and start your subscription, or add your own AI provider API key."
- (if (map? response)
- (:message response)
- response)))))))