The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
BOT-1790: Redact Metabot chain-of-thought details in embedded sessions (#81872)
Andrei Simionescu36f273d52300
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsxindex fee4b26a666..a8389db4010 100644--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/MetabotChainOfThought.unit.spec.tsx@@ -41,6 +41,10 @@ const expandChain = async () => {await userEvent.click(screen.getByTestId("metabot-chain-of-thought-header"));};+afterEach(() => {+ delete window.overrideIsWithinIframe;+});+describe("MetabotChainOfThought", () => {it("shows Thinking for the empty shell while the turn is live", () => {setup(chain({ steps: [] }), true);@@ -491,4 +495,62 @@ describe("MetabotChainOfThought", () => {expect(screen.getByText("Read 3 resources")).toBeInTheDocument();expect(screen.queryByText("Reading resource")).not.toBeInTheDocument();});++ it("keeps reasoning and entity names out of embedded sessions", async () => {+ const message = chain({+ steps: [+ { kind: "reasoning", text: "Weighing the join order" },+ {+ kind: "tool",+ id: "t1",+ name: "search",+ title: "revenue",+ status: "ended",+ searchResults: {+ totalCount: 1,+ results: [+ {+ id: 9,+ type: "table",+ name: "orders",+ display_name: "Orders",+ database_id: 1,+ database_name: "Sample DB",+ database_schema: "PUBLIC",+ },+ ],+ },+ },+ {+ kind: "tool",+ id: "t2",+ name: "read_resource",+ title: "Orders",+ status: "ended",+ },+ ],+ startedAtMs: 1000,+ endedAtMs: 2000,+ });++ window.overrideIsWithinIframe = true;+ const { unmount } = setup(message, false);+ await expandChain();+ expect(screen.getByText("Searched")).toBeInTheDocument();+ expect(screen.getByText("Read resource")).toBeInTheDocument();+ expect(screen.queryByText("Thought briefly")).not.toBeInTheDocument();+ expect(screen.queryByText("1 result")).not.toBeInTheDocument();+ expect(screen.queryByText(/Orders/)).not.toBeInTheDocument();+ unmount();++ delete window.overrideIsWithinIframe;+ setup(message, false);+ await expandChain();+ await userEvent.click(screen.getByText("Thought briefly"));+ expect(screen.getByText("Weighing the join order")).toBeInTheDocument();+ expect(screen.getByText(/Searched for revenue/)).toBeInTheDocument();+ expect(screen.getByText("Read Orders")).toBeInTheDocument();+ await userEvent.click(screen.getByText("1 result"));+ expect(screen.getByText("Sample DB", { exact: false })).toBeInTheDocument();+ });});diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsxindex 4bc53330115..5b8a3e377f0 100644--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotChainOfThought/utils.tsx@@ -3,6 +3,7 @@ import { match } from "ts-pattern";import { msgid, ngettext, t } from "ttag";import type { SearchResultItem } from "metabase/api/ai-streaming/schemas";+import { isEmbedding } from "metabase/embedding/config";import { MarkdownSmartLink } from "metabase/metabot/components/AIMarkdown/components/MarkdownSmartLink";import { getToolMessage } from "metabase/metabot/constants";import type { MetabotChainStep } from "metabase/metabot/state";@@ -185,8 +186,15 @@ const toDisplayItem = (const isRenderableItem = (item: DisplayItem): boolean =>item.kind === "resourceGroup" || isRenderableStep(item.step);+const redactStep = (step: MetabotChainStep): MetabotChainStep =>+ step.kind === "reasoning"+ ? { ...step, text: "" }+ : { ...step, title: undefined, searchResults: undefined };+export const buildDisplayItems = (steps: MetabotChainStep[]): DisplayItem[] => {- const groups = groupConsecutiveResources(steps);+ const groups = groupConsecutiveResources(+ isEmbedding() ? steps.map(redactStep) : steps,+ );return groups.map((group, groupIndex) => {const stepIndex = groups.slice(0, groupIndex).flat().length;