docs: add AI Assistant (#5249)

* added components

* added ai assistant button

* change styling

* improve AI assistant

* change to a drawer

* added command support into search

* add AiAssistant to all projects

* remove usage of Text component

* added error handling

* use recaptcha

* fix new configurations

* fix background color

* change suggested questions
This commit is contained in:
Shahed Nasser
2023-10-05 11:10:44 +03:00
committed by GitHub
parent b6bea74914
commit b3f75d8f21
45 changed files with 1864 additions and 437 deletions
+27 -3
View File
@@ -1,5 +1,10 @@
import React, { useEffect, useState } from "react"
import { SearchProvider as UiSearchProvider, checkArraySameElms } from "docs-ui"
import {
AiAssistantCommandIcon,
AiAssistantProvider,
SearchProvider as UiSearchProvider,
checkArraySameElms,
} from "docs-ui"
import { ThemeConfig } from "@medusajs/docs"
import { useThemeConfig } from "@docusaurus/theme-common"
import { useLocalPathname } from "@docusaurus/theme-common/internal"
@@ -10,7 +15,8 @@ type SearchProviderProps = {
const SearchProvider = ({ children }: SearchProviderProps) => {
const [defaultFilters, setDefaultFilters] = useState<string[]>([])
const { algoliaConfig: algolia } = useThemeConfig() as ThemeConfig
const { algoliaConfig: algolia, aiAssistant } =
useThemeConfig() as ThemeConfig
const currentPath = useLocalPathname()
useEffect(() => {
@@ -60,9 +66,27 @@ const SearchProvider = ({ children }: SearchProviderProps) => {
],
},
],
className: "z-[500]",
}}
commands={[
aiAssistant && {
name: "ai-assistant",
icon: <AiAssistantCommandIcon />,
component: (
<AiAssistantProvider
apiUrl={aiAssistant.apiUrl}
websiteId={aiAssistant.websiteId}
recaptchaSiteKey={aiAssistant.recaptchaSiteKey}
/>
),
title: "AI Assistant",
badge: {
variant: "purple",
children: "Beta",
},
},
]}
initialDefaultFilters={defaultFilters}
modalClassName="z-[500]"
>
{children}
</UiSearchProvider>