Skip to content

Commit eb13a5b

Browse files
authored
Add and enable SEARCH_OR_ASK_AI feature flag for edge environment (#1683)
* Add and enable SEARCH_OR_ASK_AI feature flag for edge environment * Run prettier * Move QueryClientProvider to top component * Attmpt to fix runtime error * Flatten * Revert "Flatten" This reverts commit b7fe316. * Revert "Attmpt to fix runtime error" This reverts commit fa09d1d. * Fix ReferenceError runtime error
1 parent cf6e824 commit eb13a5b

File tree

8 files changed

+27
-10
lines changed

8 files changed

+27
-10
lines changed

config/assembler.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ environments:
2525
enabled: false
2626
feature_flags:
2727
LAZY_LOAD_NAVIGATION: true
28+
SEARCH_OR_ASK_AI: true
2829
dev:
2930
uri: http://localhost:4000
3031
content_source: current

src/Elastic.Documentation.Configuration/Builder/FeatureFlags.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public bool DisableGitHubEditLink
3232
set => _featureFlags["disable-github-edit-link"] = value;
3333
}
3434

35+
public bool SearchOrAskAiEnabled
36+
{
37+
get => IsEnabled("search-or-ask-ai");
38+
set => _featureFlags["search-or-ask-ai"] = value;
39+
}
40+
3541
private bool IsEnabled(string key)
3642
{
3743
var envKey = $"FEATURE_{key.ToUpperInvariant().Replace('-', '_')}";

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/AskAi/useLlmGateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const useLlmGateway = (props: Props): UseLlmGatewayResponse => {
142142
)
143143

144144
const { sendMessage, abort } = useFetchEventSource<AskAiRequest>({
145-
apiEndpoint: '/_api/v1/ask-ai/stream',
145+
apiEndpoint: '/docs/_api/v1/ask-ai/stream',
146146
onMessage,
147147
onError: (error) => {
148148
setError(error)

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/Search/useSearchQuery.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useSearchTerm } from '../search.store'
22
import { useQuery } from '@tanstack/react-query'
33
import { useDebounce } from '@uidotdev/usehooks'
4-
import { z } from 'zod'
4+
import * as z from 'zod'
55

66
const SearchResultItem = z.object({
77
url: z.string(),
@@ -24,8 +24,13 @@ export const useSearchQuery = () => {
2424
return useQuery<SearchResponse>({
2525
queryKey: ['search', { searchTerm: debouncedSearchTerm }],
2626
queryFn: async () => {
27+
if (!debouncedSearchTerm || debouncedSearchTerm.length < 1) {
28+
return SearchResponse.parse({ results: [], totalResults: 0 })
29+
}
30+
2731
const response = await fetch(
28-
'/_api/v1/search?q=' + encodeURIComponent(debouncedSearchTerm)
32+
'/docs/_api/v1/search?q=' +
33+
encodeURIComponent(debouncedSearchTerm)
2934
)
3035
if (!response.ok) {
3136
throw new Error(

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAi.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { SearchOrAskAiButton } from './SearchOrAskAiButton'
22
import r2wc from '@r2wc/react-to-web-component'
3+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
34
import * as React from 'react'
45
import { StrictMode } from 'react'
56

67
const SearchOrAskAi = () => {
8+
const queryClient = new QueryClient()
79
return (
810
<StrictMode>
9-
<SearchOrAskAiButton />
11+
<QueryClientProvider client={queryClient}>
12+
<SearchOrAskAiButton />
13+
</QueryClientProvider>
1014
</StrictMode>
1115
)
1216
}

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAiModal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ import {
1010
EuiHorizontalRule,
1111
} from '@elastic/eui'
1212
import { css } from '@emotion/react'
13-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
1413
import * as React from 'react'
1514

1615
export const SearchOrAskAiModal = () => {
1716
const searchTerm = useSearchTerm()
1817
const askAiTerm = useAskAiTerm()
1918
const { setSearchTerm, submitAskAiTerm } = useSearchActions()
2019

21-
const queryClient = new QueryClient()
22-
2320
return (
24-
<QueryClientProvider client={queryClient}>
21+
<>
2522
<EuiFieldSearch
2623
fullWidth
2724
placeholder="Search the docs or ask Elastic Docs AI Assistant"
@@ -59,6 +56,6 @@ export const SearchOrAskAiModal = () => {
5956
This feature is in beta. Got feedback? We'd love to hear it!
6057
</EuiText>
6158
</div>
62-
</QueryClientProvider>
59+
</>
6360
)
6461
}

src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
}
1515
<a href="@Model.Link("/")" class="text-lg leading-[1em] hover:text-blue-elastic active:text-blue-elastic-100">Docs</a>
1616
</div>
17+
@if (Model.Features.SearchOrAskAiEnabled)
18+
{
19+
<search-or-ask-ai></search-or-ask-ai>
20+
}
1721
<ul class="flex gap-6">
1822
<li class="text-nowrap hover:text-blue-elastic active:text-blue-elastic-100">
1923
<a

src/tooling/docs-builder/Http/DocumentationWebHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private void SetUpRoutes()
135135
ServeApiFile(holder, slug, ctx));
136136

137137

138-
var apiV1 = _webApplication.MapGroup("/_api/v1");
138+
var apiV1 = _webApplication.MapGroup("/docs/_api/v1");
139139
apiV1.MapElasticDocsApiEndpoints();
140140

141141
_ = _webApplication.MapGet("{**slug}", (string slug, ReloadableGeneratorState holder, Cancel ctx) =>

0 commit comments

Comments
 (0)