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
[Metabot] Natural language query entry point (#66737)
Sloan Sparger3d5c36960d58
diff --git a/e2e/test/scenarios/metabot/metabot-query-builder.cy.spec.ts b/e2e/test/scenarios/metabot/metabot-query-builder.cy.spec.tsnew file mode 100644index 00000000000..e6a85980ddd--- /dev/null+++ b/e2e/test/scenarios/metabot/metabot-query-builder.cy.spec.ts@@ -0,0 +1,181 @@+import { SAMPLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";++const { ORDERS_ID } = SAMPLE_DATABASE;++const { H } = cy;++const metabotPromptInput = () => cy.get(".ProseMirror[contenteditable=true]");++const allOrdersQuestion = {+ dataset_query: {+ database: SAMPLE_DB_ID,+ query: { "source-table": ORDERS_ID },+ type: "query",+ },+ display: "table",+ visualization_settings: {},+};++describe("Metabot Query Builder", () => {+ describe("OSS", { tags: "@OSS" }, () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should not be available in OSS", () => {+ cy.visit("/");++ // "AI exploration" option should not appear in new button+ H.newButton().click();+ H.popover().findByText("AI exploration").should("not.exist");++ // visiting /question/ask should redirect to an empty notebook query+ cy.visit("/question/ask");+ cy.url().should("include", "/question#");+ });+ });++ describe("EE", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("bleeding-edge");+ cy.intercept("POST", "/api/ee/metabot-v3/agent-streaming").as("agentReq");+ });++ it("should be able to successfully generate a notebook query", () => {+ // visit home page+ cy.visit("/");++ // go to new button and click "AI exploration"+ H.newButton("AI exploration").click();++ // should show page+ cy.url().should("include", "/question/ask");+ cy.findByTestId("metabot-send-message").should("be.visible");++ // should have disabled send button+ cy.findByTestId("metabot-send-message").should("be.disabled");++ // should be able to type into the input+ metabotPromptInput().type("Show me all orders");++ // should be able to send prompt+ const questionHash = H.adhocQuestionHash(allOrdersQuestion);+ H.mockMetabotResponse({+ body: mockNavigateToResponse(`/question#${questionHash}`),+ delay: 100,+ });+ cy.findByTestId("metabot-send-message").click();++ // should see loading state, send button should be disabled+ cy.findByTestId("metabot-send-message").should("be.disabled");+ cy.findByTestId("metabot-send-message").should(+ "have.attr",+ "data-loading",+ "true",+ );++ // request body should include nlq profile+ cy.wait("@metabotAgent").then(({ request }) => {+ expect(request.body.profile_id).to.eq("nlq");+ });++ // when we receive a navigate_to, we should be taken to a question+ cy.url().should("include", "/question#");+ cy.findByTestId("qb-header").should("contain", "Orders");+ });++ it("should support clicking suggested prompts", () => {+ // mock suggested prompts+ cy.intercept("GET", "/api/ee/metabot-v3/metabot/*/prompt-suggestions*", {+ prompts: [{ prompt: "Show me all orders" }],+ });++ // visit AI exploration page+ cy.visit("/question/ask");+ cy.findByTestId("metabot-send-message").should("be.visible");++ // click suggested prompt+ const questionHash = H.adhocQuestionHash(allOrdersQuestion);+ H.mockMetabotResponse({+ body: mockNavigateToResponse(`/question#${questionHash}`),+ });+ cy.get("main").findByText("Show me all orders").click();++ // should be taken to a question+ cy.wait("@metabotAgent");+ cy.url().should("include", "/question#");+ cy.findByTestId("qb-header").should("contain", "Orders");+ });++ it("should handle errors", () => {+ // visit AI exploration page+ cy.visit("/question/ask");+ cy.findByTestId("metabot-send-message").should("be.visible");++ // mock the agent request to fail+ H.mockMetabotResponse({ statusCode: 500 });++ // send a prompt+ metabotPromptInput().type("Show me all orders");+ cy.findByTestId("metabot-send-message").click();++ // should show error+ cy.get("main")+ .findByText("Something went wrong. Please try again.")+ .should("be.visible");+ });++ it("should handle getting no navigate_to", () => {+ // visit AI exploration page+ cy.visit("/question/ask");+ cy.findByTestId("metabot-send-message").should("be.visible");++ // mock a response without a navigate_to data part+ H.mockMetabotResponse({+ body: mockTextOnlyResponse("I need more information to help you."),+ });++ // send a prompt+ metabotPromptInput().type("Show me something");+ cy.findByTestId("metabot-send-message").click();+ cy.wait("@metabotAgent");++ // should be taken to /question/notebook with the sidebar open+ cy.url().should("include", "/question/notebook");+ H.assertChatVisibility("visible");+ });++ it("should cancel requests if the user leaves the page", () => {+ // visit AI exploration page+ cy.visit("/question/ask");+ cy.findByTestId("metabot-send-message").should("be.visible");++ // send a prompt with a delayed response+ H.mockMetabotResponse({+ body: mockTextOnlyResponse("This should be canceled"),+ delay: 2000,+ });+ metabotPromptInput().type("Show me something");+ cy.findByTestId("metabot-send-message").click();++ // click on the logo in the app bar to leave the page+ cy.findByTestId("main-logo-link").click();++ // check that the agent request was canceled+ cy.get("@metabotAgent").its("state").should("eq", "Errored");+ });+ });+});++// Response helpers+const mockNavigateToResponse = (path: string) =>+ `2:{"type":"navigate_to","version":1,"value":"${path}"}+d:{"finishReason":"stop","usage":{"promptTokens":100,"completionTokens":10}}`;++const mockTextOnlyResponse = (text: string) =>+ `0:"${text}"+d:{"finishReason":"stop","usage":{"promptTokens":100,"completionTokens":10}}`;diff --git a/e2e/test/scenarios/metabot/native-sql-generation.cy.spec.ts b/e2e/test/scenarios/metabot/native-sql-generation.cy.spec.tsindex 01e37298740..1893cfc9a59 100644--- a/e2e/test/scenarios/metabot/native-sql-generation.cy.spec.ts+++ b/e2e/test/scenarios/metabot/native-sql-generation.cy.spec.ts@@ -4,8 +4,11 @@ const { H } = cy;const isMac = Cypress.platform === "darwin";const metaKey = isMac ? "Meta" : "Control";-const toggleInlineSQLPrompt = () =>- H.NativeEditor.get().realPress([metaKey, ";"]);+const toggleInlineSQLPrompt = () => {+ H.NativeEditor.get().focus();+ cy.wait(250);+ H.NativeEditor.get().realPress([metaKey, "Shift", "I"]);+};const inlinePrompt = () => cy.findByTestId("metabot-inline-sql-prompt");const inlinePromptInput = () =>@@ -166,14 +169,12 @@ describe("Native SQL generation", () => {// change the selected database, should close the inputrejectButton().click();- H.NativeEditor.focus();toggleInlineSQLPrompt();inlinePrompt().should("be.visible");H.NativeEditor.selectDataSource("QA Postgres12");inlinePrompt().should("not.exist");// open again, send a prompt, req.body.history should be empty- H.NativeEditor.focus();toggleInlineSQLPrompt();inlinePromptInput().type("select something");H.mockMetabotResponse({@@ -193,7 +194,6 @@ describe("Native SQL generation", () => {cy.visit("/");H.startNewNativeQuestion();H.NativeEditor.get().should("be.visible");- H.NativeEditor.focus();toggleInlineSQLPrompt();inlinePromptInput().type("new prompt");H.mockMetabotResponse({diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsxindex fc97ef7f285..dc3c98a9904 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/MetabotInlineSQLPrompt.tsx@@ -61,7 +61,7 @@ export const MetabotInlineSQLPrompt = ({handleSubmit();}},- "$mod+;": (e) => {+ "$mod+Shift+i": (e) => {e.preventDefault();handleClose();},diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.tsxindex 7708fed6375..a3ecd543527 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotInlineSQLPrompt/useInlineSQLPrompt.tsx@@ -165,7 +165,7 @@ export function useInlineSQLPrompt(createPromptInputExtension(setPortalTarget),keymap.of([{- key: "Mod-;",+ key: `Mod-Shift-i`,run: (view) => {resetInputRef.current();view.dispatch({ effects: toggleEffect.of({ view }) });diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.css b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.cssnew file mode 100644index 00000000000..770d7bb4097--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.module.css@@ -0,0 +1,159 @@+.page {+ display: flex;+ flex-direction: column;+ height: 100%;+ width: 100%;+ background: var(--mb-color-bg-white);+ position: relative;+}++/* Empty state - centered layout */+.centeredContainer {+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ flex: 1;+ padding: 2rem;+ gap: 1.5rem;+}++.greeting {+ display: flex;+ align-items: center;+ flex-direction: column;+ gap: 0.75rem;++ @media screen and (--breakpoint-min-sm) {+ flex-direction: row;+ }+}++.greetingIcon {+ width: 2.5rem;+ height: 2.5rem;+}++.inputWrapper {+ width: 100%;+ max-width: 42rem;+}++.inputContainer {+ display: flex;+ flex-direction: column;+ padding: 0.5rem 1rem 1rem;+ border-radius: 0.75rem;+ box-shadow:+ 0 0 0 1px var(--mb-color-border),+ 0 4px 24px rgba(0, 0, 0, 0.08);+ min-height: 7rem;+ transition:+ box-shadow 150ms ease,+ background 1s ease-in-out;++ &:focus-within {+ box-shadow:+ 0 0 0 1px var(--mb-color-border),+ 0 4px 24px rgba(0, 0, 0, 0.12);+ }+}++.inputContainerLoading {+ background: var(--mb-color-bg-light);+ animation: pulse 5s ease-in-out 1s infinite;+}++.editorWrapper {+ flex: 1;+ min-width: 0;+ width: 100%;+}++.inputActions {+ display: flex;+ justify-content: space-between;+ align-items: flex-end;+}++.sendButton {+ width: 2rem;+ height: 2rem;+ padding: 0;+ min-width: unset;++ &:disabled,+ &:disabled:hover {+ background-color: var(--mb-color-brand);+ color: var(--mb-color-text-white);+ border-color: var(--mb-color-brand);+ opacity: 0.35;+ }+}++.promptSuggestionsContainer {+ display: flex;+ flex-direction: column;+ align-items: flex-start;+ gap: 0.25rem;+ width: 100%;+ min-height: 10.75rem;+}++.promptSuggestion {+ padding: 0.5rem 0.75rem;+ font-size: 0.875rem;+ color: var(--mb-color-text-secondary);+ cursor: pointer;+ border-radius: 0.5rem;+ transition:+ background 150ms ease,+ color 150ms ease,+ opacity 150ms ease;++ &:hover {+ background: var(--mb-color-bg-light);+ color: var(--mb-color-text-primary);+ }+}++.promptSuggestionShow {+ opacity: 0;+ animation: fade-in 300ms ease forwards;+}++.promptSuggestionHide {+ opacity: 1;+ animation: fade-out 200ms ease forwards;+ cursor: default;+ user-select: none;+}++@keyframes fade-in {+ from {+ opacity: 0;+ }+ to {+ opacity: 1;+ }+}++@keyframes fade-out {+ from {+ opacity: 1;+ }+ to {+ opacity: 0;+ }+}++@keyframes pulse {+ 0%,+ 100% {+ background: var(--mb-color-bg-light);+ }++ 50% {+ background: var(--mb-color-bg-medium);+ }+}diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsxnew file mode 100644index 00000000000..7bc47d1a30c--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/MetabotQueryBuilder.tsx@@ -0,0 +1,242 @@+import { isFulfilled, isRejected } from "@reduxjs/toolkit";+import cx from "classnames";+import { useEffect, useState } from "react";+import { push } from "react-router-redux";+import { isMatching } from "ts-pattern";+import { t } from "ttag";+import _ from "underscore";++import { useDispatch } from "metabase/lib/redux";+import { useRouter } from "metabase/router";+import {+ Box,+ Button,+ Icon,+ Paper,+ Stack,+ Text,+ UnstyledButton,+} from "metabase/ui";+import { useGetSuggestedMetabotPromptsQuery } from "metabase-enterprise/api";+import { Urls } from "metabase-enterprise/urls";++import { useMetabotAgent } from "../../hooks";+import { MetabotPromptInput } from "../MetabotPromptInput";++import S from "./MetabotQueryBuilder.module.css";++const defaultSuggestionModels = [+ "dataset",+ "metric",+ "card",+ "table",+ "database",+ "dashboard",+] as const;++const getTitleText = () => {+ return _.sample([+ t`What would you like to know?`,+ t`What do you want to explore?`,+ t`What are you looking to learn?`,+ ]);+};++type SubmitInputResult = Awaited<+ ReturnType<ReturnType<typeof useMetabotAgent>["submitInput"]>+>;++const responseHasNavigateTo = (action: SubmitInputResult) =>+ isFulfilled(action) &&+ action.payload.data?.processedResponse.data?.some(+ isMatching({ type: "navigate_to" }),+ );++export const MetabotQueryBuilder = () => {+ const dispatch = useDispatch();+ const {+ setVisible,+ setProfileOverride,+ resetConversation,+ metabotId,+ isDoingScience,+ prompt,+ setPrompt,+ promptInputRef,+ submitInput,+ cancelRequest,+ } = useMetabotAgent();++ const [title] = useState(getTitleText);+ const [hasError, setHasError] = useState(false);++ const suggestedPromptsReq = useGetSuggestedMetabotPromptsQuery({+ metabot_id: metabotId,+ limit: 4,+ sample: true,+ });+ const suggestedPrompts = suggestedPromptsReq.currentData?.prompts;+ const suggestedPromptCount = suggestedPrompts?.length ?? 0;++ const handleSubmitPrompt = async (prompt: string) => {+ // start new nlq convo+ resetConversation();+ setProfileOverride("nlq");+ setHasError(false);++ // work around to show prompt during loading state - this is due to+ // normally we want the prompt to be cleared in a conversation+ // but in this case we want to show it in the input while responding+ // so it looks like we're processing the prompt / suggested prompt+ const req = submitInput(prompt, { preventOpenSidebar: true });+ setPrompt(prompt);+ const action = await req;+ setPrompt("");++ if (isRejected(action)) {+ return setHasError(true);+ }++ if (!action.payload.success) {+ if (action.payload.shouldRetry) {+ setPrompt(prompt);+ }+ return setHasError(true);+ }++ // as a fallback, if we receive no new query, we'll take the user+ // to an empty notebook query and show the chat sidebar as it's+ // highly likely the chat contains a response asking for clarification+ if (!responseHasNavigateTo(action)) {+ dispatch(+ push(+ Urls.newQuestion({+ mode: "notebook",+ creationType: "custom_question",+ cardType: "question",+ }),+ ),+ );+ setVisible(true);+ }+ };++ const handleEditorSubmit = () => handleSubmitPrompt(prompt);++ const inputDisabled = prompt.trim().length === 0 || isDoingScience;++ useEffect(+ function autoCloseMetabotOnMount() {+ setVisible(false);+ },+ [setVisible],+ );++ const { router, routes } = useRouter();+ const currentRoute = routes.at(-1);+ useEffect(+ function cancelRequestOnRouteLeave() {+ return router.setRouteLeaveHook(currentRoute, (nextLocation) => {+ const isNavigatingToQuestion =+ nextLocation?.pathname.startsWith("/question");+ if (isDoingScience) {+ if (isNavigatingToQuestion) {+ // we want to open the sidebar at this point as the agent could be sending a+ // navigate_to before the response has been fully completed+ setVisible(true);+ } else {+ cancelRequest();+ resetConversation(); // clear any parital response and reset profile+ }+ }+ return true;+ });+ },+ [+ router,+ currentRoute,+ setVisible,+ cancelRequest,+ resetConversation,+ isDoingScience,+ ],+ );++ return (+ <Box className={S.page}>+ <Box className={S.centeredContainer}>+ <Box className={S.greeting}>+ <Icon name="metabot" className={S.greetingIcon} c="brand" />+ <Text fz={{ base: "xl", sm: 32 }} fw={600} c="text-dark">+ {title}+ </Text>+ </Box>++ <Stack gap="lg" className={S.inputWrapper}>+ <Paper+ className={cx(+ S.inputContainer,+ isDoingScience && S.inputContainerLoading,+ )}+ >+ <Box className={S.editorWrapper}>+ <MetabotPromptInput+ ref={promptInputRef}+ value={prompt}+ autoFocus+ disabled={isDoingScience}+ placeholder={t`Ask about your data`}+ onChange={setPrompt}+ onSubmit={handleEditorSubmit}+ onStop={cancelRequest}+ suggestionConfig={{+ suggestionModels: [...defaultSuggestionModels],+ }}+ />+ </Box>+ <Box className={S.inputActions}>+ {hasError ? (+ <Text c="error" ta="center">+ {t`Something went wrong. Please try again.`}+ </Text>+ ) : (+ <div />+ )}+ <Button+ className={S.sendButton}+ variant="filled"+ disabled={inputDisabled}+ loading={isDoingScience}+ onClick={handleEditorSubmit}+ data-testid="metabot-send-message"+ >+ <Icon name="arrow_up" />+ </Button>+ </Box>+ </Paper>++ <Box className={S.promptSuggestionsContainer}>+ {suggestedPrompts?.map(({ prompt: suggestedPrompt }, index) => (+ <UnstyledButton+ key={index}+ className={cx(S.promptSuggestion, {+ [S.promptSuggestionShow]: !isDoingScience,+ [S.promptSuggestionHide]: isDoingScience,+ })}+ style={{+ animationDelay: isDoingScience+ ? `${(suggestedPromptCount - index - 1) * 50}ms`+ : `${index * 75}ms`,+ }}+ onClick={() => handleSubmitPrompt(suggestedPrompt)}+ disabled={isDoingScience}+ >+ <Text>{suggestedPrompt}</Text>+ </UnstyledButton>+ ))}+ </Box>+ </Stack>+ </Box>+ </Box>+ );+};diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/index.ts b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/index.tsnew file mode 100644index 00000000000..9c79ee2987d--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotQueryBuilder/index.ts@@ -0,0 +1 @@+export { MetabotQueryBuilder } from "./MetabotQueryBuilder";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/NewMenuItemAIExploration.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/NewMenuItemAIExploration.tsxnew file mode 100644index 00000000000..7cf2cab9620--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/NewMenuItemAIExploration.tsx@@ -0,0 +1,30 @@+import { t } from "ttag";++import { ForwardRefLink } from "metabase/common/components/Link";+import * as Urls from "metabase/lib/urls";+import { Icon, Menu } from "metabase/ui";+import type { CollectionId } from "metabase-types/api";++export function getNewMenuItemAIExploration(+ hasDataAccess: boolean,+ collectionId?: CollectionId,+) {+ if (!hasDataAccess) {+ return undefined;+ }++ return (+ <Menu.Item+ key="nlq"+ component={ForwardRefLink}+ to={Urls.newQuestion({+ mode: "ask",+ collectionId,+ cardType: "question",+ })}+ leftSection={<Icon name="comment" />}+ >+ {t`AI exploration`}+ </Menu.Item>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-agent.ts b/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-agent.tsindex 0b28670daaf..92b083374e5 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-agent.ts+++ b/enterprise/frontend/src/metabase-enterprise/metabot/hooks/use-metabot-agent.ts@@ -22,6 +22,7 @@ import {getProfileOverride,resetConversation as resetConversationAction,retryPrompt,+ setProfileOverride as setProfileOverrideAction,setVisible as setVisibleAction,submitInput as submitInputAction,} from "../state";@@ -55,6 +56,13 @@ export const useMetabotAgent = (agentId: MetabotAgentId = "omnibot") => {[promptInputRef, setPrompt],);+ const setProfileOverride = useCallback(+ (profile: string) => {+ dispatch(setProfileOverrideAction({ agentId, profile }));+ },+ [dispatch, agentId],+ );+const submitInput = useCallback(async (prompt: string | Omit<MetabotUserChatMessage, "id" | "role">,@@ -144,6 +152,7 @@ export const useMetabotAgent = (agentId: MetabotAgentId = "omnibot") => {promptInputRef,visible,setVisible,+ setProfileOverride,resetConversation,submitInput,retryMessage,diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/index.tsxindex 09d931e8d0c..8282b57dcfb 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx@@ -16,7 +16,9 @@ import { MetabotAppBarButton } from "./components/MetabotAppBarButton";import MetabotThinkingStyles from "./components/MetabotChat/MetabotThinking.module.css";import { MetabotDataStudioButton } from "./components/MetabotDataStudioButton";import { useInlineSQLPrompt } from "./components/MetabotInlineSQLPrompt";+import { MetabotQueryBuilder } from "./components/MetabotQueryBuilder";import { getMetabotQuickLinks } from "./components/MetabotQuickLinks";+import { getNewMenuItemAIExploration } from "./components/NewMenuItemAIExploration";import { MetabotContext, MetabotProvider, defaultContext } from "./context";import { getMetabotVisible, metabotReducer } from "./state";@@ -66,6 +68,10 @@ export function initializePlugin() {PLUGIN_METABOT.MetabotAppBarButton = MetabotAppBarButton;PLUGIN_METABOT.MetabotDataStudioButton = MetabotDataStudioButton;PLUGIN_METABOT.MetabotDataStudioSidebar = MetabotDataStudioSidebar;+ PLUGIN_METABOT.getMetabotQueryBuilderRoute = () => (+ <Route path="ask" component={MetabotQueryBuilder} />+ );+ PLUGIN_METABOT.getNewMenuItemAIExploration = getNewMenuItemAIExploration;PLUGIN_METABOT.useLazyMetabotGenerateContentQuery =useLazyMetabotGenerateContentQuery;PLUGIN_METABOT.MetabotThinkingStyles = MetabotThinkingStyles;diff --git a/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsx b/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsxindex f0a74c982f1..7f2ff36cd3a 100644--- a/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsx+++ b/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsx@@ -5,6 +5,7 @@ import { t } from "ttag";import { ForwardRefLink } from "metabase/common/components/Link";import { useDispatch, useSelector } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";+import { PLUGIN_METABOT } from "metabase/plugins";import { setOpenModal } from "metabase/redux/ui";import { getSetting } from "metabase/selectors/settings";import { getUserCanWriteToCollections } from "metabase/selectors/user";@@ -43,6 +44,14 @@ const NewItemMenuView = ({const menuItems = useMemo(() => {const items = [];+ const aiExplorationItem = PLUGIN_METABOT.getNewMenuItemAIExploration(+ hasDataAccess,+ collectionId,+ );+ if (aiExplorationItem) {+ items.push(aiExplorationItem);+ }+if (hasDataAccess) {items.push(<Menu.Itemdiff --git a/frontend/src/metabase/lib/urls/questions.ts b/frontend/src/metabase/lib/urls/questions.tsindex aa2a0cedbe6..61c2f0be46f 100644--- a/frontend/src/metabase/lib/urls/questions.ts+++ b/frontend/src/metabase/lib/urls/questions.ts@@ -106,7 +106,7 @@ export function serializedQuestion(card: Card, opts = {}) {}type NewQuestionUrlBuilderParams = QuestionCreatorOpts & {- mode?: "view" | "notebook" | "query";+ mode?: "view" | "notebook" | "query" | "ask";creationType?: string;objectId?: number | string;};@@ -117,6 +117,10 @@ export function newQuestion({objectId,...options}: NewQuestionUrlBuilderParams) {+ if (mode === "ask") {+ return `/question/ask`;+ }+const question = Question.create(options);const url = ML_Urls.getUrl(question, {creationType,diff --git a/frontend/src/metabase/plugins/oss/ai.ts b/frontend/src/metabase/plugins/oss/ai.tsindex a0e2b5c7ce6..1bd1b6c0441 100644--- a/frontend/src/metabase/plugins/oss/ai.ts+++ b/frontend/src/metabase/plugins/oss/ai.ts@@ -8,6 +8,7 @@ import type { MetabotContext } from "metabase/metabot";import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";import type Question from "metabase-lib/v1/Question";import type {+ CollectionId,DashCardId,DatasetQuery,MetabotGenerateContentRequest,@@ -67,6 +68,11 @@ type PluginMetabotType = {getAdminRoutes: () => React.ReactElement;getMetabotRoutes: () => React.ReactElement | null;MetabotAdminPage: ComponentType;+ getMetabotQueryBuilderRoute: () => React.ReactElement | null;+ getNewMenuItemAIExploration: (+ hasDataAccess: boolean,+ collectionId?: CollectionId,+ ) => React.ReactElement | undefined;getMetabotVisible: (state: State, conversation_id: string) => boolean;MetabotToggleButton: ComponentType<{ className?: string }>;MetabotAppBarButton: ComponentType;@@ -136,6 +142,8 @@ const getDefaultPluginMetabot = (): PluginMetabotType => ({getAdminRoutes: () => PluginPlaceholder as unknown as React.ReactElement,getMetabotRoutes: () => null,MetabotAdminPage: () => `placeholder`,+ getMetabotQueryBuilderRoute: () => null,+ getNewMenuItemAIExploration: () => undefined,getMetabotVisible: () => false,MetabotToggleButton: PluginPlaceholder,MetabotAppBarButton: PluginPlaceholder,diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.tsxindex 188cc8e89b5..f856ea73b31 100644--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.tsx+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.tsx@@ -266,7 +266,7 @@ export const getPlaceholderText = (engine?: string | null): string => {const engineType = getEngineNativeType(engine);if (PLUGIN_METABOT.isEnabled() && engineType === "sql") {- return t`Write your SQL here, or press ${METAKEY} + ; to have SQL generated for you.`;+ return t`Write your SQL here, or press ${METAKEY} + Shift + i to have SQL generated for you.`;}switch (true) {diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.unit.spec.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.unit.spec.tsxindex b053db707f2..02808360fe2 100644--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/CodeMirrorEditor/util.unit.spec.tsx@@ -187,7 +187,7 @@ describe("getPlaceholderText", () => {it("should return metabot placeholder text for sql", () => {expect(getPlaceholderText("sql")).toBe(- "Write your SQL here, or press Ctrl + ; to have SQL generated for you.",+ "Write your SQL here, or press Ctrl + Shift + i to have SQL generated for you.",);});diff --git a/frontend/src/metabase/routes.jsx b/frontend/src/metabase/routes.jsxindex a4c19f9f845..52a7ba7caaf 100644--- a/frontend/src/metabase/routes.jsx+++ b/frontend/src/metabase/routes.jsx@@ -251,6 +251,7 @@ export const getRoutes = (store) => {})}/><IndexRoute component={QueryBuilder} />+ {PLUGIN_METABOT.getMetabotQueryBuilderRoute()}<Route path="notebook" component={QueryBuilder} /><Route path=":slug" component={QueryBuilder} /><Route path=":slug/notebook" component={QueryBuilder} />