@docsearch/react 4.7.0 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +0 -2
  2. package/dist/esm/AskAiScreenState-CRHicWbN.d.ts +106 -0
  3. package/dist/esm/DocSearch-HJsNvtZr.d.ts +295 -0
  4. package/dist/esm/DocSearchAskAiModal-B7vpLudE.d.ts +48 -0
  5. package/dist/esm/DocSearchAskAiModal-KaA6fBV4.js +954 -0
  6. package/dist/esm/DocSearchAskAiModal-KaA6fBV4.js.map +1 -0
  7. package/dist/esm/DocSearchButton-CZM_jACU.d.ts +18 -0
  8. package/dist/esm/DocSearchButton-CaxxOzQU.js +71 -0
  9. package/dist/esm/DocSearchButton-CaxxOzQU.js.map +1 -0
  10. package/dist/esm/DocSearchModal-CpvDjo1O.js +250 -0
  11. package/dist/esm/DocSearchModal-CpvDjo1O.js.map +1 -0
  12. package/dist/esm/DocSearchTheme-DvL4mf0D.d.ts +5 -0
  13. package/dist/esm/askaiModal.d.ts +2 -0
  14. package/dist/esm/askaiModal.js +3 -0
  15. package/dist/esm/button.d.ts +2 -0
  16. package/dist/esm/button.js +3 -0
  17. package/dist/esm/docsearchAi.d.ts +220 -0
  18. package/dist/esm/docsearchAi.js +34 -0
  19. package/dist/esm/docsearchAi.js.map +1 -0
  20. package/dist/esm/index-Bqqv4HmN.d.ts +233 -0
  21. package/dist/esm/index.d.ts +9 -657
  22. package/dist/esm/index.js +35 -3
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/esm/keyboard-BkSdCzTU.js +9 -0
  25. package/dist/esm/keyboard-BkSdCzTU.js.map +1 -0
  26. package/dist/esm/keyboardShortcuts-C-lx6Xt7.js +25 -0
  27. package/dist/esm/keyboardShortcuts-C-lx6Xt7.js.map +1 -0
  28. package/dist/esm/modal.d.ts +2 -0
  29. package/dist/esm/modal.js +3 -0
  30. package/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js +1240 -0
  31. package/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js.map +1 -0
  32. package/dist/esm/objectSpread2-BNmiQYyW.js +67 -0
  33. package/dist/esm/objectWithoutProperties-phqYxDS0.js +53 -0
  34. package/dist/esm/objectWithoutProperties-phqYxDS0.js.map +1 -0
  35. package/dist/esm/sidepanel.d.ts +395 -0
  36. package/dist/esm/sidepanel.js +773 -0
  37. package/dist/esm/sidepanel.js.map +1 -0
  38. package/dist/esm/useDocSearchKeyboardEvents-u23fFhR9.d.ts +43 -0
  39. package/dist/esm/useDocSearchKeyboardEvents.d.ts +2 -41
  40. package/dist/esm/useDocSearchKeyboardEvents.js +43 -1
  41. package/dist/esm/useDocSearchKeyboardEvents.js.map +1 -0
  42. package/dist/esm/useSearchClient-mIHVB6ga.js +433 -0
  43. package/dist/esm/useSearchClient-mIHVB6ga.js.map +1 -0
  44. package/dist/esm/useSuggestedQuestions-CG2H3qm4.js +1116 -0
  45. package/dist/esm/useSuggestedQuestions-CG2H3qm4.js.map +1 -0
  46. package/dist/esm/useTheme.d.ts +7 -6
  47. package/dist/esm/useTheme.js +21 -1
  48. package/dist/esm/useTheme.js.map +1 -0
  49. package/dist/esm/version.d.ts +4 -2
  50. package/dist/esm/version.js +6 -1
  51. package/dist/esm/version.js.map +1 -0
  52. package/dist/umd/index.js +175 -5
  53. package/dist/umd/index.js.map +1 -1
  54. package/package.json +31 -34
  55. package/style/askai.js +1 -0
  56. package/button.js +0 -1
  57. package/dist/esm/DocSearchButton.d.ts +0 -18
  58. package/dist/esm/DocSearchButton.js +0 -1
  59. package/dist/esm/DocSearchModal.d.ts +0 -446
  60. package/dist/esm/DocSearchModal.js +0 -3
  61. package/dist/esm/Sidepanel.d.ts +0 -371
  62. package/dist/esm/Sidepanel.js +0 -3
  63. package/dist/umd/DocSearchModal.js +0 -5
  64. package/dist/umd/DocSearchModal.js.map +0 -1
  65. package/dist/umd/DocsearchButton.js +0 -3
  66. package/dist/umd/DocsearchButton.js.map +0 -1
  67. package/dist/umd/Sidepanel.js +0 -5
  68. package/dist/umd/Sidepanel.js.map +0 -1
  69. package/dist/umd/useDocSearchKeyboardEvents.js +0 -3
  70. package/dist/umd/useDocSearchKeyboardEvents.js.map +0 -1
  71. package/dist/umd/useTheme.js +0 -3
  72. package/dist/umd/useTheme.js.map +0 -1
  73. package/dist/umd/version.js +0 -3
  74. package/dist/umd/version.js.map +0 -1
  75. package/modal.js +0 -1
  76. package/sidepanel.js +0 -1
  77. package/useDocSearchKeyboardEvents.js +0 -1
  78. package/useTheme.js +0 -1
  79. package/version.js +0 -1
@@ -0,0 +1,3 @@
1
+ import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-KaA6fBV4.js";
2
+
3
+ export { DocSearchAskAiModal };
@@ -0,0 +1,2 @@
1
+ import { n as DocSearchButton, r as DocSearchButtonProps, t as ButtonTranslations } from "./DocSearchButton-CZM_jACU.js";
2
+ export { ButtonTranslations, DocSearchButton, DocSearchButtonProps };
@@ -0,0 +1,3 @@
1
+ import { t as DocSearchButton } from "./DocSearchButton-CaxxOzQU.js";
2
+
3
+ export { DocSearchButton };
@@ -0,0 +1,220 @@
1
+ import { o as ToolCalls } from "./index-Bqqv4HmN.js";
2
+ import { a as DocSearchProps } from "./DocSearch-HJsNvtZr.js";
3
+ import { DocSearchRef, InitialAskAiMessage } from "@docsearch/core";
4
+ import React, { JSX } from "react";
5
+ import { SearchParamsObject } from "algoliasearch/lite";
6
+ //#region src/DocSearchAI.d.ts
7
+ interface AskAiSearchParameters {
8
+ facetFilters?: string[];
9
+ filters?: string;
10
+ attributesToRetrieve?: string[];
11
+ restrictSearchableAttributes?: string[];
12
+ distinct?: boolean | number | string;
13
+ }
14
+ type AgentStudioSearchParameters = Record<string, Omit<AskAiSearchParameters, 'facetFilters'>>;
15
+ interface IndexTextParam {
16
+ exposed: boolean;
17
+ default?: string;
18
+ }
19
+ interface NumberConstraint {
20
+ min?: number;
21
+ max?: number;
22
+ }
23
+ interface IndexNumberParam {
24
+ exposed: boolean;
25
+ default?: number;
26
+ constraint?: NumberConstraint;
27
+ }
28
+ interface StringArrayConstraints {
29
+ values?: string[];
30
+ }
31
+ interface IndexStringArrayParam {
32
+ exposed: boolean;
33
+ default?: string[];
34
+ constraint?: StringArrayConstraints;
35
+ merge?: boolean;
36
+ }
37
+ interface IndexFacetParam {
38
+ exposed: false;
39
+ default?: string[];
40
+ }
41
+ interface AgentStudioSearchControls {
42
+ /**
43
+ * Augmented query for the MCP search tool to use.
44
+ *
45
+ * @default undefined
46
+ */
47
+ query?: IndexTextParam;
48
+ /**
49
+ * Number of hits for the MCP to return per page.
50
+ *
51
+ * @default { exposed: false, default: 7 }
52
+ */
53
+ hits_per_page?: IndexNumberParam;
54
+ /**
55
+ * The page number the MCP should pull results from.
56
+ *
57
+ * @default { exposed: false, default: 0 }
58
+ */
59
+ page?: IndexNumberParam;
60
+ /**
61
+ * List of attributes that the MCP can retrieve from the index.
62
+ *
63
+ * @default { exposed: false, default: ['*'] }
64
+ */
65
+ attributesToRetrieve?: IndexStringArrayParam;
66
+ /**
67
+ * List of fields that the MCP will return to the Agent.
68
+ *
69
+ * @default { exposed: false, default: ["hits", "nbHits", "page", "nbPages", "hitsPerPage", "facets"] }
70
+ */
71
+ responseFields?: IndexStringArrayParam;
72
+ /**
73
+ * Defined facets the MCP will use when querying the index.
74
+ *
75
+ * @default undefined
76
+ */
77
+ facets?: IndexFacetParam;
78
+ /**
79
+ * Any other custom properties the MCP should send when querying the index.
80
+ *
81
+ * @default undefined
82
+ */
83
+ custom?: Record<string, unknown>;
84
+ }
85
+ interface AgentStudioIndices {
86
+ /** The name of the index used by the search tool. */
87
+ index: string;
88
+ /** A brief description for the search tool. */
89
+ description: string;
90
+ /**
91
+ * A description used to steer the agent on how/when to use the search tool.
92
+ *
93
+ * @default ''
94
+ */
95
+ enhancedDescription?: string;
96
+ /**
97
+ * Default search parameters for the internal (non-MCP) search tool path.
98
+ *
99
+ * @default undefined
100
+ */
101
+ searchParameters?: SearchParamsObject;
102
+ /**
103
+ * Structured search parameters for the MCP-based search tool path.
104
+ *
105
+ * Each parameter controls whether it is exposed to the LLM and it's default
106
+ * value.
107
+ *
108
+ * @default undefined
109
+ */
110
+ searchControls?: AgentStudioSearchControls;
111
+ }
112
+ interface Memory {
113
+ /**
114
+ * Determines whether or not to display the memory based tool calls.
115
+ *
116
+ * @default false
117
+ */
118
+ enabled?: boolean;
119
+ /**
120
+ * The JWT used by the agent to know which user's memory to read.
121
+ *
122
+ * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/user-authentication
123
+ */
124
+ userToken?: string;
125
+ }
126
+ interface PromptSuggestions {
127
+ /** The name of the index where the prompt suggestions are stored. */
128
+ indexName: string;
129
+ /**
130
+ * The number of prompt suggestions that are retrieved and displayed.
131
+ *
132
+ * @default 3
133
+ */
134
+ hitsPerPage?: number;
135
+ }
136
+ interface DocSearchAskAi {
137
+ /**
138
+ * The index name to use for the Ask AI feature. Your assistant will search
139
+ * for relevant documents. If not provided, the root index name will be used.
140
+ */
141
+ indexName?: string;
142
+ /**
143
+ * The API key to use for the ask AI feature. Your assistant will use this API
144
+ * key to search the index. If not provided, the API key will be used.
145
+ */
146
+ apiKey?: string;
147
+ /**
148
+ * The app ID to use for the ask AI feature. Your assistant will use this app
149
+ * ID to search the index. If not provided, the app ID will be used.
150
+ */
151
+ appId?: string;
152
+ /** The assistant ID to use for the ask AI feature. */
153
+ assistantId: string;
154
+ /**
155
+ * Enables displaying suggested questions on Ask AI's new conversation screen.
156
+ *
157
+ * @default false
158
+ */
159
+ suggestedQuestions?: boolean;
160
+ /**
161
+ * The search parameters to use for the ask AI feature. Keyed by the index
162
+ * name.
163
+ *
164
+ * @example
165
+ * {
166
+ * "INDEX_NAME": { distinct: false }
167
+ * }
168
+ */
169
+ searchParameters?: AgentStudioSearchParameters;
170
+ /** List of dynamic indices for the Agent Studio search tool to use. */
171
+ indices?: AgentStudioIndices[];
172
+ /**
173
+ * Use custom tools driven by Agent Studio.
174
+ *
175
+ * For best performance, memoize this object with `useMemo` or define it
176
+ * outside the component. Inline object literals will be recreated every
177
+ * render but will not affect correctness.
178
+ */
179
+ tools?: ToolCalls;
180
+ /**
181
+ * Configuration for the Agent Studio memory feature.
182
+ *
183
+ * @example
184
+ * { enabled: true, userToken: '{{SERVER_GENERATED_JWT_TOKEN}}' }
185
+ *
186
+ * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/memory/overview
187
+ */
188
+ memory?: Memory;
189
+ /**
190
+ * Enables and configures prompt suggestions that are displayed during keyword
191
+ * search.
192
+ *
193
+ * @example
194
+ * { indexName: 'docsearch-markdown_prompt_suggestions', hitsPerPage: 1 }
195
+ *
196
+ * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/integration#prompt-suggestions
197
+ */
198
+ promptSuggestions?: PromptSuggestions;
199
+ }
200
+ interface DocSearchAIProps extends DocSearchProps {
201
+ /**
202
+ * Configuration or assistant id to enable ask ai mode. Pass a string
203
+ * assistant id or a full config object.
204
+ */
205
+ askAi: DocSearchAskAi | string;
206
+ /**
207
+ * Intercept Ask AI requests (e.g. Submitting a prompt or selecting a
208
+ * suggested question).
209
+ *
210
+ * Return `true` to prevent the default modal Ask AI flow (no toggle, no
211
+ * sendMessage). Useful to route Ask AI into a different UI (e.g.
212
+ * `@docsearch/sidepanel-js`) without flicker.
213
+ */
214
+ interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
215
+ }
216
+ declare const DocSearchAI: React.ForwardRefExoticComponent<DocSearchAIProps & React.RefAttributes<DocSearchRef>>;
217
+ declare function DocSearchAIInner(props: DocSearchAIProps): JSX.Element;
218
+ //#endregion
219
+ export { AgentStudioIndices, AgentStudioSearchControls, AgentStudioSearchParameters, AskAiSearchParameters, DocSearchAI, DocSearchAIInner, DocSearchAIProps, DocSearchAskAi, Memory, PromptSuggestions, type ToolCalls };
220
+ //# sourceMappingURL=docsearchAi.d.ts.map
@@ -0,0 +1,34 @@
1
+ import { t as _objectSpread2 } from "./objectSpread2-BNmiQYyW.js";
2
+ import { t as DocSearchButton } from "./DocSearchButton-CaxxOzQU.js";
3
+ import { t as DocSearchAskAiModal } from "./DocSearchAskAiModal-KaA6fBV4.js";
4
+ import { DocSearch, useDocSearch } from "@docsearch/core";
5
+ import React from "react";
6
+ import { createPortal } from "react-dom";
7
+
8
+ //#region src/DocSearchAI.tsx
9
+ function DocSearchAIComponent(props, ref) {
10
+ return /* @__PURE__ */ React.createElement(DocSearch, _objectSpread2(_objectSpread2({}, props), {}, { ref }), /* @__PURE__ */ React.createElement(DocSearchAIInner, props));
11
+ }
12
+ const DocSearchAI = React.forwardRef(DocSearchAIComponent);
13
+ function DocSearchAIInner(props) {
14
+ var _props$translations, _props$translations2, _props$portalContaine;
15
+ const { searchButtonRef, keyboardShortcuts, isModalActive, isAskAiActive, initialQuery, onAskAiToggle, openModal, closeModal, isHybridModeSupported } = useDocSearch();
16
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DocSearchButton, {
17
+ keyboardShortcuts,
18
+ ref: searchButtonRef,
19
+ translations: (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
20
+ onClick: openModal
21
+ }), isModalActive && createPortal(/* @__PURE__ */ React.createElement(DocSearchAskAiModal, _objectSpread2(_objectSpread2({}, props), {}, {
22
+ initialScrollY: window.scrollY,
23
+ initialQuery,
24
+ translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,
25
+ isAskAiActive,
26
+ isHybridModeSupported,
27
+ onAskAiToggle,
28
+ onClose: closeModal
29
+ })), (_props$portalContaine = props.portalContainer) !== null && _props$portalContaine !== void 0 ? _props$portalContaine : document.body));
30
+ }
31
+
32
+ //#endregion
33
+ export { DocSearchAI, DocSearchAIInner };
34
+ //# sourceMappingURL=docsearchAi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docsearchAi.js","names":["DocSearchProvider"],"sources":["../../src/DocSearchAI.tsx"],"sourcesContent":["import { DocSearch as DocSearchProvider, useDocSearch } from '@docsearch/core';\nimport type { DocSearchRef, InitialAskAiMessage } from '@docsearch/core';\nimport type { SearchParamsObject } from 'algoliasearch/lite';\nimport React, { type JSX } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport type { DocSearchProps } from './DocSearch';\nimport { DocSearchAskAiModal } from './DocSearchAskAiModal';\nimport { DocSearchButton } from './DocSearchButton';\nimport type { ToolCalls } from './types/AskiAi';\n\nexport interface AskAiSearchParameters {\n facetFilters?: string[];\n filters?: string;\n attributesToRetrieve?: string[];\n restrictSearchableAttributes?: string[];\n distinct?: boolean | number | string;\n}\n\nexport type AgentStudioSearchParameters = Record<\n string,\n Omit<AskAiSearchParameters, 'facetFilters'>\n>;\n\ninterface IndexTextParam {\n exposed: boolean;\n default?: string;\n}\n\ninterface NumberConstraint {\n min?: number;\n max?: number;\n}\n\ninterface IndexNumberParam {\n exposed: boolean;\n default?: number;\n constraint?: NumberConstraint;\n}\n\ninterface StringArrayConstraints {\n values?: string[];\n}\n\ninterface IndexStringArrayParam {\n exposed: boolean;\n default?: string[];\n constraint?: StringArrayConstraints;\n merge?: boolean;\n}\n\ninterface IndexFacetParam {\n exposed: false;\n default?: string[];\n}\n\nexport interface AgentStudioSearchControls {\n /**\n * Augmented query for the MCP search tool to use.\n *\n * @default undefined\n */\n query?: IndexTextParam;\n /**\n * Number of hits for the MCP to return per page.\n *\n * @default { exposed: false, default: 7 }\n */\n hits_per_page?: IndexNumberParam;\n /**\n * The page number the MCP should pull results from.\n *\n * @default { exposed: false, default: 0 }\n */\n page?: IndexNumberParam;\n /**\n * List of attributes that the MCP can retrieve from the index.\n *\n * @default { exposed: false, default: ['*'] }\n */\n attributesToRetrieve?: IndexStringArrayParam;\n /**\n * List of fields that the MCP will return to the Agent.\n *\n * @default { exposed: false, default: [\"hits\", \"nbHits\", \"page\", \"nbPages\", \"hitsPerPage\", \"facets\"] }\n */\n responseFields?: IndexStringArrayParam;\n /**\n * Defined facets the MCP will use when querying the index.\n *\n * @default undefined\n */\n facets?: IndexFacetParam;\n /**\n * Any other custom properties the MCP should send when querying the index.\n *\n * @default undefined\n */\n custom?: Record<string, unknown>;\n}\n\nexport interface AgentStudioIndices {\n /** The name of the index used by the search tool. */\n index: string;\n /** A brief description for the search tool. */\n description: string;\n /**\n * A description used to steer the agent on how/when to use the search tool.\n *\n * @default ''\n */\n enhancedDescription?: string;\n /**\n * Default search parameters for the internal (non-MCP) search tool path.\n *\n * @default undefined\n */\n searchParameters?: SearchParamsObject;\n /**\n * Structured search parameters for the MCP-based search tool path.\n *\n * Each parameter controls whether it is exposed to the LLM and it's default\n * value.\n *\n * @default undefined\n */\n searchControls?: AgentStudioSearchControls;\n}\n\nexport interface Memory {\n /**\n * Determines whether or not to display the memory based tool calls.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * The JWT used by the agent to know which user's memory to read.\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/user-authentication\n */\n userToken?: string;\n}\n\nexport interface PromptSuggestions {\n /** The name of the index where the prompt suggestions are stored. */\n indexName: string;\n /**\n * The number of prompt suggestions that are retrieved and displayed.\n *\n * @default 3\n */\n hitsPerPage?: number;\n}\n\nexport interface DocSearchAskAi {\n /**\n * The index name to use for the Ask AI feature. Your assistant will search\n * for relevant documents. If not provided, the root index name will be used.\n */\n indexName?: string;\n /**\n * The API key to use for the ask AI feature. Your assistant will use this API\n * key to search the index. If not provided, the API key will be used.\n */\n apiKey?: string;\n /**\n * The app ID to use for the ask AI feature. Your assistant will use this app\n * ID to search the index. If not provided, the app ID will be used.\n */\n appId?: string;\n /** The assistant ID to use for the ask AI feature. */\n assistantId: string;\n /**\n * Enables displaying suggested questions on Ask AI's new conversation screen.\n *\n * @default false\n */\n suggestedQuestions?: boolean;\n /**\n * The search parameters to use for the ask AI feature. Keyed by the index\n * name.\n *\n * @example\n * {\n * \"INDEX_NAME\": { distinct: false }\n * }\n */\n searchParameters?: AgentStudioSearchParameters;\n /** List of dynamic indices for the Agent Studio search tool to use. */\n indices?: AgentStudioIndices[];\n /**\n * Use custom tools driven by Agent Studio.\n *\n * For best performance, memoize this object with `useMemo` or define it\n * outside the component. Inline object literals will be recreated every\n * render but will not affect correctness.\n */\n tools?: ToolCalls;\n /**\n * Configuration for the Agent Studio memory feature.\n *\n * @example\n * { enabled: true, userToken: '{{SERVER_GENERATED_JWT_TOKEN}}' }\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/memory/overview\n */\n memory?: Memory;\n /**\n * Enables and configures prompt suggestions that are displayed during keyword\n * search.\n *\n * @example\n * { indexName: 'docsearch-markdown_prompt_suggestions', hitsPerPage: 1 }\n *\n * @see https://www.algolia.com/doc/guides/algolia-ai/agent-studio/how-to/integration#prompt-suggestions\n */\n promptSuggestions?: PromptSuggestions;\n}\n\nexport interface DocSearchAIProps extends DocSearchProps {\n /**\n * Configuration or assistant id to enable ask ai mode. Pass a string\n * assistant id or a full config object.\n */\n askAi: DocSearchAskAi | string;\n /**\n * Intercept Ask AI requests (e.g. Submitting a prompt or selecting a\n * suggested question).\n *\n * Return `true` to prevent the default modal Ask AI flow (no toggle, no\n * sendMessage). Useful to route Ask AI into a different UI (e.g.\n * `@docsearch/sidepanel-js`) without flicker.\n */\n interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;\n}\n\nfunction DocSearchAIComponent(\n props: DocSearchAIProps,\n ref: React.ForwardedRef<DocSearchRef>\n): JSX.Element {\n return (\n <DocSearchProvider {...props} ref={ref}>\n <DocSearchAIInner {...props} />\n </DocSearchProvider>\n );\n}\n\nexport const DocSearchAI = React.forwardRef(DocSearchAIComponent);\n\nexport function DocSearchAIInner(props: DocSearchAIProps): JSX.Element {\n const {\n searchButtonRef,\n keyboardShortcuts,\n isModalActive,\n isAskAiActive,\n initialQuery,\n onAskAiToggle,\n openModal,\n closeModal,\n isHybridModeSupported,\n } = useDocSearch();\n\n return (\n <>\n <DocSearchButton\n keyboardShortcuts={keyboardShortcuts}\n ref={searchButtonRef}\n translations={props.translations?.button}\n onClick={openModal}\n />\n {isModalActive &&\n createPortal(\n <DocSearchAskAiModal\n {...props}\n initialScrollY={window.scrollY}\n initialQuery={initialQuery}\n translations={props?.translations?.modal}\n isAskAiActive={isAskAiActive}\n isHybridModeSupported={isHybridModeSupported}\n onAskAiToggle={onAskAiToggle}\n onClose={closeModal}\n />,\n props.portalContainer ?? document.body\n )}\n </>\n );\n}\n\nexport type { ToolCalls } from './types/AskiAi';\n"],"mappings":";;;;;;;;AA6OA,SAAS,qBACP,OACA,KACa;CACb,OACE,oCAACA,6CAAsB,cAAY,KAEhB,GADjB,oCAAC,kBAAqB,KAAQ,CACb;AAEvB;AAEA,MAAa,cAAc,MAAM,WAAW,oBAAoB;AAEhE,SAAgB,iBAAiB,OAAsC;;CACrE,MAAM,EACJ,iBACA,mBACA,eACA,eACA,cACA,eACA,WACA,YACA,0BACE,aAAa;CAEjB,OACE,0DACE,oCAAC,iBAAD;EACqB;EACnB,KAAK;EACL,qCAAc,MAAM,wFAAc;EAClC,SAAS;CACV,IACA,iBACC,aACE,oCAAC,uDACK;EACJ,gBAAgB,OAAO;EACT;EACd,4EAAc,MAAO,0FAAc;EACpB;EACQ;EACR;EACf,SAAS;EACV,6BACD,MAAM,wFAAmB,SAAS,IACpC,CACF;AAEN"}
@@ -0,0 +1,233 @@
1
+ import { AutocompleteContext, AutocompleteInsightsApi, AutocompleteState, BaseItem } from "@algolia/autocomplete-core";
2
+ import { Hit } from "algoliasearch/lite";
3
+ import { UIMessage } from "@ai-sdk/react";
4
+ import "ai";
5
+ //#region src/types/DocSearchHit.d.ts
6
+ type ContentType = 'askAI' | 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
7
+ interface DocSearchHitAttributeHighlightResult {
8
+ value: string;
9
+ matchLevel: 'full' | 'none' | 'partial';
10
+ matchedWords: string[];
11
+ fullyHighlighted?: boolean;
12
+ }
13
+ interface DocSearchHitHighlightResultHierarchy {
14
+ lvl0: DocSearchHitAttributeHighlightResult;
15
+ lvl1: DocSearchHitAttributeHighlightResult;
16
+ lvl2: DocSearchHitAttributeHighlightResult;
17
+ lvl3: DocSearchHitAttributeHighlightResult;
18
+ lvl4: DocSearchHitAttributeHighlightResult;
19
+ lvl5: DocSearchHitAttributeHighlightResult;
20
+ lvl6: DocSearchHitAttributeHighlightResult;
21
+ }
22
+ interface DocSearchHitHighlightResult {
23
+ content: DocSearchHitAttributeHighlightResult;
24
+ hierarchy: DocSearchHitHighlightResultHierarchy;
25
+ hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
26
+ }
27
+ interface DocSearchHitAttributeSnippetResult {
28
+ value: string;
29
+ matchLevel: 'full' | 'none' | 'partial';
30
+ }
31
+ interface DocSearchHitSnippetResult {
32
+ content: DocSearchHitAttributeSnippetResult;
33
+ hierarchy: DocSearchHitHighlightResultHierarchy;
34
+ hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
35
+ }
36
+ declare type DocSearchHit = {
37
+ objectID: string;
38
+ content: string | null;
39
+ query?: string;
40
+ url: string;
41
+ url_without_anchor: string;
42
+ type: ContentType;
43
+ anchor: string | null;
44
+ hierarchy: {
45
+ lvl0: string;
46
+ lvl1: string;
47
+ lvl2: string | null;
48
+ lvl3: string | null;
49
+ lvl4: string | null;
50
+ lvl5: string | null;
51
+ lvl6: string | null;
52
+ };
53
+ _highlightResult: DocSearchHitHighlightResult;
54
+ _snippetResult: DocSearchHitSnippetResult;
55
+ _rankingInfo?: {
56
+ promoted: boolean;
57
+ nbTypos: number;
58
+ firstMatchedWord: number;
59
+ proximityDistance?: number;
60
+ geoDistance: number;
61
+ geoPrecision?: number;
62
+ nbExactWords: number;
63
+ words: number;
64
+ filters: number;
65
+ userScore: number;
66
+ matchedGeoLocation?: {
67
+ lat: number;
68
+ lng: number;
69
+ distance: number;
70
+ };
71
+ };
72
+ _distinctSeqID?: number;
73
+ __autocomplete_indexName?: string;
74
+ __autocomplete_queryID?: string;
75
+ __autocomplete_algoliaCredentials?: {
76
+ appId: string;
77
+ apiKey: string;
78
+ };
79
+ __autocomplete_id?: number;
80
+ };
81
+ //#endregion
82
+ //#region src/types/DocSearchState.d.ts
83
+ interface DocSearchContext extends AutocompleteContext {
84
+ algoliaInsightsPlugin?: {
85
+ insights: AutocompleteInsightsApi;
86
+ };
87
+ }
88
+ interface DocSearchState<TItem extends BaseItem> extends AutocompleteState<TItem> {
89
+ context: DocSearchContext;
90
+ }
91
+ //#endregion
92
+ //#region src/types/Feedback.d.ts
93
+ /**
94
+ * Categories a user can select when submitting negative (thumbs down) feedback
95
+ * on an AI chat message.
96
+ */
97
+ type AskAiFeedbackReason = 'incorrect' | 'not_what_i_asked' | 'other' | 'safety_or_legal' | 'slow_or_buggy' | 'style_or_tone';
98
+ /**
99
+ * Payload sent when a user submits feedback on an AI chat message. `tags` and
100
+ * `notes` are only present for negative feedback.
101
+ */
102
+ type AskAiFeedbackPayload = {
103
+ /** 1 for a thumbs up, 0 for a thumbs down. */
104
+ thumbs: 0 | 1;
105
+ /** Optional reason categories, only collected for negative feedback. */
106
+ tags?: AskAiFeedbackReason[];
107
+ /** Optional free-text note, only collected for negative feedback. */
108
+ notes?: string;
109
+ };
110
+ /** Callback invoked when a user submits feedback on an AI chat message. */
111
+ type OnAskAiFeedback = (messageId: string, feedback: AskAiFeedbackPayload) => Promise<void>;
112
+ //#endregion
113
+ //#region src/types/AskiAi.d.ts
114
+ interface CustomTool {
115
+ input: unknown;
116
+ output: unknown;
117
+ }
118
+ interface SearchIndexTool {
119
+ input: {
120
+ query: string;
121
+ };
122
+ output: {
123
+ query?: string;
124
+ hits?: any[];
125
+ };
126
+ }
127
+ interface MCPSearchToolQuery {
128
+ query: string;
129
+ [key: string]: unknown;
130
+ }
131
+ interface MCPSearchToolInputV1 {
132
+ query: string;
133
+ index: string;
134
+ number_of_results?: number;
135
+ facet_filters?: string[];
136
+ }
137
+ interface MCPSearchToolInputV2 {
138
+ queries: MCPSearchToolQuery[];
139
+ clickAnalytics: boolean;
140
+ originalQuery: string;
141
+ }
142
+ interface AlgoliaMCPSearchTool {
143
+ input: MCPSearchToolInputV1 | MCPSearchToolInputV2;
144
+ output: {
145
+ hits?: unknown[];
146
+ nbHits?: number;
147
+ queryId?: string;
148
+ } | undefined;
149
+ }
150
+ interface MemoryTool {
151
+ input: unknown;
152
+ output: unknown;
153
+ }
154
+ type ToolDefinition = {
155
+ /**
156
+ * Use the tool's input and output to build a string output for the tool
157
+ * result.
158
+ */
159
+ render: (params: {
160
+ message: {
161
+ input: unknown;
162
+ output: unknown;
163
+ };
164
+ }) => string;
165
+ /**
166
+ * Optional callback function that is invoked when a tool call is received.
167
+ * You must call addToolOutput to provide the tool result.
168
+ */
169
+ onToolCall?: (params: {
170
+ input: unknown;
171
+ addToolOutput: (props: {
172
+ output: unknown;
173
+ }) => Promise<void>;
174
+ toolCallId: string;
175
+ toolName: string;
176
+ dynamic?: boolean;
177
+ }) => Promise<void> | void;
178
+ translations?: Partial<{
179
+ /** The text displayed before tool call output is available. */
180
+ callingToolText: string;
181
+ }>;
182
+ };
183
+ type ToolCalls = Record<string, ToolDefinition>;
184
+ type AgentStudioMemoryTools = {
185
+ algolia_ponder: MemoryTool;
186
+ algolia_memorize: MemoryTool;
187
+ algolia_memory_search: MemoryTool;
188
+ };
189
+ type SearchTools = { [K in `algolia_search_index_${string}`]: AlgoliaMCPSearchTool; } & {
190
+ algolia_search_index: AlgoliaMCPSearchTool;
191
+ searchIndex: SearchIndexTool;
192
+ };
193
+ type CustomTools = { [K in string as K extends keyof SearchTools | `algolia_search_index_${string}` ? never : K]: CustomTool; };
194
+ type Tools = AgentStudioMemoryTools & CustomTools & SearchTools;
195
+ type DataParts = {
196
+ suggestions: {
197
+ suggestions: string[];
198
+ };
199
+ };
200
+ type AIMessage = UIMessage<{
201
+ stopped?: boolean;
202
+ }, DataParts, Tools>;
203
+ //#endregion
204
+ //#region src/types/StoredDocSearchHit.d.ts
205
+ type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;
206
+ type StoredAskAiMessage = AIMessage & {
207
+ /** Optional user feedback on this assistant message. */
208
+ feedback?: 'dislike' | 'like';
209
+ /** Optional reason categories submitted with negative feedback. */
210
+ feedbackTags?: AskAiFeedbackReason[];
211
+ /** Optional free-text note submitted with negative feedback. */
212
+ feedbackNotes?: string;
213
+ };
214
+ type StoredAskAiState = StoredDocSearchHit & {
215
+ chatId?: string;
216
+ stopped?: boolean;
217
+ messages?: StoredAskAiMessage[];
218
+ };
219
+ //#endregion
220
+ //#region src/types/SuggestedQuestions.d.ts
221
+ type SuggestedQuestion = {
222
+ appId: string;
223
+ assistantId: string;
224
+ question: string;
225
+ locale?: string;
226
+ state: 'published';
227
+ source: string;
228
+ order: number;
229
+ };
230
+ type SuggestedQuestionHit = Hit<SuggestedQuestion>;
231
+ //#endregion
232
+ export { StoredDocSearchHit as a, AskAiFeedbackReason as c, DocSearchHit as d, StoredAskAiState as i, OnAskAiFeedback as l, SuggestedQuestionHit as n, ToolCalls as o, StoredAskAiMessage as r, AskAiFeedbackPayload as s, SuggestedQuestion as t, DocSearchState as u };
233
+ //# sourceMappingURL=index-Bqqv4HmN.d.ts.map