@docsearch/js 5.0.0-beta.1 → 5.0.0-beta.2

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.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @docsearch/js 5.0.0-beta.1 (UNRELEASED cc75f9a) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/js 5.0.0-beta.2 (UNRELEASED c7e1a88) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp$1 = Object.defineProperty;
@@ -1188,7 +1188,7 @@ function DocSearchButtonKey({ reactsToKey, children }) {
1188
1188
 
1189
1189
  //#endregion
1190
1190
  //#region ../docsearch-react/dist/esm/version.js
1191
- const version$2 = "5.0.0-beta.0";
1191
+ const version$2 = "5.0.0-beta.2";
1192
1192
 
1193
1193
  //#endregion
1194
1194
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/OverloadYield.js
@@ -12295,7 +12295,7 @@ const BOUNDARY_OFFSET = 2;
12295
12295
  *
12296
12296
  * Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
12297
12297
  */
12298
- const MenuTrigger$2 = fastComponentRef(function MenuTrigger(componentProps, forwardedRef) {
12298
+ const MenuTrigger$1 = fastComponentRef(function MenuTrigger(componentProps, forwardedRef) {
12299
12299
  var _handle$store;
12300
12300
  const { render, className, style, disabled: disabledProp = false, nativeButton = true, id: idProp, openOnHover: openOnHoverProp, delay = 100, closeDelay = 0, handle, payload } = componentProps, elementProps = _objectWithoutProperties$5(componentProps, _excluded$23);
12301
12301
  const rootContext = useMenuRootContext(true);
@@ -12496,7 +12496,7 @@ function useMenuParent() {
12496
12496
  }
12497
12497
 
12498
12498
  //#endregion
12499
- //#region ../docsearch-react/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js
12499
+ //#region ../docsearch-react/dist/esm/normalizeDocSearchIndexes-D8P3VEXa.js
12500
12500
  init_compat();
12501
12501
  function capitalize(text) {
12502
12502
  return `${text.charAt(0).toLocaleUpperCase()}${text.substring(1)}`;
@@ -12557,6 +12557,10 @@ function identity(x) {
12557
12557
  function isModifierEvent(event) {
12558
12558
  return event.button === 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
12559
12559
  }
12560
+ function isQueryEmpty(query) {
12561
+ if (!query || query.trim().length === 0) return true;
12562
+ return false;
12563
+ }
12560
12564
  function noop$2(..._args) {}
12561
12565
  const regexHighlightTags = /(<mark>|<\/mark>)/g;
12562
12566
  const regexHasHighlightTags = RegExp(regexHighlightTags.source);
@@ -12672,12 +12676,28 @@ function getFacetLabel(facet) {
12672
12676
  if (facet.label) return facet.label;
12673
12677
  return facet.key.replace(/[._-]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
12674
12678
  }
12675
- const _excluded$6$12 = ["className", "type"];
12679
+ function deriveDefaultSelectedFacetsFromIndex(indices) {
12680
+ const defaultFacets = {};
12681
+ for (const index of indices) {
12682
+ var _index$searchParamete;
12683
+ const facetFilters = (_index$searchParamete = index.searchParameters) === null || _index$searchParamete === void 0 ? void 0 : _index$searchParamete.facetFilters;
12684
+ for (const facetFilter of Array.isArray(facetFilters) ? facetFilters : [facetFilters]) {
12685
+ if (typeof facetFilter !== "string") continue;
12686
+ const separatorIndex = facetFilter.indexOf(":");
12687
+ if (separatorIndex <= 0) continue;
12688
+ const key = facetFilter.slice(0, separatorIndex);
12689
+ const value = facetFilter.slice(separatorIndex + 1);
12690
+ if (key && value) defaultFacets[key] = value;
12691
+ }
12692
+ }
12693
+ return defaultFacets;
12694
+ }
12695
+ const _excluded$6$11 = ["className", "type"];
12676
12696
  function Chip({ children }) {
12677
12697
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Chip" }, children);
12678
12698
  }
12679
12699
  function ChipDismiss(_ref) {
12680
- let { className, type = "button" } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$6$12);
12700
+ let { className, type = "button" } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$6$11);
12681
12701
  const cn = `DocSearch-Chip-Dismiss${className ? ` ${className}` : ""}`;
12682
12702
  return /* @__PURE__ */ En.createElement("button", _objectSpread2$2({
12683
12703
  type,
@@ -12701,12 +12721,14 @@ function Menu$1(_ref) {
12701
12721
  let props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
12702
12722
  return /* @__PURE__ */ En.createElement(MenuRoot, props);
12703
12723
  }
12704
- function MenuTrigger$1(_ref2) {
12724
+ Menu$1.Trigger = En.forwardRef((_ref2, ref) => {
12705
12725
  let { className } = _ref2, props = _objectWithoutProperties$6(_ref2, _excluded$5$13);
12706
12726
  const cn = `DocSearch-Menu-Trigger${className ? ` ${className}` : ""}`;
12707
- return /* @__PURE__ */ En.createElement(MenuTrigger$2, _objectSpread2$2({ className: cn }, props));
12708
- }
12709
- Menu$1.Trigger = MenuTrigger$1;
12727
+ return /* @__PURE__ */ En.createElement(MenuTrigger$1, _objectSpread2$2({
12728
+ className: cn,
12729
+ ref
12730
+ }, props));
12731
+ });
12710
12732
  function MenuPopup(_ref3) {
12711
12733
  let { align = "start", alignOffset = 0, side = "bottom", sideOffset = 4, collisionBoundary = "clipping-ancestors", container } = _ref3, props = _objectWithoutProperties$6(_ref3, _excluded2$5);
12712
12734
  return /* @__PURE__ */ En.createElement(MenuPortal, { container }, /* @__PURE__ */ En.createElement(MenuPositioner, {
@@ -12774,9 +12796,10 @@ const SelectedFacetChip = En.memo(function SelectedFacetChip({ facetKey, facetLa
12774
12796
  });
12775
12797
  const FacetBar = En.memo(function FacetBar({ facets, selections, onSelectionChange, clearSelections, translations = {} }) {
12776
12798
  const { defaultValueLabel = "All", facetMenuTriggerAriaLabel = "selected", clearAllLabel = "Clear all", facetsAriaLabel = "Search filters", selectedFacetsAriaLabel = "Selected search filters", clearFacetAriaLabel = "Clear filter:" } = translations;
12799
+ const visibleFacetKeys = En.useMemo(() => new Set(facets.map((f) => f.key)), [facets]);
12777
12800
  const selectionsToDisplay = En.useMemo(() => {
12778
- return Object.entries(selections).filter(([_, value]) => Boolean(value));
12779
- }, [selections]);
12801
+ return Object.entries(selections).filter(([key, value]) => Boolean(value) && visibleFacetKeys.has(key));
12802
+ }, [selections, visibleFacetKeys]);
12780
12803
  const triggerRefs = En.useRef(/* @__PURE__ */ new Map());
12781
12804
  const registerTrigger = En.useCallback((facetKey, el) => {
12782
12805
  if (el) triggerRefs.current.set(facetKey, el);
@@ -12837,7 +12860,7 @@ const FacetBar = En.memo(function FacetBar({ facets, selections, onSelectionChan
12837
12860
  onClick: handleClearAll
12838
12861
  }, clearAllLabel)));
12839
12862
  });
12840
- const _excluded$4$18 = [
12863
+ const _excluded$4$19 = [
12841
12864
  "actionsBeforeClose",
12842
12865
  "autoFocus",
12843
12866
  "clearButtonAriaLabel",
@@ -12856,7 +12879,7 @@ const _excluded$4$18 = [
12856
12879
  "state"
12857
12880
  ];
12858
12881
  function SearchBoxForm(_ref) {
12859
- let { actionsBeforeClose, autoFocus, clearButtonAriaLabel, clearButtonTitle, closeButtonAriaLabel, closeButtonText, hideInput, inputOverlay, inputProps, inputRef, isFromSelection, leadingElement, onClose, placeholder, searchInputLabel, state } = _ref, autocomplete = _objectWithoutProperties$6(_ref, _excluded$4$18);
12882
+ let { actionsBeforeClose, autoFocus, clearButtonAriaLabel, clearButtonTitle, closeButtonAriaLabel, closeButtonText, hideInput, inputOverlay, inputProps, inputRef, isFromSelection, leadingElement, onClose, placeholder, searchInputLabel, state } = _ref, autocomplete = _objectWithoutProperties$6(_ref, _excluded$4$19);
12860
12883
  const { onReset } = autocomplete.getFormProps({ inputElement: inputRef.current });
12861
12884
  En.useEffect(() => {
12862
12885
  if (autoFocus && inputRef.current) inputRef.current.focus();
@@ -12949,21 +12972,15 @@ function useFacetValues({ facets, indexes, searchClient }) {
12949
12972
  En.useEffect(() => {
12950
12973
  let isMounted = true;
12951
12974
  const facetKeys = stableFacetKeys ? stableFacetKeys.split(",") : [];
12952
- if (facetKeys.length === 0 || indexes.length === 0) {
12953
- setFacetValues({});
12954
- return () => {
12955
- isMounted = false;
12956
- };
12957
- }
12958
- searchClient.search({ requests: indexes.map((index) => {
12959
- var _index$searchParamete2;
12960
- return _objectSpread2$2(_objectSpread2$2({}, (_index$searchParamete2 = index.searchParameters) !== null && _index$searchParamete2 !== void 0 ? _index$searchParamete2 : {}), {}, {
12961
- indexName: index.name,
12962
- query: "",
12963
- hitsPerPage: 0,
12964
- facets: facetKeys
12965
- });
12966
- }) }).then(({ results }) => {
12975
+ if (facetKeys.length === 0 || indexes.length === 0) return () => {
12976
+ isMounted = false;
12977
+ };
12978
+ searchClient.search({ requests: indexes.map((index) => ({
12979
+ indexName: index.name,
12980
+ query: "",
12981
+ hitsPerPage: 0,
12982
+ facets: facetKeys
12983
+ })) }).then(({ results }) => {
12967
12984
  if (!isMounted) return;
12968
12985
  const valuesByFacet = facetKeys.reduce((acc, facet) => {
12969
12986
  acc[facet] = [];
@@ -12992,19 +13009,23 @@ function useFacetValues({ facets, indexes, searchClient }) {
12992
13009
  }
12993
13010
  function useDocSearchFacets({ facets, indexes, searchClient, onSelectionsChange }) {
12994
13011
  const normalizedFacets = En.useMemo(() => normalizeFacets(facets), [facets]);
13012
+ const normalizedFacetsRef = En.useRef(normalizedFacets);
12995
13013
  const facetValues = useFacetValues({
12996
13014
  facets: normalizedFacets,
12997
13015
  indexes,
12998
13016
  searchClient
12999
13017
  });
13000
- const [facetSelections, setFacetSelections] = En.useState({});
13018
+ const [facetSelections, setFacetSelections] = En.useState(() => deriveDefaultSelectedFacetsFromIndex(indexes));
13001
13019
  const facetSelectionsRef = En.useRef(facetSelections);
13002
13020
  const onSelectionsChangeRef = En.useRef(onSelectionsChange);
13003
- onSelectionsChangeRef.current = onSelectionsChange;
13004
13021
  const visibleFacets = En.useMemo(() => normalizedFacets.map((facet) => {
13005
13022
  var _facetValues$facet$ke;
13006
13023
  return _objectSpread2$2(_objectSpread2$2({}, facet), {}, { values: (_facetValues$facet$ke = facetValues[facet.key]) !== null && _facetValues$facet$ke !== void 0 ? _facetValues$facet$ke : [] });
13007
13024
  }).filter((facet) => facet.values.length > 0), [facetValues, normalizedFacets]);
13025
+ En.useLayoutEffect(() => {
13026
+ normalizedFacetsRef.current = normalizedFacets;
13027
+ onSelectionsChangeRef.current = onSelectionsChange;
13028
+ });
13008
13029
  const applySelections = En.useCallback((next) => {
13009
13030
  var _onSelectionsChangeRe;
13010
13031
  facetSelectionsRef.current = next;
@@ -13018,13 +13039,14 @@ function useDocSearchFacets({ facets, indexes, searchClient, onSelectionsChange
13018
13039
  handleFacetSelectionChange: En.useCallback((facet, value) => {
13019
13040
  if (facetSelectionsRef.current[facet] === value) return;
13020
13041
  const next = _objectSpread2$2({}, facetSelectionsRef.current);
13021
- if (value === "") delete next[facet];
13022
- else next[facet] = value;
13042
+ next[facet] = value;
13023
13043
  applySelections(next);
13024
13044
  }, [applySelections]),
13025
13045
  clearFacetSelections: En.useCallback(() => {
13026
13046
  if (Object.keys(facetSelectionsRef.current).length === 0) return;
13027
- applySelections({});
13047
+ const next = {};
13048
+ for (const facet of normalizedFacetsRef.current) if (facetSelectionsRef.current[facet.key]) next[facet.key] = "";
13049
+ applySelections(next);
13028
13050
  }, [applySelections])
13029
13051
  };
13030
13052
  }
@@ -13233,7 +13255,7 @@ function useRelativeFormattedDate(start, end = Date.now()) {
13233
13255
  }, [diff]);
13234
13256
  return start ? formattedDate : null;
13235
13257
  }
13236
- const _excluded$3$19 = [
13258
+ const _excluded$3$20 = [
13237
13259
  "hit",
13238
13260
  "attribute",
13239
13261
  "tagName"
@@ -13246,7 +13268,7 @@ function getPropertyByPath(object, path) {
13246
13268
  }
13247
13269
  function Snippet(_ref) {
13248
13270
  let { hit, attribute, tagName = "span" } = _ref;
13249
- return _$2(tagName, _objectSpread2$2(_objectSpread2$2({}, _objectWithoutProperties$6(_ref, _excluded$3$19)), {}, { dangerouslySetInnerHTML: { __html: getPropertyByPath(hit, `_snippetResult.${attribute}.value`) || getPropertyByPath(hit, attribute) } }));
13271
+ return _$2(tagName, _objectSpread2$2(_objectSpread2$2({}, _objectWithoutProperties$6(_ref, _excluded$3$20)), {}, { dangerouslySetInnerHTML: { __html: getPropertyByPath(hit, `_snippetResult.${attribute}.value`) || getPropertyByPath(hit, attribute) } }));
13250
13272
  }
13251
13273
  function Results(props) {
13252
13274
  var _props$sourceIcon;
@@ -13331,9 +13353,9 @@ function AskAiButton({ item, getItemProps, onItemClick, collection }) {
13331
13353
  }
13332
13354
  })), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit--AskAI" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-AskAIButton DocSearch-Hit-Container" }, /* @__PURE__ */ En.createElement("div", { className: " DocSearch-Hit-AskAIButton-icon DocSearch-Hit-icon" }, /* @__PURE__ */ En.createElement(SparklesIcon, null)), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-AskAIButton-title" }, /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Hit-AskAIButton-title-query" }, item.query)))));
13333
13355
  }
13334
- const _excluded$2$21 = ["translations"];
13356
+ const _excluded$2$22 = ["translations"];
13335
13357
  function StoredSearchesSections(_ref) {
13336
- let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$2$21);
13358
+ let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$2$22);
13337
13359
  const { recentSearchesTitle = "Recently viewed docs", saveRecentSearchButtonTitle = "Pin this search", removeRecentSearchButtonTitle = "Remove this search from history", favoriteSearchesTitle = "Pinned", removeFavoriteSearchButtonTitle = "Remove this saved search" } = translations;
13338
13360
  const favoriteSearches = getCollection(props.state, "favoriteSearches");
13339
13361
  const recentSearchesCollection = getCollection(props.state, "recentSearches");
@@ -13386,9 +13408,9 @@ function ErrorScreen({ translations = {} }) {
13386
13408
  const { titleText = "Unable to fetch results", helpText = "You might want to check your network connection." } = translations;
13387
13409
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-ErrorScreen" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Screen-Icon" }, /* @__PURE__ */ En.createElement(ErrorIcon, null)), /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Title" }, titleText), /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Help" }, helpText));
13388
13410
  }
13389
- const _excluded$1$22 = ["translations"];
13411
+ const _excluded$1$20 = ["translations"];
13390
13412
  function NoResultsScreen(_ref) {
13391
- let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$22);
13413
+ let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$20);
13392
13414
  const { noResultsText = "No results found for", suggestedQueryText = "Try searching for", reportMissingResultsText = "Believe this query should return results?", reportMissingResultsLinkText = "Let us know." } = translations;
13393
13415
  const searchSuggestions = props.state.context.searchSuggestions;
13394
13416
  return /* @__PURE__ */ En.createElement("div", { className: `DocSearch-NoResults ${props.canHandleAskAi ? "DocSearch-NoResults--withAskAi" : ""}` }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Screen-Icon" }, /* @__PURE__ */ En.createElement(NoResultsIcon, null)), /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Title" }, noResultsText, " \"", /* @__PURE__ */ En.createElement("strong", null, props.state.query), "\""), searchSuggestions && searchSuggestions.length > 0 && /* @__PURE__ */ En.createElement("div", { className: "DocSearch-NoResults-Prefill-List" }, /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Help" }, suggestedQueryText, ":"), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-NoResults-Prefill-List-Items" }, searchSuggestions.slice(0, 3).reduce((acc, search) => [...acc, /* @__PURE__ */ En.createElement("p", { key: search }, /* @__PURE__ */ En.createElement(SearchIcon, { size: 16 }), /* @__PURE__ */ En.createElement("button", {
@@ -13426,10 +13448,6 @@ function HitResultBadge({ item, resultBadgeKey, translations = {} }) {
13426
13448
  const _excluded$22 = ["translations", "resultBadgeKey"];
13427
13449
  function ResultsScreen(_ref) {
13428
13450
  let { translations = {}, resultBadgeKey } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$22);
13429
- const { resultsSectionTitle = "Results" } = translations;
13430
- const renderIcon = En.useCallback(({ item }) => {
13431
- return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-icon" }, /* @__PURE__ */ En.createElement(SourceIcon, { type: item.type }));
13432
- }, []);
13433
13451
  const renderAction = En.useCallback(() => {
13434
13452
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-action" }, /* @__PURE__ */ En.createElement(SelectIcon, null));
13435
13453
  }, []);
@@ -13442,22 +13460,45 @@ function ResultsScreen(_ref) {
13442
13460
  }, [resultBadgeKey, translations.resultBadgeLabelText]);
13443
13461
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Dropdown-Container" }, props.state.collections.map((collection) => {
13444
13462
  if (collection.items.length === 0) return null;
13463
+ const title = removeHighlightTags(collection.items[0]);
13445
13464
  return /* @__PURE__ */ En.createElement(Results, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
13446
13465
  key: collection.source.sourceId,
13447
13466
  translations,
13448
- title: resultsSectionTitle,
13467
+ title,
13449
13468
  collection,
13450
- renderIcon,
13469
+ renderIcon: ({ item, index }) => {
13470
+ var _collection$items;
13471
+ return /* @__PURE__ */ En.createElement(En.Fragment, null, item.__docsearch_parent && /* @__PURE__ */ En.createElement("svg", {
13472
+ className: "DocSearch-Hit-Tree",
13473
+ viewBox: "0 0 24 54"
13474
+ }, /* @__PURE__ */ En.createElement("g", {
13475
+ stroke: "currentColor",
13476
+ fill: "none",
13477
+ fillRule: "evenodd",
13478
+ strokeLinecap: "round",
13479
+ strokeLinejoin: "round"
13480
+ }, item.__docsearch_parent !== ((_collection$items = collection.items[index + 1]) === null || _collection$items === void 0 ? void 0 : _collection$items.__docsearch_parent) ? /* @__PURE__ */ En.createElement("path", { d: "M8 6v21M20 27H8.3" }) : /* @__PURE__ */ En.createElement("path", { d: "M8 6v42M20 27H8.3" }))), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-icon" }, /* @__PURE__ */ En.createElement(SourceIcon, { type: item.type })));
13481
+ },
13451
13482
  renderAction,
13452
13483
  renderResultBadge
13453
13484
  }));
13454
13485
  }), props.resultsFooterComponent && /* @__PURE__ */ En.createElement("section", { className: "DocSearch-HitsFooter" }, /* @__PURE__ */ En.createElement(props.resultsFooterComponent, { state: props.state })));
13455
13486
  }
13456
13487
  function createFacetFilters(searchParametersFacetFilters, facetSelections) {
13457
- const dynamicFacetFilters = Object.entries(facetSelections).filter(([, value]) => value).map(([facet, value]) => `${facet}:${value}`);
13458
- if (dynamicFacetFilters.length === 0) return searchParametersFacetFilters;
13459
- if (!searchParametersFacetFilters) return dynamicFacetFilters;
13460
- return [...searchParametersFacetFilters, ...dynamicFacetFilters];
13488
+ const selections = Object.entries(facetSelections);
13489
+ const selectedFacets = new Set(selections.map(([facet]) => facet));
13490
+ const dynamicFacetFilters = [];
13491
+ for (const [facet, selection] of selections) if (selection !== "") dynamicFacetFilters.push(`${facet}:${selection}`);
13492
+ if (selectedFacets.size === 0) return searchParametersFacetFilters;
13493
+ let configuredFacetFilters = [];
13494
+ if (searchParametersFacetFilters && Array.isArray(searchParametersFacetFilters)) configuredFacetFilters = searchParametersFacetFilters;
13495
+ else if (searchParametersFacetFilters) configuredFacetFilters = [searchParametersFacetFilters];
13496
+ return [...configuredFacetFilters.filter((facetFilter) => {
13497
+ if (typeof facetFilter !== "string") return true;
13498
+ const separatorIndex = facetFilter.indexOf(":");
13499
+ const facet = facetFilter.slice(0, separatorIndex);
13500
+ return separatorIndex <= 0 || !selectedFacets.has(facet);
13501
+ }), ...dynamicFacetFilters];
13461
13502
  }
13462
13503
  function buildNoQuerySources({ recentSearches, favoriteSearches, saveRecentSearch, onClose, disableUserPersonalization }) {
13463
13504
  if (disableUserPersonalization) return [];
@@ -13524,7 +13565,7 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13524
13565
  highlightPostTag: (_searchParams$highlig2 = searchParams === null || searchParams === void 0 ? void 0 : searchParams.highlightPostTag) !== null && _searchParams$highlig2 !== void 0 ? _searchParams$highlig2 : "</mark>",
13525
13566
  hitsPerPage: (_searchParams$hitsPer = searchParams === null || searchParams === void 0 ? void 0 : searchParams.hitsPerPage) !== null && _searchParams$hitsPer !== void 0 ? _searchParams$hitsPer : 20,
13526
13567
  clickAnalytics: (_searchParams$clickAn = searchParams === null || searchParams === void 0 ? void 0 : searchParams.clickAnalytics) !== null && _searchParams$clickAn !== void 0 ? _searchParams$clickAn : insightsActive
13527
- }, searchParams !== null && searchParams !== void 0 ? searchParams : {}), facetFilters ? { facetFilters } : {});
13568
+ }, searchParams), facetFilters ? { facetFilters } : {});
13528
13569
  }) });
13529
13570
  return results.flatMap((res) => {
13530
13571
  const result = res;
@@ -13547,9 +13588,8 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13547
13588
  apiKey
13548
13589
  }
13549
13590
  };
13550
- const items = Object.values(sources).flat();
13551
- return {
13552
- sourceId: `hits_${result.index}`,
13591
+ return Object.values(sources).map((items, index) => ({
13592
+ sourceId: `hits_${result.index}_${index}`,
13553
13593
  onSelect({ item, event }) {
13554
13594
  saveRecentSearch(item);
13555
13595
  if (!isModifierEvent(event)) onClose();
@@ -13563,26 +13603,18 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13563
13603
  const potentialParent = groupedHits.find((siblingItem) => siblingItem.type === "lvl1" && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1);
13564
13604
  if (item.type !== "lvl1" && potentialParent) parent = potentialParent;
13565
13605
  return _objectSpread2$2(_objectSpread2$2({}, item), {}, { __docsearch_parent: parent }, insightsParams);
13566
- }).flat()).flat();
13606
+ })).flat();
13567
13607
  }
13568
- };
13608
+ }));
13569
13609
  });
13570
13610
  } catch (error) {
13571
13611
  if (error.name === "RetryError") setStatus("error");
13572
13612
  throw error;
13573
13613
  }
13574
13614
  }
13575
- function normalizeDocSearchIndexes({ indexName, indices = [], searchParameters }) {
13576
- const indexes = [];
13577
- if (indexName && indexName !== "") indexes.push({
13578
- name: indexName,
13579
- searchParameters
13580
- });
13581
- if (indices.length > 0) indices.forEach((index) => {
13582
- indexes.push(typeof index === "string" ? { name: index } : index);
13583
- });
13584
- if (indexes.length < 1) throw new Error("Must supply either `indexName` or `indices` for DocSearch to work");
13585
- return indexes;
13615
+ function normalizeDocSearchIndexes({ indices }) {
13616
+ if (!Array.isArray(indices) || indices.length < 1) throw new Error("Must supply at least one `indices` entry for DocSearch");
13617
+ return indices.map((index) => typeof index === "string" ? { name: index } : index);
13586
13618
  }
13587
13619
 
13588
13620
  //#endregion
@@ -13789,7 +13821,7 @@ const _excluded$21 = [
13789
13821
  "closeDelay",
13790
13822
  "id"
13791
13823
  ];
13792
- const PopoverTrigger$1 = /*#__PURE__*/ M$1(function PopoverTrigger(componentProps, forwardedRef) {
13824
+ const PopoverTrigger = /*#__PURE__*/ M$1(function PopoverTrigger(componentProps, forwardedRef) {
13793
13825
  var _handle$store;
13794
13826
  const { render, className, style, disabled = false, nativeButton = true, handle, payload, openOnHover = false, delay = 300, closeDelay = 0, id: idProp } = componentProps, elementProps = _objectWithoutProperties$5(componentProps, _excluded$21);
13795
13827
  const rootContext = usePopoverRootContext(true);
@@ -27212,7 +27244,7 @@ var require_throttleit = /* @__PURE__ */ __commonJSMin(((exports, module) => {
27212
27244
  //#region ../../node_modules/.bun/@ai-sdk+react@2.0.215+38ec045d21336c81/node_modules/@ai-sdk/react/dist/index.mjs
27213
27245
  init_compat();
27214
27246
  var import_throttleit = /* @__PURE__ */ __toESM(require_throttleit(), 1);
27215
- const _excluded$13 = ["messages"];
27247
+ const _excluded$12 = ["messages"];
27216
27248
  const _excluded2$4 = ["experimental_throttle", "resume"];
27217
27249
  var __accessCheck = (obj, member, msg) => {
27218
27250
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
@@ -27331,7 +27363,7 @@ _callErrorCallbacks = /* @__PURE__ */ new WeakMap();
27331
27363
  var _state;
27332
27364
  var Chat = class extends AbstractChat {
27333
27365
  constructor(_ref) {
27334
- let { messages } = _ref, init = _objectWithoutProperties$5(_ref, _excluded$13);
27366
+ let { messages } = _ref, init = _objectWithoutProperties$5(_ref, _excluded$12);
27335
27367
  const state = new ReactChatState(messages);
27336
27368
  super(_objectSpread2$1(_objectSpread2$1({}, init), {}, { state }));
27337
27369
  __privateAdd(this, _state, void 0);
@@ -27376,7 +27408,7 @@ function useChat(_ref2 = {}) {
27376
27408
  }
27377
27409
 
27378
27410
  //#endregion
27379
- //#region ../docsearch-react/dist/esm/useSuggestedQuestions-CG2H3qm4.js
27411
+ //#region ../docsearch-react/dist/esm/useSuggestedQuestions-Ds7H1JCr.js
27380
27412
  init_compat();
27381
27413
  function AlertIcon(props) {
27382
27414
  return /* @__PURE__ */ En.createElement("svg", _objectSpread2$2({
@@ -27602,7 +27634,7 @@ function FeedbackActions({ id, showActions, latestAssistantMessageContent, trans
27602
27634
  translations,
27603
27635
  onClick: () => navigator.clipboard.writeText(latestAssistantMessageContent)
27604
27636
  });
27605
- return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Actions" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Actions-Controls" }, isSidepanel ? copyButton : null, view === "thanks" ? /* @__PURE__ */ En.createElement("p", { className: "DocSearch-AskAiScreen-FeedbackText DocSearch-AskAiScreen-FeedbackText--visible" }, thanksForFeedbackText) : /* @__PURE__ */ En.createElement(En.Fragment, null, saving && view === "actions" ? /* @__PURE__ */ En.createElement(LoadingIcon, { className: "DocSearch-AskAiScreen-SmallerLoadingIcon" }) : /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement(LikeButton, {
27637
+ return /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Actions-Controls" }, isSidepanel ? copyButton : null, view === "thanks" ? /* @__PURE__ */ En.createElement("p", { className: "DocSearch-AskAiScreen-FeedbackText DocSearch-AskAiScreen-FeedbackText--visible" }, thanksForFeedbackText) : /* @__PURE__ */ En.createElement(En.Fragment, null, saving && view === "actions" ? /* @__PURE__ */ En.createElement(LoadingIcon, { className: "DocSearch-AskAiScreen-SmallerLoadingIcon" }) : /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement(LikeButton, {
27606
27638
  title: likeButtonTitle,
27607
27639
  onClick: handleLike
27608
27640
  }), /* @__PURE__ */ En.createElement(DislikeButton, {
@@ -27621,18 +27653,22 @@ function FeedbackActions({ id, showActions, latestAssistantMessageContent, trans
27621
27653
  }) : null);
27622
27654
  }
27623
27655
  function NegativeFeedbackPanel({ translations, tags, notes, saving, savingError, onToggleTag, onNotesChange, onSubmit, onClose }) {
27656
+ const feedbackTitleId = En.useId();
27624
27657
  const { feedbackPanelTitle = "What went wrong? (optional)", feedbackDetailsPlaceholder = "Share some details...", feedbackSubmitButtonText = "Submit", feedbackCancelButtonText = "Cancel" } = translations;
27625
27658
  return /* @__PURE__ */ En.createElement("div", {
27626
27659
  className: "DocSearch-Feedback-Panel",
27627
27660
  role: "group",
27628
- "aria-label": feedbackPanelTitle
27629
- }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Feedback-Panel-Header" }, /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Feedback-Panel-Title" }, feedbackPanelTitle)), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Feedback-Panel-Reasons" }, FEEDBACK_REASONS.map((reason) => {
27661
+ "aria-labelledby": feedbackTitleId
27662
+ }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Feedback-Panel-Header" }, /* @__PURE__ */ En.createElement("p", {
27663
+ className: "DocSearch-Feedback-Panel-Title",
27664
+ id: feedbackTitleId
27665
+ }, feedbackPanelTitle)), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Feedback-Panel-Reasons" }, FEEDBACK_REASONS.map((reason) => {
27630
27666
  var _translations$reason$;
27631
27667
  const isSelected = tags.includes(reason.value);
27632
27668
  return /* @__PURE__ */ En.createElement("button", {
27633
27669
  key: reason.value,
27634
27670
  type: "button",
27635
- className: `DocSearch-Feedback-Panel-Reason${isSelected ? " DocSearch-Feedback-Panel-Reason--selected" : ""}`,
27671
+ className: "DocSearch-Feedback-Panel-Reason",
27636
27672
  "aria-pressed": isSelected,
27637
27673
  onClick: () => onToggleTag(reason.value)
27638
27674
  }, /* @__PURE__ */ En.createElement("span", null, (_translations$reason$ = translations[reason.translationKey]) !== null && _translations$reason$ !== void 0 ? _translations$reason$ : reason.defaultLabel));
@@ -27757,12 +27793,14 @@ function Popover$1(_ref) {
27757
27793
  let props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
27758
27794
  return /* @__PURE__ */ En.createElement(PopoverRoot, props);
27759
27795
  }
27760
- function PopoverTrigger(_ref2) {
27796
+ Popover$1.Trigger = En.forwardRef((_ref2, ref) => {
27761
27797
  let { className } = _ref2, props = _objectWithoutProperties$6(_ref2, _excluded$2$12);
27762
27798
  const cn = `DocSearch-Popover-Trigger${className ? ` ${className}` : ""}`;
27763
- return /* @__PURE__ */ En.createElement(PopoverTrigger$1, _objectSpread2$2({ className: cn }, props));
27764
- }
27765
- Popover$1.Trigger = PopoverTrigger;
27799
+ return /* @__PURE__ */ En.createElement(PopoverTrigger, _objectSpread2$2({
27800
+ className: cn,
27801
+ ref
27802
+ }, props));
27803
+ });
27766
27804
  function PopoverPopup(_ref3) {
27767
27805
  let { align = "center", alignOffset = 0, side = "bottom", sideOffset = 4, collisionBoundary = "clipping-ancestors", container, children } = _ref3, props = _objectWithoutProperties$6(_ref3, _excluded2$3);
27768
27806
  return /* @__PURE__ */ En.createElement(PopoverPortal, { container }, /* @__PURE__ */ En.createElement(PopoverPositioner, {
@@ -27780,10 +27818,11 @@ function PopoverTitle(_ref4) {
27780
27818
  return /* @__PURE__ */ En.createElement(PopoverTitle$1, _objectSpread2$2({ className: "DocSearch-Popover-Title" }, props));
27781
27819
  }
27782
27820
  Popover$1.Title = PopoverTitle;
27783
- function SourcesPanel({ links, titleText = "Sources" }) {
27821
+ function SourcesPanel({ links, titleText = "Source", pluralTitleText = "Sources" }) {
27784
27822
  const [open, setOpen] = En.useState(false);
27785
27823
  const triggerRef = En.useRef(null);
27786
27824
  const [boundary, setBoundary] = En.useState(null);
27825
+ const sourcesTitle = links.length > 1 ? pluralTitleText : titleText;
27787
27826
  _$1(() => {
27788
27827
  var _ref, _trigger$closest;
27789
27828
  if (!open) return;
@@ -27810,13 +27849,13 @@ function SourcesPanel({ links, titleText = "Sources" }) {
27810
27849
  }, /* @__PURE__ */ En.createElement(Popover$1.Trigger, {
27811
27850
  ref: triggerRef,
27812
27851
  className: "DocSearch-AskAiScreen-Sources-Action"
27813
- }, /* @__PURE__ */ En.createElement("span", { className: "DocSearch-AskAiScreen-Sources-Action-icon" }, /* @__PURE__ */ En.createElement(ContentIcon, null)), /* @__PURE__ */ En.createElement("span", { className: "DocSearch-AskAiScreen-Sources-Action-text" }, links.length, " sources")), /* @__PURE__ */ En.createElement(Popover$1.Popup, {
27852
+ }, /* @__PURE__ */ En.createElement("span", { className: "DocSearch-AskAiScreen-Sources-Action-icon" }, /* @__PURE__ */ En.createElement(ContentIcon, null)), /* @__PURE__ */ En.createElement("span", { className: "DocSearch-AskAiScreen-Sources-Action-text" }, links.length, " ", sourcesTitle)), /* @__PURE__ */ En.createElement(Popover$1.Popup, {
27814
27853
  container: boundary,
27815
27854
  sideOffset: 10,
27816
27855
  align: "start",
27817
27856
  alignOffset: -16,
27818
27857
  collisionBoundary: boundary !== null && boundary !== void 0 ? boundary : "clipping-ancestors"
27819
- }, /* @__PURE__ */ En.createElement(Popover$1.Title, null, titleText), /* @__PURE__ */ En.createElement("ul", { className: "DocSearch-AskAiScreen-Sources" }, links.map((l) => /* @__PURE__ */ En.createElement("li", {
27858
+ }, /* @__PURE__ */ En.createElement(Popover$1.Title, null, sourcesTitle), /* @__PURE__ */ En.createElement("ul", { className: "DocSearch-AskAiScreen-Sources" }, links.map((l) => /* @__PURE__ */ En.createElement("li", {
27820
27859
  key: l.url,
27821
27860
  className: "DocSearch-AskAiScreen-Sources-source"
27822
27861
  }, /* @__PURE__ */ En.createElement("a", {
@@ -27896,7 +27935,10 @@ const buildDummyAskAiHit = (query, messages, chatId) => {
27896
27935
  url_without_anchor: ""
27897
27936
  };
27898
27937
  };
27899
- const getMessageContent = (message) => message === null || message === void 0 ? void 0 : message.parts.find((part) => part.type === "text");
27938
+ const getMessageContent = (message) => {
27939
+ var _message$parts;
27940
+ return ((_message$parts = message === null || message === void 0 ? void 0 : message.parts) !== null && _message$parts !== void 0 ? _message$parts : []).filter((part) => part.type === "text").map((part) => part.text).join("\n\n");
27941
+ };
27900
27942
  /** Helper function to check if error is a thread depth error (AI-217). */
27901
27943
  function isThreadDepthError(error) {
27902
27944
  var _error$message;
@@ -28147,7 +28189,7 @@ function groupConsecutiveToolResults(parts) {
28147
28189
  }
28148
28190
  return aggregatedParts;
28149
28191
  }
28150
- const _excluded$1$11 = [
28192
+ const _excluded$1$10 = [
28151
28193
  "children",
28152
28194
  "className",
28153
28195
  "onClick"
@@ -28197,7 +28239,7 @@ function MenuContent({ children }) {
28197
28239
  }
28198
28240
  Menu.Content = MenuContent;
28199
28241
  function MenuItem(_ref) {
28200
- let { children, className = "", onClick } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$11);
28242
+ let { children, className = "", onClick } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$10);
28201
28243
  const { setOpen } = En.useContext(MenuContext);
28202
28244
  const handleClick = (e) => {
28203
28245
  if (onClick) {
@@ -28244,24 +28286,24 @@ const postAgentStudioFeedback = ({ agentId, vote, messageId, appId, apiKey, abor
28244
28286
  signal: abortSignal
28245
28287
  });
28246
28288
  };
28247
- const _excluded$12 = [
28289
+ const _excluded$13 = [
28248
28290
  "id",
28249
28291
  "messages",
28250
28292
  "body"
28251
28293
  ];
28252
- const getAgentStudioTransport = ({ appId, apiKey, assistantId, searchParameters, userToken, indices }) => {
28294
+ const getAgentStudioTransport = ({ appId, apiKey, agentId, searchParameters, userToken, indices }) => {
28253
28295
  const algoliaParams = {};
28254
28296
  if (searchParameters) algoliaParams.searchParameters = searchParameters;
28255
28297
  if (indices && indices.length > 0) algoliaParams.indices = indices;
28256
28298
  return new DefaultChatTransport({
28257
- api: `${agentStudioBaseUrl(appId)}/agents/${assistantId}/completions?stream=true&compatibilityMode=ai-sdk-5`,
28299
+ api: `${agentStudioBaseUrl(appId)}/agents/${agentId}/completions?stream=true&compatibilityMode=ai-sdk-5`,
28258
28300
  headers: _objectSpread2$2({
28259
28301
  "x-algolia-application-id": appId,
28260
28302
  "x-algolia-api-key": apiKey
28261
28303
  }, userToken ? { "x-algolia-secure-user-token": userToken } : {}),
28262
28304
  body: { algolia: algoliaParams },
28263
28305
  prepareSendMessagesRequest(_ref) {
28264
- let { id, messages, body } = _ref, rest = _objectWithoutProperties$6(_ref, _excluded$12);
28306
+ let { id, messages, body } = _ref, rest = _objectWithoutProperties$6(_ref, _excluded$13);
28265
28307
  const sanitizedMessages = sanitizeMessagesForRequest(messages);
28266
28308
  return _objectSpread2$2(_objectSpread2$2({}, rest), {}, { body: _objectSpread2$2({
28267
28309
  id,
@@ -28270,19 +28312,19 @@ const getAgentStudioTransport = ({ appId, apiKey, assistantId, searchParameters,
28270
28312
  }
28271
28313
  });
28272
28314
  };
28273
- const useAskAi = ({ assistantId, apiKey, appId, indexName, tools = EMPTY_TOOLS, searchParameters, memory, indices }) => {
28315
+ const useAskAi = ({ agentId, apiKey, appId, tools = EMPTY_TOOLS, searchParameters, memory, indices }) => {
28274
28316
  const abortControllerRef = F$2(new AbortController());
28275
28317
  const askAiTransport = q$2(() => getAgentStudioTransport({
28276
28318
  apiKey,
28277
28319
  appId,
28278
- assistantId,
28320
+ agentId,
28279
28321
  searchParameters,
28280
28322
  userToken: memory === null || memory === void 0 ? void 0 : memory.userToken,
28281
28323
  indices
28282
28324
  }), [
28283
28325
  apiKey,
28284
28326
  appId,
28285
- assistantId,
28327
+ agentId,
28286
28328
  searchParameters,
28287
28329
  memory === null || memory === void 0 ? void 0 : memory.userToken,
28288
28330
  indices
@@ -28319,14 +28361,14 @@ const useAskAi = ({ assistantId, apiKey, appId, indexName, tools = EMPTY_TOOLS,
28319
28361
  addToolOutputRef.current = addToolOutput;
28320
28362
  }, [addToolOutput]);
28321
28363
  const conversations = F$2(createStoredConversations({
28322
- key: `__DOCSEARCH_ASKAI_CONVERSATIONS__${indexName}`,
28364
+ key: `__DOCSEARCH_ASKAI_CONVERSATIONS__${appId}`,
28323
28365
  limit: 10
28324
28366
  })).current;
28325
28367
  const sendFeedback = b$1(async (messageId, { thumbs, tags, notes }) => {
28326
28368
  var _conversations$addFee;
28327
- if (!assistantId) return;
28369
+ if (!agentId) return;
28328
28370
  if ((await postAgentStudioFeedback({
28329
- agentId: assistantId,
28371
+ agentId,
28330
28372
  vote: thumbs,
28331
28373
  messageId,
28332
28374
  appId,
@@ -28340,7 +28382,7 @@ const useAskAi = ({ assistantId, apiKey, appId, indexName, tools = EMPTY_TOOLS,
28340
28382
  notes
28341
28383
  });
28342
28384
  }, [
28343
- assistantId,
28385
+ agentId,
28344
28386
  appId,
28345
28387
  apiKey,
28346
28388
  conversations
@@ -28397,22 +28439,22 @@ const useAskAi = ({ assistantId, apiKey, appId, indexName, tools = EMPTY_TOOLS,
28397
28439
  restoreConversation
28398
28440
  };
28399
28441
  };
28400
- const useSuggestedQuestions = ({ assistantId, searchClient, suggestedQuestionsEnabled = false }) => {
28442
+ const useSuggestedQuestions = ({ agentId, searchClient, suggestedQuestionsEnabled = false }) => {
28401
28443
  const [suggestedQuestions, setSuggestedQuestions] = h([]);
28402
28444
  _$1(() => {
28403
28445
  const getSuggestedQuestions = async () => {
28404
28446
  const { results } = await searchClient.search({ requests: [{
28405
28447
  indexName: SUGGESTED_QUETIONS_INDEX_NAME,
28406
- filters: `state:published AND assistantId:${assistantId}`,
28448
+ filters: `state:published AND assistantId:${agentId}`,
28407
28449
  hitsPerPage: 3
28408
28450
  }] });
28409
28451
  const result = results[0];
28410
28452
  setSuggestedQuestions(result.hits);
28411
28453
  };
28412
- if (suggestedQuestionsEnabled && assistantId && assistantId !== "") getSuggestedQuestions();
28454
+ if (suggestedQuestionsEnabled && agentId && agentId !== "") getSuggestedQuestions();
28413
28455
  }, [
28414
28456
  suggestedQuestionsEnabled,
28415
- assistantId,
28457
+ agentId,
28416
28458
  searchClient
28417
28459
  ]);
28418
28460
  return suggestedQuestions;
@@ -31226,7 +31268,7 @@ function createAutocomplete(options) {
31226
31268
  }
31227
31269
 
31228
31270
  //#endregion
31229
- //#region ../docsearch-react/dist/esm/DocSearchAskAiModal-KaA6fBV4.js
31271
+ //#region ../docsearch-react/dist/esm/DocSearchAskAiModal-BczGFkvR.js
31230
31272
  init_compat();
31231
31273
  function MessageIcon() {
31232
31274
  return /* @__PURE__ */ En.createElement("svg", {
@@ -31284,9 +31326,9 @@ function AskAiScreenDisclaimer({ disclaimerText }) {
31284
31326
  return /* @__PURE__ */ En.createElement("p", { className: "DocSearch-AskAiScreen-Disclaimer" }, /* @__PURE__ */ En.createElement(SparklesIcon, null), " ", disclaimerText);
31285
31327
  }
31286
31328
  function AskAiExchangeCard({ exchange, askAiError, isLastExchange, loadingStatus, onSearchQueryClick, translations, tools, conversations, onFeedback, memoryEnabled, onSelectPromptSuggestion }) {
31287
- var _userMessage$metadata, _assistantMessage$met, _userContent$text;
31329
+ var _userMessage$metadata, _assistantMessage$met;
31288
31330
  const { userMessage, assistantMessage } = exchange;
31289
- const { stoppedStreamingText = "You stopped this response", errorTitleText = "Chat error", relatedSourcesText, suggestedPromptsTitleText = "Suggested prompts" } = translations;
31331
+ const { stoppedStreamingText = "You stopped this response", errorTitleText = "Chat error", relatedSourcesText, relatedSourcesTextPlural, suggestedPromptsTitleText = "Suggested prompts" } = translations;
31290
31332
  const toolCallTranslations = q$2(() => toToolCallTranslations(translations), [translations]);
31291
31333
  const isThreadDepth = isThreadDepthError(askAiError);
31292
31334
  const assistantContent = q$2(() => getMessageContent(assistantMessage), [assistantMessage]);
@@ -31303,7 +31345,7 @@ function AskAiExchangeCard({ exchange, askAiError, isLastExchange, loadingStatus
31303
31345
  const showActions = !wasStopped && (!isLastExchange || isLastExchange && loadingStatus === "ready" && Boolean(assistantMessage));
31304
31346
  const isThinking = ["submitted", "streaming"].includes(loadingStatus) && isLastExchange && !displayParts.some((part) => part.type !== "step-start");
31305
31347
  const messageId = (assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.id) || exchange.id;
31306
- return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Response-Container" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Response" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Message DocSearch-AskAiScreen-Message--user" }, /* @__PURE__ */ En.createElement("p", { className: "DocSearch-AskAiScreen-Query" }, (_userContent$text = userContent === null || userContent === void 0 ? void 0 : userContent.text) !== null && _userContent$text !== void 0 ? _userContent$text : "")), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Message DocSearch-AskAiScreen-Message--assistant" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-MessageContent" }, loadingStatus === "error" && askAiError && isLastExchange && !isThreadDepth && /* @__PURE__ */ En.createElement("div", {
31348
+ return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Response-Container" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Response" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Message DocSearch-AskAiScreen-Message--user" }, /* @__PURE__ */ En.createElement("p", { className: "DocSearch-AskAiScreen-Query" }, userContent !== null && userContent !== void 0 ? userContent : "")), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Message DocSearch-AskAiScreen-Message--assistant" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-MessageContent" }, loadingStatus === "error" && askAiError && isLastExchange && !isThreadDepth && /* @__PURE__ */ En.createElement("div", {
31307
31349
  className: "DocSearch-AskAiScreen-Error",
31308
31350
  role: "alert"
31309
31351
  }, /* @__PURE__ */ En.createElement(AlertIcon, { "aria-hidden": "true" }), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Error-Content" }, /* @__PURE__ */ En.createElement("h4", { className: "DocSearch-AskAiScreen-Error-Title" }, errorTitleText), /* @__PURE__ */ En.createElement(MemoizedMarkdown, {
@@ -31351,11 +31393,12 @@ function AskAiExchangeCard({ exchange, askAiError, isLastExchange, loadingStatus
31351
31393
  return null;
31352
31394
  })), wasStopped && /* @__PURE__ */ En.createElement("p", { className: "DocSearch-AskAiScreen-MessageContent-Stopped" }, stoppedStreamingText)), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-AskAiScreen-Answer-Footer" }, /* @__PURE__ */ En.createElement(SourcesPanel, {
31353
31395
  links: urlsToDisplay,
31354
- titleText: relatedSourcesText
31396
+ titleText: relatedSourcesText,
31397
+ pluralTitleText: relatedSourcesTextPlural
31355
31398
  }), /* @__PURE__ */ En.createElement(FeedbackActions, {
31356
31399
  id: messageId,
31357
31400
  showActions,
31358
- latestAssistantMessageContent: (assistantContent === null || assistantContent === void 0 ? void 0 : assistantContent.text) || null,
31401
+ latestAssistantMessageContent: assistantContent || null,
31359
31402
  translations,
31360
31403
  conversations,
31361
31404
  onFeedback
@@ -31423,7 +31466,7 @@ function RecentConversationsResults(_ref) {
31423
31466
  return /* @__PURE__ */ En.createElement(Results, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
31424
31467
  title: recentConversationsTitle,
31425
31468
  collection: recentConversations,
31426
- renderIcon: () => /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-icon DocSearch-Hit-icon--small" }, /* @__PURE__ */ En.createElement(MessageIcon, null)),
31469
+ renderIcon: () => /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-icon DocSearch-Hit-icon--start" }, /* @__PURE__ */ En.createElement(MessageIcon, null)),
31427
31470
  renderAction: ({ item }) => /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-action" }, /* @__PURE__ */ En.createElement("button", {
31428
31471
  className: "DocSearch-Hit-action-button",
31429
31472
  title: removeRecentConversationButtonTitle,
@@ -31477,10 +31520,10 @@ function NewConversationScreen({ translations = {}, suggestedQuestions = [], sel
31477
31520
  onClick: () => selectSuggestedQuestion(question)
31478
31521
  }, question.question))));
31479
31522
  }
31480
- const _excluded$2 = ["translations", "selectAskAiQuestion"];
31523
+ const _excluded$2$1 = ["translations", "selectAskAiQuestion"];
31481
31524
  const AskAiScreenState = En.memo((_ref) => {
31482
31525
  var _props$state;
31483
- let { translations = {}, selectAskAiQuestion } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$2);
31526
+ let { translations = {}, selectAskAiQuestion } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$2$1);
31484
31527
  const handleSelectPromptSuggestion = En.useCallback((prompt) => {
31485
31528
  selectAskAiQuestion(true, prompt);
31486
31529
  }, [selectAskAiQuestion]);
@@ -31501,15 +31544,18 @@ const AskAiScreenState = En.memo((_ref) => {
31501
31544
  onSelectPromptSuggestion: handleSelectPromptSuggestion
31502
31545
  }));
31503
31546
  if (((_props$state = props.state) === null || _props$state === void 0 ? void 0 : _props$state.status) === "error") return /* @__PURE__ */ En.createElement(ErrorScreen, { translations: translations === null || translations === void 0 ? void 0 : translations.errorScreen });
31504
- if (!props.state.query) return /* @__PURE__ */ En.createElement(AskAiStartScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
31547
+ if (isQueryEmpty(props.state.query)) return /* @__PURE__ */ En.createElement(AskAiStartScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
31505
31548
  hasCollections: props.hasCollections,
31506
31549
  translations: translations === null || translations === void 0 ? void 0 : translations.startScreen,
31507
31550
  selectAskAiQuestion
31508
31551
  }));
31509
31552
  if (!props.hasCollections && !props.canHandleAskAi) return /* @__PURE__ */ En.createElement(NoResultsScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.noResultsScreen }));
31510
31553
  return /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement(ResultsScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.resultsScreen })), props.canHandleAskAi && !props.hasCollections && /* @__PURE__ */ En.createElement(NoResultsScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.noResultsScreen })));
31511
- }, function areEqual(_prevProps, nextProps) {
31512
- return nextProps.state.status === "loading" || nextProps.state.status === "stalled";
31554
+ }, function areEqual(prevProps, nextProps) {
31555
+ if (prevProps.isAskAiActive !== nextProps.isAskAiActive || prevProps.askAiState !== nextProps.askAiState || prevProps.canHandleAskAi !== nextProps.canHandleAskAi) return false;
31556
+ const isLoading = nextProps.state.status === "loading" || nextProps.state.status === "stalled";
31557
+ const isWaitingForCollections = nextProps.state.status === "idle" && !isQueryEmpty(nextProps.state.query) && prevProps.state.query !== nextProps.state.query && prevProps.state.collections === nextProps.state.collections;
31558
+ return isLoading || isWaitingForCollections;
31513
31559
  });
31514
31560
  function ModalHeading({ heading, shimmer = false }) {
31515
31561
  return /* @__PURE__ */ En.createElement("span", { className: `DocSearch-Modal-heading${shimmer ? " DocSearch-shimmer" : ""}` }, heading);
@@ -31564,7 +31610,7 @@ function AskAiSearchBox(_ref) {
31564
31610
  onKeyDown: (e) => {
31565
31611
  let askAiHandled = false;
31566
31612
  if (props.isAskAiActive && blockedKeys.has(e.key)) {
31567
- if (e.key === "Enter" && !isAskAiStreaming && props.state.query) props.onAskAgain(props.state.query);
31613
+ if (e.key === "Enter" && !isAskAiStreaming && !isQueryEmpty(props.state.query)) props.onAskAgain(props.state.query);
31568
31614
  askAiHandled = true;
31569
31615
  }
31570
31616
  if (askAiHandled) {
@@ -31766,8 +31812,6 @@ const _excluded$7 = [
31766
31812
  "recentSearchesLimit",
31767
31813
  "recentSearchesWithFavoritesLimit",
31768
31814
  "indices",
31769
- "indexName",
31770
- "searchParameters",
31771
31815
  "facets",
31772
31816
  "isHybridModeSupported"
31773
31817
  ];
@@ -31778,7 +31822,7 @@ const _excluded2 = [
31778
31822
  ];
31779
31823
  function DocSearchAskAiModal(_ref) {
31780
31824
  var _translations$searchB, _askAiConfig$memory$e, _askAiConfig$memory, _askAiConfig$tools;
31781
- let { appId, apiKey, askAi, maxResultsPerGroup, theme, onClose = noop$2, transformItems = identity, hitComponent = Hit, resultsFooterComponent = () => null, navigator, initialScrollY = 0, transformSearchClient = identity, disableUserPersonalization = false, initialQuery: initialQueryFromProp = "", translations = {}, getMissingResultsUrl, insights = false, onAskAiToggle, interceptAskAiEvent, isAskAiActive = false, recentSearchesLimit = 7, recentSearchesWithFavoritesLimit = 4, indices = [], indexName, searchParameters, facets, isHybridModeSupported = false } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$7);
31825
+ let { appId, apiKey, askAi, maxResultsPerGroup, theme, onClose = noop$2, transformItems = identity, hitComponent = Hit, resultsFooterComponent = () => null, navigator, initialScrollY = 0, transformSearchClient = identity, disableUserPersonalization = false, initialQuery: initialQueryFromProp = "", translations = {}, getMissingResultsUrl, insights = false, onAskAiToggle, interceptAskAiEvent, isAskAiActive = false, recentSearchesLimit = 7, recentSearchesWithFavoritesLimit = 4, indices, facets, isHybridModeSupported = false } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$7);
31782
31826
  const { footer: footerTranslations, searchBox: searchBoxTranslations, facets: facetBarTranslations } = translations, screenStateTranslations = _objectWithoutProperties$6(translations, _excluded2);
31783
31827
  const [state, setState] = En.useState({
31784
31828
  query: "",
@@ -31803,25 +31847,17 @@ function DocSearchAskAiModal(_ref) {
31803
31847
  const { initialQuery, initialQueryFromSelection } = useInitialModalQuery(initialQueryFromProp);
31804
31848
  const searchClient = useSearchClient(appId, apiKey, transformSearchClient);
31805
31849
  const askAiConfig = typeof askAi === "object" ? askAi : null;
31806
- const askAiConfigurationId = askAiConfig ? askAiConfig.assistantId : askAi;
31850
+ const askAiConfigurationId = askAiConfig ? askAiConfig.agentId : askAi;
31807
31851
  const askAiSearchParameters = askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.searchParameters;
31808
31852
  const [askAiState, setAskAiState] = En.useState("initial");
31809
31853
  const suggestedQuestions = useSuggestedQuestions({
31810
- assistantId: askAiConfigurationId,
31854
+ agentId: askAiConfigurationId,
31811
31855
  searchClient,
31812
31856
  suggestedQuestionsEnabled: askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.suggestedQuestions
31813
31857
  });
31814
31858
  const memoryEnabled = (_askAiConfig$memory$e = askAiConfig === null || askAiConfig === void 0 || (_askAiConfig$memory = askAiConfig.memory) === null || _askAiConfig$memory === void 0 ? void 0 : _askAiConfig$memory.enabled) !== null && _askAiConfig$memory$e !== void 0 ? _askAiConfig$memory$e : false;
31815
31859
  const tools = (_askAiConfig$tools = askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.tools) !== null && _askAiConfig$tools !== void 0 ? _askAiConfig$tools : EMPTY_TOOLS;
31816
- const indexes = En.useMemo(() => normalizeDocSearchIndexes({
31817
- indexName,
31818
- indices,
31819
- searchParameters
31820
- }), [
31821
- indexName,
31822
- indices,
31823
- searchParameters
31824
- ]);
31860
+ const indexes = En.useMemo(() => normalizeDocSearchIndexes({ indices }), [indices]);
31825
31861
  const defaultIndexName = indexes[0].name;
31826
31862
  const autocompleteRef = En.useRef(void 0);
31827
31863
  const { visibleFacets, facetSelections, facetSelectionsRef, handleFacetSelectionChange, clearFacetSelections } = useDocSearchFacets({
@@ -31840,10 +31876,9 @@ function DocSearchAskAiModal(_ref) {
31840
31876
  });
31841
31877
  const [stoppedStream, setStoppedStream] = En.useState(false);
31842
31878
  const { chatId, messages, status, setMessages, sendMessage, stopAskAiStreaming, askAiError, sendFeedback, conversations, startNewConversation, restoreConversation } = useAskAi({
31843
- assistantId: askAiConfigurationId,
31879
+ agentId: askAiConfigurationId,
31844
31880
  apiKey: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.apiKey) || apiKey,
31845
31881
  appId: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.appId) || appId,
31846
- indexName: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.indexName) || defaultIndexName,
31847
31882
  searchParameters: askAiSearchParameters,
31848
31883
  tools,
31849
31884
  memory: askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.memory,
@@ -31940,7 +31975,7 @@ function DocSearchAskAiModal(_ref) {
31940
31975
  setState(changes.state);
31941
31976
  },
31942
31977
  async getSources({ query, state: sourcesState, setContext, setStatus }) {
31943
- if (!query) {
31978
+ if (isQueryEmpty(query)) {
31944
31979
  const noQuerySources = buildNoQuerySources({
31945
31980
  recentSearches,
31946
31981
  favoriteSearches,
@@ -32038,7 +32073,7 @@ function DocSearchAskAiModal(_ref) {
32038
32073
  };
32039
32074
  let showDocsearchDropdown = true;
32040
32075
  const hasCollections = state.collections.some((collection) => collection.source.sourceId !== SOURCE_IDS.askAI && collection.items.length > 0);
32041
- if (state.status === "idle" && hasCollections === false && state.query.length === 0 && !isAskAiActive) showDocsearchDropdown = false;
32076
+ if (state.status === "idle" && hasCollections === false && isQueryEmpty(state.query) && !isAskAiActive) showDocsearchDropdown = false;
32042
32077
  return /* @__PURE__ */ En.createElement(ModalShell, {
32043
32078
  state,
32044
32079
  containerRef,
@@ -32050,7 +32085,7 @@ function DocSearchAskAiModal(_ref) {
32050
32085
  searchBox: /* @__PURE__ */ En.createElement(AskAiSearchBox, _objectSpread2$2(_objectSpread2$2({}, autocomplete), {}, {
32051
32086
  state,
32052
32087
  placeholder: placeholder || "Search docs",
32053
- autoFocus: initialQuery.length === 0,
32088
+ autoFocus: isQueryEmpty(initialQuery),
32054
32089
  inputRef,
32055
32090
  isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection,
32056
32091
  translations: searchBoxTranslations,
@@ -32069,7 +32104,7 @@ function DocSearchAskAiModal(_ref) {
32069
32104
  onNewConversation: handleNewConversation,
32070
32105
  onViewConversationHistory: handleViewConversationHistory
32071
32106
  })),
32072
- filterBar: !isAskAiActive && state.query !== "" ? /* @__PURE__ */ En.createElement(FacetBar, {
32107
+ filterBar: !isAskAiActive && !isQueryEmpty(state.query) ? /* @__PURE__ */ En.createElement(FacetBar, {
32073
32108
  facets: visibleFacets,
32074
32109
  selections: facetSelections,
32075
32110
  translations: facetBarTranslations,
@@ -32284,8 +32319,10 @@ function _objectWithoutProperties(e, t) {
32284
32319
  }
32285
32320
  return i;
32286
32321
  }
32287
- const _excluded$1 = [
32322
+ const _excluded$2 = [
32288
32323
  "children",
32324
+ "appId",
32325
+ "apiKey",
32289
32326
  "theme",
32290
32327
  "onReady",
32291
32328
  "onOpen",
@@ -32296,7 +32333,7 @@ const _excluded$1 = [
32296
32333
  const Context = En.createContext(void 0);
32297
32334
  Context.displayName = "DocSearchContext";
32298
32335
  function DocSearchInner(_ref, ref) {
32299
- let { children, theme, onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose } = _ref, props = _objectWithoutProperties(_ref, _excluded$1);
32336
+ let { children, appId, apiKey, theme, onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose } = _ref, props = _objectWithoutProperties(_ref, _excluded$2);
32300
32337
  const [docsearchState, setDocsearchState] = En.useState("ready");
32301
32338
  const [initialQuery, setInitialQuery] = En.useState(props.initialQuery || "");
32302
32339
  const searchButtonRef = En.useRef(null);
@@ -32403,6 +32440,8 @@ function DocSearchInner(_ref, ref) {
32403
32440
  keyboardShortcuts
32404
32441
  });
32405
32442
  const value = En.useMemo(() => ({
32443
+ appId,
32444
+ apiKey,
32406
32445
  docsearchState,
32407
32446
  setDocsearchState,
32408
32447
  searchButtonRef,
@@ -32417,6 +32456,8 @@ function DocSearchInner(_ref, ref) {
32417
32456
  registerView,
32418
32457
  isHybridModeSupported
32419
32458
  }), [
32459
+ appId,
32460
+ apiKey,
32420
32461
  docsearchState,
32421
32462
  searchButtonRef,
32422
32463
  initialQuery,
@@ -32443,19 +32484,28 @@ function useDocSearch() {
32443
32484
  //#endregion
32444
32485
  //#region ../docsearch-react/dist/esm/docsearchAi.js
32445
32486
  init_compat();
32446
- function DocSearchAIComponent(props, ref) {
32447
- return /* @__PURE__ */ En.createElement(DocSearch, _objectSpread2$2(_objectSpread2$2({}, props), {}, { ref }), /* @__PURE__ */ En.createElement(DocSearchAIInner, props));
32487
+ const _excluded$1 = ["appId", "apiKey"];
32488
+ function DocSearchAIComponent(_ref, ref) {
32489
+ let { appId, apiKey } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1);
32490
+ return /* @__PURE__ */ En.createElement(DocSearch, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
32491
+ appId,
32492
+ apiKey,
32493
+ ref
32494
+ }), /* @__PURE__ */ En.createElement(DocSearchAIInner, props));
32448
32495
  }
32449
32496
  const DocSearchAI = En.forwardRef(DocSearchAIComponent);
32450
32497
  function DocSearchAIInner(props) {
32451
32498
  var _props$translations, _props$translations2, _props$portalContaine;
32452
- const { searchButtonRef, keyboardShortcuts, isModalActive, isAskAiActive, initialQuery, onAskAiToggle, openModal, closeModal, isHybridModeSupported } = useDocSearch();
32499
+ const { searchButtonRef, keyboardShortcuts, isModalActive, isAskAiActive, initialQuery, onAskAiToggle, openModal, closeModal, isHybridModeSupported, appId, apiKey } = useDocSearch();
32500
+ if (!appId || !apiKey) throw new Error("`DocSearchAI` requires `appId` and `apiKey` props.");
32453
32501
  return /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement(DocSearchButton, {
32454
32502
  keyboardShortcuts,
32455
32503
  ref: searchButtonRef,
32456
32504
  translations: (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
32457
32505
  onClick: openModal
32458
32506
  }), isModalActive && H(/* @__PURE__ */ En.createElement(DocSearchAskAiModal, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
32507
+ appId,
32508
+ apiKey,
32459
32509
  initialScrollY: window.scrollY,
32460
32510
  initialQuery,
32461
32511
  translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,