Skip to content

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

Stop the inline SQL prompt from rethrowing generation errors (#84395)

Andrei Simionescu93214d24f4fe
diff --git a/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx b/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx
index 9a79754698d..b53eeeec7a1 100644
--- a/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx
@@ -159,6 +159,7 @@ export const MetabotInlineSQLPrompt = ({
flex={1}
miw={0}
fz="sm"
+ ff="var(--mb-default-font-family)"
c={
error?.type === "aborted" ? "text-secondary" : "feedback-negative"
}
diff --git a/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.unit.spec.tsx
index 366b37bc82b..5996b79f5f5 100644
--- a/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.unit.spec.tsx
@@ -16,7 +16,10 @@ import { createMockEntitiesState } from "__support__/store";
import { renderWithProviders, screen, waitFor, within } from "__support__/ui";
import type { SSEEvent } from "metabase/api/ai-streaming/sse-types";
import { MetabotProvider } from "metabase/metabot/context";
-import { mockAgentEndpoint } from "metabase/metabot/tests/utils";
+import {
+ erroredResponse,
+ mockAgentEndpoint,
+} from "metabase/metabot/tests/utils";
import { NativeQueryEditor } from "metabase/querying/components/NativeQueryEditor/NativeQueryEditor";
import { NATIVE_EDITOR_ICON_SIZE } from "metabase/querying/components/NativeQueryEditor/NativeQueryEditorActionButtons/NativeQueryEditorActionButtons";
import { checkNotNull } from "metabase/utils/types";
@@ -117,6 +120,20 @@ function setup({ isMetabotEnabled = true } = {}) {
);
}
+async function startGenerating() {
+ expect(await screen.findByText("SELECT")).toBeInTheDocument();
+ await userEvent.click(await screen.findByLabelText("Ask Metabot"));
+ const prompt = await screen.findByTestId("metabot-inline-sql-prompt");
+ await userEvent.type(within(prompt).getByRole("textbox"), "count orders");
+ await userEvent.click(
+ within(prompt).getByRole("button", { name: "Send to Metabot" }),
+ );
+ expect(await within(prompt).findByRole("status")).toHaveTextContent(
+ "Working on it...",
+ );
+ return prompt;
+}
+
describe("useInlineSQLPrompt", () => {
it("toggles the inline prompt open and closed", async () => {
setup();
@@ -161,16 +178,7 @@ describe("useInlineSQLPrompt", () => {
});
setup();
- expect(await screen.findByText("SELECT")).toBeInTheDocument();
- await userEvent.click(await screen.findByLabelText("Ask Metabot"));
- const prompt = await screen.findByTestId("metabot-inline-sql-prompt");
- await userEvent.type(within(prompt).getByRole("textbox"), "count orders");
- await userEvent.click(
- within(prompt).getByRole("button", { name: "Send to Metabot" }),
- );
- expect(await within(prompt).findByRole("status")).toHaveTextContent(
- "Working on it...",
- );
+ await startGenerating();
agent.sendResponse();
await waitFor(() => {
@@ -178,6 +186,39 @@ describe("useInlineSQLPrompt", () => {
});
});
+ it("replaces the working status with the error when generation fails", async () => {
+ const agent = mockAgentEndpoint({
+ events: erroredResponse,
+ waitForResponse: true,
+ });
+ setup();
+
+ const prompt = await startGenerating();
+
+ agent.sendResponse();
+ expect(
+ await within(prompt).findByText(
+ "Sorry, I ran into an error. Could you please try that again?",
+ ),
+ ).toBeInTheDocument();
+ expect(within(prompt).queryByRole("status")).not.toBeInTheDocument();
+ });
+
+ it("replaces the working status with the interruption notice when generation is stopped", async () => {
+ mockAgentEndpoint({ stream: new ReadableStream<Uint8Array>() });
+ setup();
+
+ const prompt = await startGenerating();
+
+ await userEvent.click(
+ within(prompt).getByRole("button", { name: "Stop generating" }),
+ );
+ expect(
+ await within(prompt).findByText("Response from Metabot was interrupted"),
+ ).toBeInTheDocument();
+ expect(within(prompt).queryByRole("status")).not.toBeInTheDocument();
+ });
+
it("does not render when metabot is not enabled", async () => {
setup({ isMetabotEnabled: false });
diff --git a/frontend/src/metabase/metabot/hooks/use-metabot-sql-suggestion.tsx b/frontend/src/metabase/metabot/hooks/use-metabot-sql-suggestion.tsx
index f3006eb9799..f82835e07e4 100644
--- a/frontend/src/metabase/metabot/hooks/use-metabot-sql-suggestion.tsx
+++ b/frontend/src/metabase/metabot/hooks/use-metabot-sql-suggestion.tsx
@@ -79,7 +79,6 @@ export function useMetabotSQLSuggestion({
};
setError(error);
- throw new Error(error.message);
} else {
onGenerated?.();
}