diff --git a/www/apps/api-reference/providers/search.tsx b/www/apps/api-reference/providers/search.tsx index 6c07df10e31db..9f0cebeb577f6 100644 --- a/www/apps/api-reference/providers/search.tsx +++ b/www/apps/api-reference/providers/search.tsx @@ -4,6 +4,8 @@ import { usePageLoading, SearchProvider as UiSearchProvider, searchFiltersV2, + AiAssistantIcon, + AiAssistantProvider, } from "docs-ui" import { config } from "../config" import basePathUrl from "../utils/base-path-url" @@ -33,15 +35,14 @@ const SearchProvider = ({ children }: SearchProviderProps) => { items: [ "Install Medusa with create-medusa-app", "What is an API route?", - "What is a Module?", "What is a Workflow?", ], }, { title: "Developing with Medusa", items: [ - "How to create a Module", "How to create an API route", + "How to create a module", "How to create a data model", "How to create an admin widget", ], @@ -52,6 +53,28 @@ const SearchProvider = ({ children }: SearchProviderProps) => { ), filterOptions: searchFiltersV2, }} + commands={[ + { + name: "ai-assistant", + icon: , + component: ( + + ), + title: "AI Assistant", + badge: { + variant: "blue", + badgeType: "shaded", + children: "Beta", + }, + }, + ]} > {children} diff --git a/www/apps/book/providers/search.tsx b/www/apps/book/providers/search.tsx index 21645c25d8fbc..24ce8468adff2 100644 --- a/www/apps/book/providers/search.tsx +++ b/www/apps/book/providers/search.tsx @@ -1,6 +1,11 @@ "use client" -import { SearchProvider as UiSearchProvider, searchFiltersV2 } from "docs-ui" +import { + AiAssistantIcon, + AiAssistantProvider, + SearchProvider as UiSearchProvider, + searchFiltersV2, +} from "docs-ui" import { config } from "../config" type SearchProviderProps = { @@ -47,6 +52,28 @@ const SearchProvider = ({ children }: SearchProviderProps) => { ), filterOptions: searchFiltersV2, }} + commands={[ + { + name: "ai-assistant", + icon: , + component: ( + + ), + title: "AI Assistant", + badge: { + variant: "blue", + badgeType: "shaded", + children: "Beta", + }, + }, + ]} initialDefaultFilters={["book"]} > {children} diff --git a/www/apps/resources/providers/search.tsx b/www/apps/resources/providers/search.tsx index 44846d5677ae9..78fb9f2972081 100644 --- a/www/apps/resources/providers/search.tsx +++ b/www/apps/resources/providers/search.tsx @@ -1,6 +1,11 @@ "use client" -import { SearchProvider as UiSearchProvider, searchFiltersV2 } from "docs-ui" +import { + AiAssistantIcon, + AiAssistantProvider, + SearchProvider as UiSearchProvider, + searchFiltersV2, +} from "docs-ui" import { config } from "../config" type SearchProviderProps = { @@ -28,15 +33,36 @@ const SearchProvider = ({ children }: SearchProviderProps) => { items: [ "Medusa Configurations", "Commerce Modules", - "Medusa JS Reference", - "Medusa React Reference", - "Workflows API Reference", + "Medusa Workflows Reference", + "Storefront Development", ], }, ], checkInternalPattern: new RegExp(`^${config.baseUrl}/v2/resources/.*`), filterOptions: searchFiltersV2, }} + commands={[ + { + name: "ai-assistant", + icon: , + component: ( + + ), + title: "AI Assistant", + badge: { + variant: "blue", + badgeType: "shaded", + children: "Beta", + }, + }, + ]} initialDefaultFilters={["resources"]} > {children} diff --git a/www/apps/ui/src/providers/search.tsx b/www/apps/ui/src/providers/search.tsx index dfc4ed633256c..f6c574ab688fc 100644 --- a/www/apps/ui/src/providers/search.tsx +++ b/www/apps/ui/src/providers/search.tsx @@ -49,6 +49,7 @@ const SearchProvider = ({ children }: SearchProviderProps) => { process.env.NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY || "temp" } + version="v1" /> ), title: "AI Assistant", diff --git a/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/Actions/index.tsx b/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/Actions/index.tsx index 5840f301d413f..23364d5aacd37 100644 --- a/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/Actions/index.tsx +++ b/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/Actions/index.tsx @@ -1,13 +1,8 @@ import React, { useState } from "react" import { ThreadType } from "../.." import clsx from "clsx" -import { - Button, - type ButtonProps, - ThumbDownIcon, - ThumbUpIcon, -} from "@/components" -import { Check, SquareTwoStack } from "@medusajs/icons" +import { Button, type ButtonProps } from "@/components" +import { Check, SquareTwoStackMini, ThumbDown, ThumbUp } from "@medusajs/icons" import { useCopy } from "@/hooks" import { AiAssistantFeedbackType, useAiAssistant } from "@/providers" @@ -43,21 +38,17 @@ export const AiAssistantThreadItemActions = ({ return (
- {isCopied ? : } + {isCopied ? : } {(feedback === null || feedback === "upvote") && ( handleFeedback("upvote", item.question_id)} className={clsx(feedback === "upvote" && "!text-medusa-fg-subtle")} > - + )} {(feedback === null || feedback === "downvote") && ( @@ -65,7 +56,7 @@ export const AiAssistantThreadItemActions = ({ onClick={async () => handleFeedback("downvote", item.question_id)} className={clsx(feedback === "downvote" && "!text-medusa-fg-subtle")} > - + )}
@@ -79,7 +70,7 @@ const ActionButton = ({ children, className, ...props }: ButtonProps) => { className={clsx( "text-medusa-fg-muted hover:text-medusa-fg-subtle", "hover:bg-medusa-bg-subtle-hover", - "p-docs_0.125 rounded-docs_sm", + "!p-[4.5px] rounded-docs_sm", className )} {...props} diff --git a/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/index.tsx b/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/index.tsx index e40663bac76f7..44e4bcb5eb601 100644 --- a/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/index.tsx +++ b/www/packages/docs-ui/src/components/AiAssistant/ThreadItem/index.tsx @@ -1,8 +1,7 @@ import clsx from "clsx" import React from "react" import { ThreadType } from ".." -import { DotsLoading, MarkdownContent, QuestionMarkIcon } from "@/components" -import { ExclamationCircle, Sparkles } from "@medusajs/icons" +import { AiAssistantIcon, DotsLoading, MarkdownContent } from "@/components" import { AiAssistantThreadItemActions } from "./Actions" export type AiAssistantThreadItemProps = { @@ -13,39 +12,37 @@ export const AiAssistantThreadItem = ({ item }: AiAssistantThreadItemProps) => { return (
- } +
- {item.type === "question" && } - {item.type === "answer" && } - {item.type === "error" && } - -
{item.type === "question" && <>{item.content}} {item.type === "answer" && ( - <> +
{!item.question_id && item.content.length === 0 && } - {item.content} - + + {item.content} + + {item.question_id && } +
)} {item.type === "error" && ( {item.content} )}
- {item.type === "answer" && item.question_id && ( - - )}
) } diff --git a/www/packages/docs-ui/src/components/AiAssistant/index.tsx b/www/packages/docs-ui/src/components/AiAssistant/index.tsx index 0d372b50f41e8..2d966bc792729 100644 --- a/www/packages/docs-ui/src/components/AiAssistant/index.tsx +++ b/www/packages/docs-ui/src/components/AiAssistant/index.tsx @@ -11,10 +11,9 @@ import { SearchHitGroupName, Tooltip, Link, - AiAssistantIcon, } from "@/components" import { useAiAssistant, useSearch } from "@/providers" -import { ArrowUturnLeft, XMarkMini } from "@medusajs/icons" +import { ArrowUturnLeft } from "@medusajs/icons" import clsx from "clsx" import { useSearchNavigation } from "@/hooks" import { AiAssistantThreadItem } from "./ThreadItem" @@ -77,26 +76,50 @@ export const AiAssistant = () => { const [answer, setAnswer] = useState("") const [identifiers, setIdentifiers] = useState(null) const [loading, setLoading] = useState(false) - const { getAnswer } = useAiAssistant() + const { getAnswer, version } = useAiAssistant() const { setCommand } = useSearch() const inputRef = useRef(null) const contentRef = useRef(null) - const suggestions: SearchSuggestionType[] = [ - { - title: "FAQ", - items: [ - "What is Medusa?", - "How can I create an ecommerce store with Medusa?", - "How can I build a marketplace with Medusa?", - "How can I build subscription-based purchases with Medusa?", - "How can I build digital products with Medusa?", - "What can I build with Medusa?", - "What is Medusa Admin?", - "How do I configure the database in Medusa?", - ], - }, - ] + const suggestions: SearchSuggestionType[] = useMemo(() => { + return version === "v2" + ? [ + { + title: "FAQ", + items: [ + "What is Medusa?", + "How can I create a module?", + "How can I create a data model?", + "How do I create a workflow?", + "How can I extend a data model in the Product Module?", + ], + }, + { + title: "Recipes", + items: [ + "How do I build a marketplace with Medusa?", + "How do I build digital products with Medusa?", + "How do I build subscription-based purchases with Medusa?", + "What other recipes are available in the Medusa documentation?", + ], + }, + ] + : [ + { + title: "FAQ", + items: [ + "What is Medusa?", + "How can I create an ecommerce store with Medusa?", + "How can I build a marketplace with Medusa?", + "How can I build subscription-based purchases with Medusa?", + "How can I build digital products with Medusa?", + "What can I build with Medusa?", + "What is Medusa Admin?", + "How do I configure the database in Medusa?", + ], + }, + ] + }, [version]) const handleSubmit = (selectedQuestion?: string) => { if (!selectedQuestion?.length && !question.length) { @@ -292,6 +315,22 @@ export const AiAssistant = () => { return (
+
+ + This site is protected by reCAPTCHA and the{" "} + + Google Privacy Policy + {" "} + and ToS{" "} + apply + + } + > + AI Assistant + +
{ @@ -311,7 +350,7 @@ export const AiAssistant = () => { onChange={(e) => setQuestion(e.target.value)} className={clsx( "bg-transparent border-0 focus:outline-none hover:!bg-transparent", - "shadow-none flex-1 text-medusa-fg-base", + "!shadow-none flex-1 text-medusa-fg-base", "disabled:!bg-transparent disabled:cursor-not-allowed" )} placeholder="Ask me a question about Medusa..." @@ -319,23 +358,22 @@ export const AiAssistant = () => { passedRef={inputRef} disabled={loading} /> - + Clear +
-
+
{!thread.length && (
@@ -372,35 +410,12 @@ export const AiAssistant = () => {