react-instantsearch 7.35.0 → 7.36.0

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.
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch 7.35.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch 7.36.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
@@ -24,7 +24,7 @@
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- var version$2 = '7.35.0';
27
+ var version$2 = '7.36.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -10821,7 +10821,7 @@
10821
10821
  };
10822
10822
  }
10823
10823
 
10824
- var version = '4.101.0';
10824
+ var version = '4.102.0';
10825
10825
 
10826
10826
  var withUsage$r = createDocumentationMessageGenerator({
10827
10827
  name: 'instantsearch'
@@ -13575,7 +13575,7 @@
13575
13575
  return (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'submitted' || (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'streaming';
13576
13576
  }
13577
13577
 
13578
- var SearchIndexToolType$1 = 'algolia_search_index';
13578
+ var SearchIndexToolType$2 = 'algolia_search_index';
13579
13579
  var RecommendToolType = 'algolia_recommend';
13580
13580
  var MemorizeToolType = 'algolia_memorize';
13581
13581
  var MemorySearchToolType = 'algolia_memory_search';
@@ -13994,8 +13994,8 @@
13994
13994
  sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
13995
13995
  shouldRepairToolInput: function shouldRepairToolInput(toolName) {
13996
13996
  var tool = tools[toolName];
13997
- if (!tool && toolName.startsWith("".concat(SearchIndexToolType$1, "_"))) {
13998
- tool = tools[SearchIndexToolType$1];
13997
+ if (!tool && toolName.startsWith("".concat(SearchIndexToolType$2, "_"))) {
13998
+ tool = tools[SearchIndexToolType$2];
13999
13999
  }
14000
14000
  if (!tool) return true;
14001
14001
  return Boolean(tool.streamInput);
@@ -14004,8 +14004,8 @@
14004
14004
  var toolCall = param.toolCall;
14005
14005
  var tool = tools[toolCall.toolName];
14006
14006
  // Compatibility shim with Algolia MCP Server search tool
14007
- if (!tool && toolCall.toolName.startsWith("".concat(SearchIndexToolType$1, "_"))) {
14008
- tool = tools[SearchIndexToolType$1];
14007
+ if (!tool && toolCall.toolName.startsWith("".concat(SearchIndexToolType$2, "_"))) {
14008
+ tool = tools[SearchIndexToolType$2];
14009
14009
  }
14010
14010
  if (!tool) {
14011
14011
  return _chatInstance.addToolResult({
@@ -19868,6 +19868,8 @@
19868
19868
  return str.slice(0, prefix.length) === prefix;
19869
19869
  }
19870
19870
 
19871
+ // Keep in sync with packages/instantsearch.js/src/lib/chat/index.ts
19872
+ var SearchIndexToolType$1 = 'algolia_search_index';
19871
19873
  var getTextContent = function getTextContent(message) {
19872
19874
  return message.parts.map(function(part) {
19873
19875
  return 'text' in part ? part.text : '';
@@ -19894,6 +19896,117 @@
19894
19896
  }
19895
19897
  return tool;
19896
19898
  };
19899
+ var FACET_KEY_PREFIX = 'facet_';
19900
+ /**
19901
+ * Extracts the `facetFilters` from a search tool input.
19902
+ *
19903
+ * The default search tool provides a ready-to-use `facet_filters` array. The
19904
+ * Algolia MCP Server search tool instead expresses refinements as individual
19905
+ * `facet_<attribute>` keys (e.g. `facet_categories: ['Books', 'Toys']`), which
19906
+ * are converted here into the `[['attribute:value']]` shape `applyFilters`
19907
+ * expects.
19908
+ */ var getFacetFiltersFromToolInput = function getFacetFiltersFromToolInput(input) {
19909
+ if (!input) {
19910
+ return undefined;
19911
+ }
19912
+ if (Array.isArray(input.facet_filters)) {
19913
+ return input.facet_filters;
19914
+ }
19915
+ var facetFilters = Object.entries(input).reduce(function(acc, param) {
19916
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
19917
+ if (!startsWith(key, FACET_KEY_PREFIX) || !Array.isArray(value)) {
19918
+ return acc;
19919
+ }
19920
+ var attribute = key.slice(FACET_KEY_PREFIX.length);
19921
+ var values = value.filter(function(item) {
19922
+ return typeof item === 'string';
19923
+ });
19924
+ if (attribute && values.length > 0) {
19925
+ acc.push(values.map(function(item) {
19926
+ return "".concat(attribute, ":").concat(item);
19927
+ }));
19928
+ }
19929
+ return acc;
19930
+ }, []);
19931
+ return facetFilters.length > 0 ? facetFilters : undefined;
19932
+ };
19933
+ var isSearchToolPart = function isSearchToolPart(part) {
19934
+ return part.type === "tool-".concat(SearchIndexToolType$1) || // Compatibility shim with Algolia MCP Server search tool
19935
+ startsWith(part.type, "tool-".concat(SearchIndexToolType$1, "_"));
19936
+ };
19937
+ var collectHitsFromPart = function collectHitsFromPart(part, hitsByObjectID) {
19938
+ var output = part.state === 'output-available' ? part.output : undefined;
19939
+ var hits = output === null || output === void 0 ? void 0 : output.hits;
19940
+ if (!Array.isArray(hits)) {
19941
+ return;
19942
+ }
19943
+ hits.forEach(function(hit) {
19944
+ if (!hit) {
19945
+ return;
19946
+ }
19947
+ if (typeof hit.objectID === 'string' && hit.objectID !== '') {
19948
+ hitsByObjectID[hit.objectID] = hit;
19949
+ }
19950
+ });
19951
+ };
19952
+ /**
19953
+ * Builds a map of `objectID` -> full record by collecting the hits from search
19954
+ * tool outputs across the conversation.
19955
+ *
19956
+ * The display results tool only receives object IDs from the backend, so it
19957
+ * relies on this map to hydrate each result with the full record that the
19958
+ * preceding search tool already fetched.
19959
+ *
19960
+ * Pass `untilToolCallId` (the display tool's own `toolCallId`) to scope
19961
+ * collection to the turn that produced it: hits are only gathered up to and
19962
+ * including the message that contains that tool call. This prevents a later
19963
+ * turn's search from overwriting an earlier display tool's records (and their
19964
+ * per-query metadata like `__queryID`).
19965
+ */ var getHitsByObjectID = function getHitsByObjectID(messages, untilToolCallId) {
19966
+ var hitsByObjectID = {};
19967
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
19968
+ try {
19969
+ var _loop = function _loop() {
19970
+ var message = _step.value;
19971
+ var reachedBoundary = false;
19972
+ message.parts.forEach(function(part) {
19973
+ if (!isPartTool(part)) {
19974
+ return;
19975
+ }
19976
+ // Note the boundary but keep processing the rest of this message's parts:
19977
+ // the search tool that fed this display tool lives in the same message,
19978
+ // so its hits must still be collected before we stop.
19979
+ if (untilToolCallId && part.toolCallId === untilToolCallId) {
19980
+ reachedBoundary = true;
19981
+ }
19982
+ if (isSearchToolPart(part)) {
19983
+ collectHitsFromPart(part, hitsByObjectID);
19984
+ }
19985
+ });
19986
+ if (reachedBoundary) {
19987
+ return "break";
19988
+ }
19989
+ };
19990
+ for(var _iterator = messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
19991
+ var _ret = _loop();
19992
+ if (_ret === "break") break;
19993
+ }
19994
+ } catch (err) {
19995
+ _didIteratorError = true;
19996
+ _iteratorError = err;
19997
+ } finally{
19998
+ try {
19999
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
20000
+ _iterator.return();
20001
+ }
20002
+ } finally{
20003
+ if (_didIteratorError) {
20004
+ throw _iteratorError;
20005
+ }
20006
+ }
20007
+ }
20008
+ return hitsByObjectID;
20009
+ };
19897
20010
 
19898
20011
  function n(){return n=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t]);}return e},n.apply(this,arguments)}const o=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce((e,n)=>(e[n.toLowerCase()]=n,e),{class:"className",for:"htmlFor"}),a={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},c=["style","script","pre"],i=["src","href","data","formAction","srcDoc","action"],u=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,l=/\n{2,}$/,s=/^(\s*>[\s\S]*?)(?=\n\n|$)/,f=/^ *> ?/gm,_=/^(?:\[!([^\]]*)\]\n)?([\s\S]*)/,d=/^ {2,}\n/,p=/^(?:([-*_])( *\1){2,}) *(?:\n *)+\n/,y=/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/,h=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,g=/^(`+)((?:\\`|(?!\1)`|[^`])+)\1/,m=/^(?:\n *)*\n/,k=/\r\n?/g,x=/^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/,q=/^\[\^([^\]]+)]/,v=/\f/g,b=/^---[ \t]*\n(.|\n)*\n---[ \t]*\n/,$=/^\s*?\[(x|\s)\]/,S=/^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,z=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,E=/^([^\n]+)\n *(=|-)\2{2,} *\n/,A=/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i,R=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,B=/^<!--[\s\S]*?(?:-->)/,L=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,O=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,j=/^\{.*\}$/,C=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,I=/^<([^ >]+[:@\/][^ >]+)>/,T=/-([a-z])?/gi,M=/^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/,w=/^[^\n]+(?: \n|\n{2,})/,D=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,F=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,P=/^\[([^\]]*)\] ?\[([^\]]*)\]/,Z=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,N=/\t/g,G=/(^ *\||\| *$)/g,U=/^ *:-+: *$/,V=/^ *:-+ *$/,H=/^ *-+: *$/,Q=e=>`(?=[\\s\\S]+?\\1${e?"\\1":""})`,W="((?:\\[.*?\\][([].*?[)\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\1|[\\s\\S])+?)",J=RegExp(`^([*_])\\1${Q(1)}${W}\\1\\1(?!\\1)`),K=RegExp(`^([*_])${Q(0)}${W}\\1(?!\\1)`),X=RegExp(`^(==)${Q(0)}${W}\\1`),Y=RegExp(`^(~~)${Q(0)}${W}\\1`),ee=/^(:[a-zA-Z0-9-_]+:)/,ne=/^\\([^0-9A-Za-z\s])/,re=/\\([^0-9A-Za-z\s])/g,te=/^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/,oe=/^\n+/,ae=/^([ \t]*)/,ce=/(?:^|\n)( *)$/,ie="(?:\\d+\\.)",ue="(?:[*+-])";function le(e){return "( *)("+(1===e?ie:ue)+") +"}const se=le(1),fe=le(2);function _e(e){return RegExp("^"+(1===e?se:fe))}const de=_e(1),pe=_e(2);function ye(e){return RegExp("^"+(1===e?se:fe)+"[^\\n]*(?:\\n(?!\\1"+(1===e?ie:ue)+" )[^\\n]*)*(\\n|$)","gm")}const he=ye(1),ge=ye(2);function me(e){const n=1===e?ie:ue;return RegExp("^( *)("+n+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+n+" (?!"+n+" ))\\n*|\\s*\\n*$)")}const ke=me(1),xe=me(2);function qe(e,n){const r=1===n,t=r?ke:xe,o=r?he:ge,a=r?de:pe;return {t:e=>a.test(e),o:je(function(e,n){const r=ce.exec(n.prevCapture);return r&&(n.list||!n.inline&&!n.simple)?t.exec(e=r[1]+e):null}),i:1,u(e,n,t){const c=r?+e[2]:void 0,i=e[0].replace(l,"\n").match(o);let u=!1;return {items:i.map(function(e,r){const o=a.exec(e)[0].length,c=RegExp("^ {1,"+o+"}","gm"),l=e.replace(c,"").replace(a,""),s=r===i.length-1,f=-1!==l.indexOf("\n\n")||s&&u;u=f;const _=t.inline,d=t.list;let p;t.list=!0,f?(t.inline=!1,p=Se(l)+"\n\n"):(t.inline=!0,p=Se(l));const y=n(p,t);return t.inline=_,t.list=d,y}),ordered:r,start:c}},l:(n,r,t)=>e(n.ordered?"ol":"ul",{key:t.key,start:"20"===n.type?n.start:void 0},n.items.map(function(n,o){return e("li",{key:o},r(n,t))}))}}const ve=RegExp("^\\[((?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*)\\]\\(\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),be=/^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;function $e(e){return "string"==typeof e}function Se(e){let n=e.length;for(;n>0&&e[n-1]<=" ";)n--;return e.slice(0,n)}function ze(e,n){return e.startsWith(n)}function Ee(e,n,r){if(Array.isArray(r)){for(let n=0;n<r.length;n++)if(ze(e,r[n]))return !0;return !1}return r(e,n)}function Ae(e){return e.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function Re(e){return H.test(e)?"right":U.test(e)?"center":V.test(e)?"left":null}function Be(e,n,r,t){const o=r.inTable;r.inTable=!0;let a=[[]],c="";function i(){if(!c)return;const e=a[a.length-1];e.push.apply(e,n(c,r)),c="";}return e.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach((e,n,r)=>{"|"===e.trim()&&(i(),t)?0!==n&&n!==r.length-1&&a.push([]):c+=e;}),i(),r.inTable=o,a}function Le(e,n,r){r.inline=!0;const t=e[2]?e[2].replace(G,"").split("|").map(Re):[],o=e[3]?function(e,n,r){return e.trim().split("\n").map(function(e){return Be(e,n,r,!0)})}(e[3],n,r):[],a=Be(e[1],n,r,!!o.length);return r.inline=!1,o.length?{align:t,cells:o,header:a,type:"25"}:{children:a,type:"21"}}function Oe(e,n){return null==e.align[n]?{}:{textAlign:e.align[n]}}function je(e){return e.inline=1,e}function Ce(e){return je(function(n,r){return r.inline?e.exec(n):null})}function Ie(e){return je(function(n,r){return r.inline||r.simple?e.exec(n):null})}function Te(e){return function(n,r){return r.inline||r.simple?null:e.exec(n)}}function Me(e){return je(function(n){return e.exec(n)})}const we=/(javascript|vbscript|data(?!:image)):/i;function De(e){try{const n=decodeURIComponent(e).replace(/[^A-Za-z0-9/:]/g,"");if(we.test(n))return null}catch(e){return null}return e}function Fe(e){return e?e.replace(re,"$1"):e}function Pe(e,n,r){const t=r.inline||!1,o=r.simple||!1;r.inline=!0,r.simple=!0;const a=e(n,r);return r.inline=t,r.simple=o,a}function Ze(e,n,r){const t=r.inline||!1,o=r.simple||!1;r.inline=!1,r.simple=!0;const a=e(n,r);return r.inline=t,r.simple=o,a}function Ne(e,n,r){const t=r.inline||!1;r.inline=!1;const o=e(n,r);return r.inline=t,o}const Ge=(e,n,r)=>({children:Pe(n,e[2],r)});function Ue(){return {}}function Ve(){return null}function He(...e){return e.filter(Boolean).join(" ")}function Qe(e,n,r){let t=e;const o=n.split(".");for(;o.length&&(t=t[o[0]],void 0!==t);)o.shift();return t||r}function We(r="",t={}){t.overrides=t.overrides||{},t.namedCodesToUnicode=t.namedCodesToUnicode?n({},a,t.namedCodesToUnicode):a;const l=t.slugify||Ae,G=t.sanitizer||De,U=t.createElement||React__namespace.createElement,V=[s,y,h,t.enforceAtxHeadings?z:S,E,M,ke,xe],H=[...V,w,A,B,O];function Q(e,n){for(let r=0;r<e.length;r++)if(e[r].test(n))return !0;return !1}function W(e,r,...o){const a=Qe(t.overrides,e+".props",{});return U(function(e,n){const r=Qe(n,e);return r?"function"==typeof r||"object"==typeof r&&"render"in r?r:Qe(n,e+".component",e):e}(e,t.overrides),n({},r,a,{className:He(null==r?void 0:r.className,a.className)||void 0}),...o)}function re(e){e=e.replace(b,"");let n=!1;t.forceInline?n=!0:t.forceBlock||(n=!1===Z.test(e));const r=fe(se(n?e:Se(e).replace(oe,"")+"\n\n",{inline:n}));for(;$e(r[r.length-1])&&!r[r.length-1].trim();)r.pop();if(null===t.wrapper)return r;const o=t.wrapper||(n?"span":"div");let a;if(r.length>1||t.forceWrapper)a=r;else {if(1===r.length)return a=r[0],"string"==typeof a?W("span",{key:"outer"},a):a;a=null;}return U(o,{key:"outer"},a)}function ce(e,n){if(!n||!n.trim())return null;const r=n.match(u);return r?r.reduce(function(n,r){const t=r.indexOf("=");if(-1!==t){const a=function(e){return -1!==e.indexOf("-")&&null===e.match(L)&&(e=e.replace(T,function(e,n){return n.toUpperCase()})),e}(r.slice(0,t)).trim(),c=function(e){const n=e[0];return ('"'===n||"'"===n)&&e.length>=2&&e[e.length-1]===n?e.slice(1,-1):e}(r.slice(t+1).trim()),u=o[a]||a;if("ref"===u)return n;const l=n[u]=function(e,n,r,t){return "style"===n?function(e){const n=[];let r="",t=!1,o=!1,a="";if(!e)return n;for(let c=0;c<e.length;c++){const i=e[c];if('"'!==i&&"'"!==i||t||(o?i===a&&(o=!1,a=""):(o=!0,a=i)),"("===i&&r.endsWith("url")?t=!0:")"===i&&t&&(t=!1),";"!==i||o||t)r+=i;else {const e=r.trim();if(e){const r=e.indexOf(":");if(r>0){const t=e.slice(0,r).trim(),o=e.slice(r+1).trim();n.push([t,o]);}}r="";}}const c=r.trim();if(c){const e=c.indexOf(":");if(e>0){const r=c.slice(0,e).trim(),t=c.slice(e+1).trim();n.push([r,t]);}}return n}(r).reduce(function(n,[r,o]){return n[r.replace(/(-[a-z])/g,e=>e[1].toUpperCase())]=t(o,e,r),n},{}):-1!==i.indexOf(n)?t(Fe(r),e,n):(r.match(j)&&(r=Fe(r.slice(1,r.length-1))),"true"===r||"false"!==r&&r)}(e,a,c,G);"string"==typeof l&&(A.test(l)||O.test(l))&&(n[u]=re(l.trim()));}else "style"!==r&&(n[o[r]||r]=!0);return n},{}):null}const ie=[],ue={},le={0:{t:[">"],o:Te(s),i:1,u(e,n,r){const[,t,o]=e[0].replace(f,"").match(_);return {alert:t,children:n(o,r)}},l(e,n,r){const t={key:r.key};return e.alert&&(t.className="markdown-alert-"+l(e.alert.toLowerCase(),Ae),e.children.unshift({attrs:{},children:[{type:"27",text:e.alert}],noInnerParse:!0,type:"11",tag:"header"})),W("blockquote",t,n(e.children,r))}},1:{t:[" "],o:Me(d),i:1,u:Ue,l:(e,n,r)=>W("br",{key:r.key})},2:{t:["--","__","**","- ","* ","_ "],o:Te(p),i:1,u:Ue,l:(e,n,r)=>W("hr",{key:r.key})},3:{t:[" "],o:Te(h),i:0,u:e=>({lang:void 0,text:Fe(Se(e[0].replace(/^ {4}/gm,"")))}),l:(e,r,t)=>W("pre",{key:t.key},W("code",n({},e.attrs,{className:e.lang?"lang-"+e.lang:""}),e.text))},4:{t:["```","~~~"],o:Te(y),i:0,u:e=>({attrs:ce("code",e[3]||""),lang:e[2]||void 0,text:e[4],type:"3"})},5:{t:["`"],o:Ie(g),i:3,u:e=>({text:Fe(e[2])}),l:(e,n,r)=>W("code",{key:r.key},e.text)},6:{t:["[^"],o:Te(x),i:0,u:e=>(ie.push({footnote:e[2],identifier:e[1]}),{}),l:Ve},7:{t:["[^"],o:Ce(q),i:1,u:e=>({target:"#"+l(e[1],Ae),text:e[1]}),l:(e,n,r)=>W("a",{key:r.key,href:G(e.target,"a","href")},W("sup",{key:r.key},e.text))},8:{t:["[ ]","[x]"],o:Ce($),i:1,u:e=>({completed:"x"===e[1].toLowerCase()}),l:(e,n,r)=>W("input",{checked:e.completed,key:r.key,readOnly:!0,type:"checkbox"})},9:{t:["#"],o:Te(t.enforceAtxHeadings?z:S),i:1,u:(e,n,r)=>({children:Pe(n,e[2],r),id:l(e[2],Ae),level:e[1].length}),l:(e,n,r)=>W("h"+e.level,{id:e.id,key:r.key},n(e.children,r))},10:{t:e=>{const n=e.indexOf("\n");return n>0&&n<e.length-1&&("="===e[n+1]||"-"===e[n+1])},o:Te(E),i:0,u:(e,n,r)=>({children:Pe(n,e[1],r),level:"="===e[2]?1:2,type:"9"})},11:{t:["<"],o:Me(A),i:1,u(e,n,r){const[,t]=e[3].match(ae),o=RegExp("^"+t,"gm"),a=e[3].replace(o,""),i=Q(H,a)?Ne:Pe,u=e[1].toLowerCase(),l=-1!==c.indexOf(u),s=(l?u:e[1]).trim(),f={attrs:ce(s,e[2]),noInnerParse:l,tag:s};if(r.inAnchor=r.inAnchor||"a"===u,l)f.text=e[3];else {const e=r.inHTML;r.inHTML=!0,f.children=i(n,a,r),r.inHTML=e;}return r.inAnchor=!1,f},l:(e,r,t)=>W(e.tag,n({key:t.key},e.attrs),e.text||(e.children?r(e.children,t):""))},13:{t:["<"],o:Me(O),i:1,u(e){const n=e[1].trim();return {attrs:ce(n,e[2]||""),tag:n}},l:(e,r,t)=>W(e.tag,n({},e.attrs,{key:t.key}))},12:{t:["\x3c!--"],o:Me(B),i:1,u:()=>({}),l:Ve},14:{t:["!["],o:Ie(be),i:1,u:e=>({alt:Fe(e[1]),target:Fe(e[2]),title:Fe(e[3])}),l:(e,n,r)=>W("img",{key:r.key,alt:e.alt||void 0,title:e.title||void 0,src:G(e.target,"img","src")})},15:{t:["["],o:Ce(ve),i:3,u:(e,n,r)=>({children:Ze(n,e[1],r),target:Fe(e[2]),title:Fe(e[3])}),l:(e,n,r)=>W("a",{key:r.key,href:G(e.target,"a","href"),title:e.title},n(e.children,r))},16:{t:["<"],o:Ce(I),i:0,u(e){let n=e[1],r=!1;return -1!==n.indexOf("@")&&-1===n.indexOf("//")&&(r=!0,n=n.replace("mailto:","")),{children:[{text:n,type:"27"}],target:r?"mailto:"+n:n,type:"15"}}},17:{t:(e,n)=>!n.inAnchor&&!t.disableAutoLink&&(ze(e,"http://")||ze(e,"https://")),o:Ce(C),i:0,u:e=>({children:[{text:e[1],type:"27"}],target:e[1],title:void 0,type:"15"})},20:qe(W,1),33:qe(W,2),19:{t:["\n"],o:Te(m),i:3,u:Ue,l:()=>"\n"},21:{o:je(function(e,n){if(n.inline||n.simple||n.inHTML&&-1===e.indexOf("\n\n")&&-1===n.prevCapture.indexOf("\n\n"))return null;let r="",t=0;for(;;){const n=e.indexOf("\n",t),o=e.slice(t,-1===n?void 0:n+1);if(Q(V,o))break;if(r+=o,-1===n||!o.trim())break;t=n+1;}const o=Se(r);return ""===o?null:[r,,o]}),i:3,u:Ge,l:(e,n,r)=>W("p",{key:r.key},n(e.children,r))},22:{t:["["],o:Ce(D),i:0,u:e=>(ue[e[1]]={target:e[2],title:e[4]},{}),l:Ve},23:{t:["!["],o:Ie(F),i:0,u:e=>({alt:e[1]?Fe(e[1]):void 0,ref:e[2]}),l:(e,n,r)=>ue[e.ref]?W("img",{key:r.key,alt:e.alt,src:G(ue[e.ref].target,"img","src"),title:ue[e.ref].title}):null},24:{t:e=>"["===e[0]&&-1===e.indexOf("]("),o:Ce(P),i:0,u:(e,n,r)=>({children:n(e[1],r),fallbackChildren:e[0],ref:e[2]}),l:(e,n,r)=>ue[e.ref]?W("a",{key:r.key,href:G(ue[e.ref].target,"a","href"),title:ue[e.ref].title},n(e.children,r)):W("span",{key:r.key},e.fallbackChildren)},25:{t:["|"],o:Te(M),i:1,u:Le,l(e,n,r){const t=e;return W("table",{key:r.key},W("thead",null,W("tr",null,t.header.map(function(e,o){return W("th",{key:o,style:Oe(t,o)},n(e,r))}))),W("tbody",null,t.cells.map(function(e,o){return W("tr",{key:o},e.map(function(e,o){return W("td",{key:o,style:Oe(t,o)},n(e,r))}))})))}},27:{o:je(function(e,n){let r;return ze(e,":")&&(r=ee.exec(e)),r||te.exec(e)}),i:4,u(e){const n=e[0];return {text:-1===n.indexOf("&")?n:n.replace(R,(e,n)=>t.namedCodesToUnicode[n]||e)}},l:e=>e.text},28:{t:["**","__"],o:Ie(J),i:2,u:(e,n,r)=>({children:n(e[2],r)}),l:(e,n,r)=>W("strong",{key:r.key},n(e.children,r))},29:{t:e=>{const n=e[0];return ("*"===n||"_"===n)&&e[1]!==n},o:Ie(K),i:3,u:(e,n,r)=>({children:n(e[2],r)}),l:(e,n,r)=>W("em",{key:r.key},n(e.children,r))},30:{t:["\\"],o:Ie(ne),i:1,u:e=>({text:e[1],type:"27"})},31:{t:["=="],o:Ie(X),i:3,u:Ge,l:(e,n,r)=>W("mark",{key:r.key},n(e.children,r))},32:{t:["~~"],o:Ie(Y),i:3,u:Ge,l:(e,n,r)=>W("del",{key:r.key},n(e.children,r))}};!0===t.disableParsingRawHTML&&(delete le[11],delete le[13]);const se=function(e){var n=Object.keys(e);function r(t,o){var a=[];if(o.prevCapture=o.prevCapture||"",t.trim())for(;t;)for(var c=0;c<n.length;){var i=n[c],u=e[i];if(!u.t||Ee(t,o,u.t)){var l=u.o(t,o);if(l&&l[0]){t=t.substring(l[0].length);var s=u.u(l,r,o);o.prevCapture+=l[0],s.type||(s.type=i),a.push(s);break}c++;}else c++;}return o.prevCapture="",a}return n.sort(function(n,r){return e[n].i-e[r].i||(n<r?-1:1)}),function(e,n){return r(function(e){return e.replace(k,"\n").replace(v,"").replace(N," ")}(e),n)}}(le),fe=function(e,n){return function r(t,o={}){if(Array.isArray(t)){const e=o.key,n=[];let a=!1;for(let e=0;e<t.length;e++){o.key=e;const c=r(t[e],o),i=$e(c);i&&a?n[n.length-1]+=c:null!==c&&n.push(c),a=i;}return o.key=e,n}return function(r,t,o){const a=e[r.type].l;return n?n(()=>a(r,t,o),r,t,o):a(r,t,o)}(t,r,o)}}(le,t.renderRule),_e=re(r);return ie.length?W("div",null,_e,W("footer",{key:"footer"},ie.map(function(e){return W("div",{id:l(e.identifier,Ae),key:e.identifier},e.identifier,fe(se(e.footnote,{inline:!0})))}))):_e}
19899
20012
 
@@ -19905,7 +20018,7 @@
19905
20018
  createElement: createElement
19906
20019
  });
19907
20020
  return function ChatMessage(userProps) {
19908
- var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, status = userProps.status, _userProps_side = userProps.side, side = _userProps_side === void 0 ? 'left' : _userProps_side, _userProps_variant = userProps.variant, variant = _userProps_variant === void 0 ? 'subtle' : _userProps_variant, _userProps_actions = userProps.actions, actions = _userProps_actions === void 0 ? [] : _userProps_actions, _userProps_autoHideActions = userProps.autoHideActions, autoHideActions = _userProps_autoHideActions === void 0 ? false : _userProps_autoHideActions, LeadingComponent = userProps.leadingComponent, ActionsComponent = userProps.actionsComponent, FooterComponent = userProps.footerComponent, _userProps_tools = userProps.tools, tools = _userProps_tools === void 0 ? {} : _userProps_tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, onClose = userProps.onClose, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, props = _object_without_properties(userProps, [
20021
+ var _userProps_classNames = userProps.classNames, classNames = _userProps_classNames === void 0 ? {} : _userProps_classNames, message = userProps.message, status = userProps.status, _userProps_side = userProps.side, side = _userProps_side === void 0 ? 'left' : _userProps_side, _userProps_variant = userProps.variant, variant = _userProps_variant === void 0 ? 'subtle' : _userProps_variant, _userProps_actions = userProps.actions, actions = _userProps_actions === void 0 ? [] : _userProps_actions, _userProps_autoHideActions = userProps.autoHideActions, autoHideActions = _userProps_autoHideActions === void 0 ? false : _userProps_autoHideActions, LeadingComponent = userProps.leadingComponent, ActionsComponent = userProps.actionsComponent, FooterComponent = userProps.footerComponent, _userProps_tools = userProps.tools, tools = _userProps_tools === void 0 ? {} : _userProps_tools, indexUiState = userProps.indexUiState, setIndexUiState = userProps.setIndexUiState, messages = userProps.messages, onClose = userProps.onClose, userTranslations = userProps.translations, suggestionsElement = userProps.suggestionsElement, _userProps_parseMarkdown = userProps.parseMarkdown, parseMarkdown = _userProps_parseMarkdown === void 0 ? true : _userProps_parseMarkdown, props = _object_without_properties(userProps, [
19909
20022
  "classNames",
19910
20023
  "message",
19911
20024
  "status",
@@ -19919,9 +20032,11 @@
19919
20032
  "tools",
19920
20033
  "indexUiState",
19921
20034
  "setIndexUiState",
20035
+ "messages",
19922
20036
  "onClose",
19923
20037
  "translations",
19924
- "suggestionsElement"
20038
+ "suggestionsElement",
20039
+ "parseMarkdown"
19925
20040
  ]);
19926
20041
  var translations = _object_spread({
19927
20042
  messageLabel: 'Message',
@@ -19950,6 +20065,18 @@
19950
20065
  if (part.text.startsWith('<context>') && part.text.endsWith('</context>')) {
19951
20066
  return null;
19952
20067
  }
20068
+ if (!parseMarkdown) {
20069
+ // Render the literal text. The `ais-ChatMessage-text` class applies
20070
+ // `white-space: pre-wrap` to preserve the newlines that markdown
20071
+ // would otherwise collapse, and streaming deltas append cleanly
20072
+ // because there's no parser state to get into a half-parsed entity.
20073
+ // Wrapped in a `<p>` to keep some structure for screen readers
20074
+ // (markdown produces semantic elements; a bare text node would not).
20075
+ return /*#__PURE__*/ createElement("p", {
20076
+ key: "".concat(message.id, "-").concat(index),
20077
+ className: "ais-ChatMessage-text"
20078
+ }, part.text);
20079
+ }
19953
20080
  var markdown = We(part.text, {
19954
20081
  createElement: createElement,
19955
20082
  disableParsingRawHTML: true
@@ -19994,6 +20121,7 @@
19994
20121
  message: toolMessage,
19995
20122
  indexUiState: indexUiState,
19996
20123
  setIndexUiState: setIndexUiState,
20124
+ messages: messages,
19997
20125
  addToolResult: boundAddToolResult,
19998
20126
  applyFilters: tool.applyFilters,
19999
20127
  sendEvent: tool.sendEvent || function() {},
@@ -20148,6 +20276,20 @@
20148
20276
  var copyToClipboard = function copyToClipboard(message) {
20149
20277
  navigator.clipboard.writeText(getTextContent(message));
20150
20278
  };
20279
+ /**
20280
+ * Memoization comparator for a message row. `replaceMessage` only clones the
20281
+ * message being updated, so completed messages keep a stable reference across
20282
+ * streaming deltas. We compare just what affects a row's render — `message`,
20283
+ * `status`, `suggestionsElement`, and this message's feedback — and ignore the
20284
+ * props that get a fresh reference every render but don't change the output
20285
+ * (`tools`, `messages`, callbacks, `indexUiState`). `indexUiState` in
20286
+ * particular can't be compared: `getUiState()` returns a new object each render
20287
+ * and would defeat the memo. Trade-off: a completed row keeps the callbacks/
20288
+ * `indexUiState` it last rendered with until its next genuine render.
20289
+ */ function areMessagePropsEqual(prev, next) {
20290
+ var _prev_feedbackState, _next_feedbackState;
20291
+ return prev.message === next.message && prev.status === next.status && prev.suggestionsElement === next.suggestionsElement && ((_prev_feedbackState = prev.feedbackState) === null || _prev_feedbackState === void 0 ? void 0 : _prev_feedbackState[prev.message.id]) === ((_next_feedbackState = next.feedbackState) === null || _next_feedbackState === void 0 ? void 0 : _next_feedbackState[next.message.id]);
20292
+ }
20151
20293
  function createDefaultMessageComponent(param) {
20152
20294
  var createElement = param.createElement, Fragment = param.Fragment;
20153
20295
  var ChatMessage = createChatMessageComponent({
@@ -20155,7 +20297,7 @@
20155
20297
  Fragment: Fragment
20156
20298
  });
20157
20299
  return function DefaultMessage(param) {
20158
- var message = param.message, status = param.status, userMessageProps = param.userMessageProps, assistantMessageProps = param.assistantMessageProps, tools = param.tools, indexUiState = param.indexUiState, setIndexUiState = param.setIndexUiState, onReload = param.onReload, onClose = param.onClose, onFeedback = param.onFeedback, feedbackState = param.feedbackState, actionsComponent = param.actionsComponent, classNames = param.classNames, messageTranslations = param.messageTranslations, translations = param.translations, suggestionsElement = param.suggestionsElement;
20300
+ var message = param.message, status = param.status, userMessageProps = param.userMessageProps, assistantMessageProps = param.assistantMessageProps, tools = param.tools, indexUiState = param.indexUiState, setIndexUiState = param.setIndexUiState, messages = param.messages, onReload = param.onReload, onClose = param.onClose, onFeedback = param.onFeedback, feedbackState = param.feedbackState, actionsComponent = param.actionsComponent, classNames = param.classNames, messageTranslations = param.messageTranslations, translations = param.translations, suggestionsElement = param.suggestionsElement;
20159
20301
  var defaultAssistantActions = _to_consumable_array(hasTextContent(message) ? [
20160
20302
  {
20161
20303
  title: translations.copyToClipboardLabel,
@@ -20243,6 +20385,7 @@
20243
20385
  tools: tools,
20244
20386
  indexUiState: indexUiState,
20245
20387
  setIndexUiState: setIndexUiState,
20388
+ messages: messages,
20246
20389
  onClose: onClose,
20247
20390
  actions: defaultActions,
20248
20391
  actionsComponent: actionsComponent,
@@ -20254,7 +20397,7 @@
20254
20397
  };
20255
20398
  }
20256
20399
  function createChatMessagesComponent(param) {
20257
- var createElement = param.createElement, Fragment = param.Fragment;
20400
+ var createElement = param.createElement, Fragment = param.Fragment, memo = param.memo;
20258
20401
  var Button = createButtonComponent({
20259
20402
  createElement: createElement
20260
20403
  });
@@ -20262,6 +20405,10 @@
20262
20405
  createElement: createElement,
20263
20406
  Fragment: Fragment
20264
20407
  });
20408
+ // Skip re-rendering (and re-compiling the markdown of) completed messages on
20409
+ // every streaming delta. Falls back to the plain component when the host
20410
+ // renderer doesn't provide a `memo` HOC.
20411
+ var MemoizedDefaultMessage = memo ? memo(DefaultMessageComponent, areMessagePropsEqual) : DefaultMessageComponent;
20265
20412
  var DefaultLoaderComponent = createChatMessageLoaderComponent({
20266
20413
  createElement: createElement
20267
20414
  });
@@ -20324,7 +20471,7 @@
20324
20471
  var lastPart = lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage_parts = lastMessage.parts) === null || _lastMessage_parts === void 0 ? void 0 : _lastMessage_parts[lastMessage.parts.length - 1];
20325
20472
  var showLoader = getShowLoader(status, lastPart, tools);
20326
20473
  var showEmpty = messages.length === 0 && !showLoader && !isClearing && status !== 'error';
20327
- var DefaultMessage = MessageComponent || DefaultMessageComponent;
20474
+ var DefaultMessage = MessageComponent || MemoizedDefaultMessage;
20328
20475
  var DefaultLoader = LoaderComponent || DefaultLoaderComponent;
20329
20476
  var DefaultError = ErrorComponent || DefaultErrorComponent;
20330
20477
  return /*#__PURE__*/ createElement("div", _object_spread_props(_object_spread({}, props), {
@@ -20357,6 +20504,7 @@
20357
20504
  tools: tools,
20358
20505
  indexUiState: indexUiState,
20359
20506
  setIndexUiState: setIndexUiState,
20507
+ messages: messages,
20360
20508
  onReload: onReload,
20361
20509
  onFeedback: onFeedback,
20362
20510
  feedbackState: feedbackState,
@@ -20638,14 +20786,15 @@
20638
20786
  }
20639
20787
 
20640
20788
  function createChatComponent(param) {
20641
- var createElement = param.createElement, Fragment = param.Fragment;
20789
+ var createElement = param.createElement, Fragment = param.Fragment, memo = param.memo;
20642
20790
  var ChatHeader = createChatHeaderComponent({
20643
20791
  createElement: createElement,
20644
20792
  Fragment: Fragment
20645
20793
  });
20646
20794
  var ChatMessages = createChatMessagesComponent({
20647
20795
  createElement: createElement,
20648
- Fragment: Fragment
20796
+ Fragment: Fragment,
20797
+ memo: memo
20649
20798
  });
20650
20799
  var ChatPrompt = createChatPromptComponent({
20651
20800
  createElement: createElement,
@@ -20896,11 +21045,18 @@
20896
21045
  streamingLabel: 'Curating results…'
20897
21046
  };
20898
21047
  function createDisplayResultsToolComponent(param) {
20899
- var createElement = param.createElement, Fragment = param.Fragment;
21048
+ var createElement = param.createElement, Fragment = param.Fragment, useMemo = param.useMemo;
20900
21049
  return function DisplayResultsTool(userProps) {
20901
- var toolProps = userProps.toolProps, GroupCarousel = userProps.groupCarouselComponent, userTranslations = userProps.translations;
20902
- var message = toolProps.message, sendEvent = toolProps.sendEvent;
21050
+ var toolProps = userProps.toolProps, renderGroupCarousel = userProps.groupCarouselComponent, userTranslations = userProps.translations;
21051
+ var message = toolProps.message, messages = toolProps.messages, sendEvent = toolProps.sendEvent;
20903
21052
  var translations = _object_spread({}, DEFAULT_TRANSLATIONS$1, userTranslations);
21053
+ var toolCallId = message === null || message === void 0 ? void 0 : message.toolCallId;
21054
+ var hitsByObjectID = useMemo(function() {
21055
+ return messages ? getHitsByObjectID(messages, toolCallId) : undefined;
21056
+ }, [
21057
+ messages,
21058
+ toolCallId
21059
+ ]);
20904
21060
  var output = message === null || message === void 0 ? void 0 : message.output;
20905
21061
  var intro = typeof (output === null || output === void 0 ? void 0 : output.intro) === 'string' ? output.intro : undefined;
20906
21062
  var groups = Array.isArray(output === null || output === void 0 ? void 0 : output.groups) ? output.groups : [];
@@ -20918,8 +21074,11 @@
20918
21074
  }) : [];
20919
21075
  if (results.length === 0) return null;
20920
21076
  var items = results.map(function(result, idx) {
20921
- return _object_spread_props(_object_spread({}, result), {
20922
- __position: idx + 1
21077
+ var hydrated = hitsByObjectID === null || hitsByObjectID === void 0 ? void 0 : hitsByObjectID[result.objectID];
21078
+ return _object_spread_props(_object_spread({}, hydrated), {
21079
+ objectID: result.objectID,
21080
+ __position: idx + 1,
21081
+ __displayToolResult: result
20923
21082
  });
20924
21083
  });
20925
21084
  return /*#__PURE__*/ createElement("div", {
@@ -20929,7 +21088,7 @@
20929
21088
  className: "ais-ChatToolDisplayResults-groupTitle"
20930
21089
  }, group.title), group.why && /*#__PURE__*/ createElement("div", {
20931
21090
  className: "ais-ChatToolDisplayResults-groupWhy"
20932
- }, group.why), /*#__PURE__*/ createElement(GroupCarousel, {
21091
+ }, group.why), renderGroupCarousel({
20933
21092
  items: items,
20934
21093
  sendEvent: sendEvent
20935
21094
  }));
@@ -22111,6 +22270,13 @@
22111
22270
  Fragment: React.Fragment
22112
22271
  });
22113
22272
  var id = 0;
22273
+ var useAutocompleteInstanceId = React.useId ? function() {
22274
+ return React.useId().replace(/:/g, '');
22275
+ } : function() {
22276
+ return React.useState(function() {
22277
+ return "a".concat(id++);
22278
+ })[0];
22279
+ };
22114
22280
  var usePropGetters = createAutocompletePropGetters({
22115
22281
  useEffect: React.useEffect,
22116
22282
  useId: React.useId || function() {
@@ -22246,91 +22412,182 @@
22246
22412
  setIsModalOpen: setIsModalOpen
22247
22413
  };
22248
22414
  }
22249
- function EXPERIMENTAL_Autocomplete(_0) {
22250
- var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, aiMode = _0.aiMode, props = _object_without_properties(_0, [
22251
- "indices",
22415
+ function EXPERIMENTAL_Autocomplete(props) {
22416
+ var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
22417
+ var indices = 'indices' in props ? props.indices : undefined;
22418
+ var feeds = 'feeds' in props ? props.feeds : undefined;
22419
+ var isFeedsMode = feeds !== undefined;
22420
+ var showQuerySuggestions = props.showQuerySuggestions, showPromptSuggestions = props.showPromptSuggestions, showRecent = props.showRecent, userSearchParameters = props.searchParameters, detachedMediaQuery = props.detachedMediaQuery, tmp = props.translations, userTranslations = tmp === void 0 ? {} : tmp, transformItems = props.transformItems, restProps = _object_without_properties(props, [
22252
22421
  "showQuerySuggestions",
22253
22422
  "showPromptSuggestions",
22254
22423
  "showRecent",
22255
22424
  "searchParameters",
22256
22425
  "detachedMediaQuery",
22257
22426
  "translations",
22258
- "aiMode"
22427
+ "transformItems"
22259
22428
  ]);
22260
- var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
22261
22429
  var translations = _object_spread({}, DEFAULT_TRANSLATIONS, userTranslations);
22262
22430
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
22431
+ var compositionID = useInstantSearchContext().compositionID;
22263
22432
  var refine = useSearchBox({}, _object_spread({
22264
22433
  $$type: 'ais.autocomplete',
22265
22434
  $$widgetType: 'ais.autocomplete'
22266
- }, aiMode ? {
22435
+ }, props.aiMode ? {
22267
22436
  opensChat: true
22268
22437
  } : {})).refine;
22438
+ // In feeds-mode, indexId disambiguates multiple Autocomplete instances
22439
+ // sharing the same compositionID. Mirrors the fallback at line 111 for React <18.
22440
+ var instanceKey = useAutocompleteInstanceId();
22441
+ if (isFeedsMode && indices !== undefined) {
22442
+ throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
22443
+ }
22444
+ if (isFeedsMode && !compositionID) {
22445
+ throw new Error('EXPERIMENTAL_Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
22446
+ }
22269
22447
  var isSearchStalled = status === 'stalled';
22270
22448
  var searchParameters = _object_spread({
22271
22449
  hitsPerPage: 5
22272
22450
  }, userSearchParameters);
22273
- var indicesConfig = _to_consumable_array(indices);
22274
- if (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName) {
22275
- var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
22276
- indicesConfig.unshift({
22277
- indexName: showQuerySuggestions.indexName,
22278
- headerComponent: showQuerySuggestions.headerComponent,
22279
- itemComponent: showQuerySuggestions.itemComponent || function(param) {
22280
- var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
22281
- return /*#__PURE__*/ React.createElement(AutocompleteSuggestion, {
22282
- item: item,
22283
- onSelect: onSelect,
22284
- onApply: onApply
22285
- }, /*#__PURE__*/ React.createElement(ConditionalReverseHighlight, {
22286
- item: item
22287
- }));
22288
- },
22289
- classNames: {
22290
- root: cx('ais-AutocompleteSuggestions', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames === void 0 ? void 0 : _showQuerySuggestions_classNames.root),
22291
- list: cx('ais-AutocompleteSuggestionsList', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames1 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames1 === void 0 ? void 0 : _showQuerySuggestions_classNames1.list),
22292
- header: cx('ais-AutocompleteSuggestionsHeader', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames2 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames2 === void 0 ? void 0 : _showQuerySuggestions_classNames2.header),
22293
- item: cx('ais-AutocompleteSuggestionsItem', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames3 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames3 === void 0 ? void 0 : _showQuerySuggestions_classNames3.item)
22294
- },
22295
- searchParameters: _object_spread({
22451
+ // In feeds-mode `indexName` carries the feedID so downstream matching
22452
+ // (section building, dedupe in createAutocompleteStorage) treats feeds
22453
+ // like indices without any changes to InnerAutocomplete.
22454
+ var querySuggestionsKey = isFeedsMode ? showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.feedID : showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName;
22455
+ var promptSuggestionsKey = isFeedsMode ? showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.feedID : showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName;
22456
+ var indicesConfig = React.useMemo(function() {
22457
+ var config = isFeedsMode ? feeds.map(function(feed) {
22458
+ return {
22459
+ indexName: feed.feedID,
22460
+ headerComponent: feed.headerComponent,
22461
+ itemComponent: feed.itemComponent,
22462
+ noResultsComponent: feed.noResultsComponent,
22463
+ getURL: feed.getURL,
22464
+ getQuery: feed.getQuery,
22465
+ classNames: feed.classNames
22466
+ };
22467
+ }) : _to_consumable_array(indices !== null && indices !== void 0 ? indices : []);
22468
+ if (querySuggestionsKey) {
22469
+ var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
22470
+ var querySuggestionsSearchParameters = isFeedsMode ? undefined : _object_spread({
22296
22471
  hitsPerPage: 3
22297
- }, showQuerySuggestions.searchParameters),
22298
- getQuery: function getQuery(item) {
22299
- return item.query;
22300
- },
22301
- getURL: showQuerySuggestions.getURL
22302
- });
22303
- }
22304
- if (showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : showPromptSuggestions.indexName) {
22305
- var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
22306
- indicesConfig.push({
22307
- indexName: showPromptSuggestions.indexName,
22308
- headerComponent: showPromptSuggestions.headerComponent,
22309
- itemComponent: showPromptSuggestions.itemComponent || function(param) {
22310
- var item = param.item, onSelect = param.onSelect;
22311
- return /*#__PURE__*/ React.createElement(AutocompletePromptSuggestion, {
22312
- item: item,
22313
- onSelect: onSelect
22314
- }, /*#__PURE__*/ React.createElement(ConditionalHighlight, {
22315
- item: item,
22316
- attribute: "prompt"
22317
- }));
22318
- },
22319
- classNames: {
22320
- root: cx('ais-AutocompletePromptSuggestions', (_showPromptSuggestions_classNames = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames === void 0 ? void 0 : _showPromptSuggestions_classNames.root),
22321
- list: cx('ais-AutocompletePromptSuggestionsList', (_showPromptSuggestions_classNames1 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames1 === void 0 ? void 0 : _showPromptSuggestions_classNames1.list),
22322
- header: cx('ais-AutocompletePromptSuggestionsHeader', (_showPromptSuggestions_classNames2 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames2 === void 0 ? void 0 : _showPromptSuggestions_classNames2.header),
22323
- item: cx('ais-AutocompletePromptSuggestionsItem', (_showPromptSuggestions_classNames3 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames3 === void 0 ? void 0 : _showPromptSuggestions_classNames3.item)
22324
- },
22325
- searchParameters: _object_spread({
22472
+ }, showQuerySuggestions.searchParameters);
22473
+ config.unshift({
22474
+ indexName: querySuggestionsKey,
22475
+ headerComponent: showQuerySuggestions.headerComponent,
22476
+ itemComponent: showQuerySuggestions.itemComponent || function(param) {
22477
+ var item = param.item, onSelect = param.onSelect, onApply = param.onApply;
22478
+ return /*#__PURE__*/ React.createElement(AutocompleteSuggestion, {
22479
+ item: item,
22480
+ onSelect: onSelect,
22481
+ onApply: onApply
22482
+ }, /*#__PURE__*/ React.createElement(ConditionalReverseHighlight, {
22483
+ item: item
22484
+ }));
22485
+ },
22486
+ classNames: {
22487
+ root: cx('ais-AutocompleteSuggestions', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames === void 0 ? void 0 : _showQuerySuggestions_classNames.root),
22488
+ list: cx('ais-AutocompleteSuggestionsList', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames1 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames1 === void 0 ? void 0 : _showQuerySuggestions_classNames1.list),
22489
+ header: cx('ais-AutocompleteSuggestionsHeader', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames2 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames2 === void 0 ? void 0 : _showQuerySuggestions_classNames2.header),
22490
+ item: cx('ais-AutocompleteSuggestionsItem', showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : (_showQuerySuggestions_classNames3 = showQuerySuggestions.classNames) === null || _showQuerySuggestions_classNames3 === void 0 ? void 0 : _showQuerySuggestions_classNames3.item)
22491
+ },
22492
+ searchParameters: querySuggestionsSearchParameters,
22493
+ getQuery: function getQuery(item) {
22494
+ return item.query;
22495
+ },
22496
+ getURL: showQuerySuggestions.getURL
22497
+ });
22498
+ }
22499
+ if (promptSuggestionsKey) {
22500
+ var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
22501
+ var promptSuggestionsSearchParameters = isFeedsMode ? undefined : _object_spread({
22326
22502
  hitsPerPage: 3
22327
- }, showPromptSuggestions.searchParameters),
22328
- getQuery: function getQuery(item) {
22329
- return item.prompt;
22330
- },
22331
- getURL: showPromptSuggestions.getURL
22332
- });
22333
- }
22503
+ }, showPromptSuggestions.searchParameters);
22504
+ config.push({
22505
+ indexName: promptSuggestionsKey,
22506
+ headerComponent: showPromptSuggestions.headerComponent,
22507
+ itemComponent: showPromptSuggestions.itemComponent || function(param) {
22508
+ var item = param.item, onSelect = param.onSelect;
22509
+ return /*#__PURE__*/ React.createElement(AutocompletePromptSuggestion, {
22510
+ item: item,
22511
+ onSelect: onSelect
22512
+ }, /*#__PURE__*/ React.createElement(ConditionalHighlight, {
22513
+ item: item,
22514
+ attribute: "prompt"
22515
+ }));
22516
+ },
22517
+ classNames: {
22518
+ root: cx('ais-AutocompletePromptSuggestions', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames === void 0 ? void 0 : _showPromptSuggestions_classNames.root),
22519
+ list: cx('ais-AutocompletePromptSuggestionsList', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames1 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames1 === void 0 ? void 0 : _showPromptSuggestions_classNames1.list),
22520
+ header: cx('ais-AutocompletePromptSuggestionsHeader', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames2 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames2 === void 0 ? void 0 : _showPromptSuggestions_classNames2.header),
22521
+ item: cx('ais-AutocompletePromptSuggestionsItem', showPromptSuggestions === null || showPromptSuggestions === void 0 ? void 0 : (_showPromptSuggestions_classNames3 = showPromptSuggestions.classNames) === null || _showPromptSuggestions_classNames3 === void 0 ? void 0 : _showPromptSuggestions_classNames3.item)
22522
+ },
22523
+ searchParameters: promptSuggestionsSearchParameters,
22524
+ getQuery: function getQuery(item) {
22525
+ return item.prompt;
22526
+ },
22527
+ getURL: showPromptSuggestions.getURL
22528
+ });
22529
+ }
22530
+ return config;
22531
+ }, [
22532
+ feeds,
22533
+ indices,
22534
+ isFeedsMode,
22535
+ promptSuggestionsKey,
22536
+ querySuggestionsKey,
22537
+ showPromptSuggestions,
22538
+ showQuerySuggestions
22539
+ ]);
22540
+ // Normalize `show*` for InnerAutocomplete: always surface `indexName`
22541
+ // (in feeds-mode it carries the feedID). Keeps downstream dedupe in
22542
+ // createAutocompleteStorage (suggestionsIndexName === index.indexName) working.
22543
+ var normalizedShowQuerySuggestions = React.useMemo(function() {
22544
+ if (!showQuerySuggestions) {
22545
+ return undefined;
22546
+ }
22547
+ if (isFeedsMode) {
22548
+ return _object_spread_props(_object_spread({}, showQuerySuggestions), {
22549
+ indexName: querySuggestionsKey
22550
+ });
22551
+ }
22552
+ return showQuerySuggestions;
22553
+ }, [
22554
+ isFeedsMode,
22555
+ querySuggestionsKey,
22556
+ showQuerySuggestions
22557
+ ]);
22558
+ var normalizedShowPromptSuggestions = React.useMemo(function() {
22559
+ if (!showPromptSuggestions) {
22560
+ return undefined;
22561
+ }
22562
+ if (isFeedsMode) {
22563
+ return _object_spread_props(_object_spread({}, showPromptSuggestions), {
22564
+ indexName: promptSuggestionsKey
22565
+ });
22566
+ }
22567
+ return showPromptSuggestions;
22568
+ }, [
22569
+ isFeedsMode,
22570
+ promptSuggestionsKey,
22571
+ showPromptSuggestions
22572
+ ]);
22573
+ // In feeds-mode, remap `indexName := indexId` so downstream storage (which
22574
+ // matches on indexName) sees feedIDs instead of the composition index name
22575
+ // that connectAutocomplete sets from the helper results.
22576
+ // Must be memoized: useConnector's useStableValue runs dequal on each render
22577
+ // and treats a new function identity as a change, re-registering the widget.
22578
+ var effectiveTransformItems = React.useMemo(function() {
22579
+ return isFeedsMode ? function(items) {
22580
+ var remapped = items.map(function(item) {
22581
+ return _object_spread_props(_object_spread({}, item), {
22582
+ indexName: item.indexId
22583
+ });
22584
+ });
22585
+ return transformItems ? transformItems(remapped) : remapped;
22586
+ } : transformItems;
22587
+ }, [
22588
+ isFeedsMode,
22589
+ transformItems
22590
+ ]);
22334
22591
  var recentSearchConfig = showRecent ? {
22335
22592
  headerComponent: (typeof showRecent === "undefined" ? "undefined" : _type_of(showRecent)) === 'object' ? showRecent.headerComponent : undefined,
22336
22593
  itemComponent: (typeof showRecent === "undefined" ? "undefined" : _type_of(showRecent)) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
@@ -22346,15 +22603,11 @@
22346
22603
  }, [
22347
22604
  indexRenderState
22348
22605
  ]);
22349
- return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Index, {
22350
- EXPERIMENTAL_isolated: true
22351
- }, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
22352
- return /*#__PURE__*/ React.createElement(Index, {
22353
- key: index.indexName,
22354
- indexName: index.indexName
22355
- }, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
22356
- }), /*#__PURE__*/ React.createElement(InnerAutocomplete, _object_spread_props(_object_spread({}, props), {
22357
- aiMode: aiMode,
22606
+ restProps.indices; restProps.feeds; var forwardedProps = _object_without_properties(restProps, [
22607
+ "indices",
22608
+ "feeds"
22609
+ ]);
22610
+ var innerAutocomplete = /*#__PURE__*/ React.createElement(InnerAutocomplete, _object_spread_props(_object_spread({}, forwardedProps), {
22358
22611
  indicesConfig: indicesConfig,
22359
22612
  refineSearchBox: refine,
22360
22613
  isSearchStalled: isSearchStalled,
@@ -22362,12 +22615,33 @@
22362
22615
  isSearchPage: isSearchPage,
22363
22616
  showRecent: showRecent,
22364
22617
  recentSearchConfig: recentSearchConfig,
22365
- showQuerySuggestions: showQuerySuggestions,
22618
+ showQuerySuggestions: normalizedShowQuerySuggestions,
22366
22619
  detachedMediaQuery: detachedMediaQuery,
22367
22620
  translations: translations,
22368
- showPromptSuggestions: showPromptSuggestions,
22621
+ showPromptSuggestions: normalizedShowPromptSuggestions,
22622
+ transformItems: effectiveTransformItems,
22369
22623
  chatRenderState: indexRenderState.chat
22370
- }))));
22624
+ }));
22625
+ if (isFeedsMode) {
22626
+ return /*#__PURE__*/ React.createElement(Index, {
22627
+ EXPERIMENTAL_isolated: true,
22628
+ indexName: compositionID,
22629
+ indexId: "ais-autocomplete-".concat(instanceKey)
22630
+ }, /*#__PURE__*/ React.createElement(Configure, searchParameters), /*#__PURE__*/ React.createElement(Feeds, {
22631
+ isolated: false,
22632
+ renderFeed: function renderFeed() {
22633
+ return null;
22634
+ }
22635
+ }), innerAutocomplete);
22636
+ }
22637
+ return /*#__PURE__*/ React.createElement(Index, {
22638
+ EXPERIMENTAL_isolated: true
22639
+ }, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
22640
+ return /*#__PURE__*/ React.createElement(Index, {
22641
+ key: index.indexName,
22642
+ indexName: index.indexName
22643
+ }, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
22644
+ }), innerAutocomplete);
22371
22645
  }
22372
22646
  function InnerAutocomplete(_0) {
22373
22647
  var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, props = _object_without_properties(_0, [
@@ -22845,7 +23119,8 @@
22845
23119
  function createDisplayResultsTool(itemComponent) {
22846
23120
  var DisplayResultsUIComponent = createDisplayResultsToolComponent({
22847
23121
  createElement: React.createElement,
22848
- Fragment: React.Fragment
23122
+ Fragment: React.Fragment,
23123
+ useMemo: React.useMemo
22849
23124
  });
22850
23125
  var Button = createButtonComponent({
22851
23126
  createElement: React.createElement
@@ -22952,7 +23227,7 @@
22952
23227
  if (!input || !applyFilters) return;
22953
23228
  var params = applyFilters({
22954
23229
  query: input.query,
22955
- facetFilters: input.facet_filters
23230
+ facetFilters: getFacetFiltersFromToolInput(input)
22956
23231
  });
22957
23232
  if (getSearchPageURL && new URL(getSearchPageURL(params)).pathname !== window.location.pathname) {
22958
23233
  window.location.href = getSearchPageURL(params);
@@ -22991,11 +23266,12 @@
22991
23266
 
22992
23267
  var ChatUiComponent = createChatComponent({
22993
23268
  createElement: React.createElement,
22994
- Fragment: React.Fragment
23269
+ Fragment: React.Fragment,
23270
+ memo: React.memo
22995
23271
  });
22996
23272
  function createDefaultTools(itemComponent, getSearchPageURL) {
22997
23273
  var _obj;
22998
- return _obj = {}, _define_property(_obj, SearchIndexToolType$1, createCarouselTool(true, itemComponent, getSearchPageURL)), _define_property(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _define_property(_obj, DisplayResultsToolType, createDisplayResultsTool(itemComponent)), _define_property(_obj, MemorizeToolType, {}), _define_property(_obj, MemorySearchToolType, {}), _define_property(_obj, PonderToolType, {}), _obj;
23274
+ return _obj = {}, _define_property(_obj, SearchIndexToolType$2, createCarouselTool(true, itemComponent, getSearchPageURL)), _define_property(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _define_property(_obj, DisplayResultsToolType, createDisplayResultsTool(itemComponent)), _define_property(_obj, MemorizeToolType, {}), _define_property(_obj, MemorySearchToolType, {}), _define_property(_obj, PonderToolType, {}), _obj;
22999
23275
  }
23000
23276
  function ChatInner(_0, _1) {
23001
23277
  var _ref = [
@@ -23079,6 +23355,23 @@
23079
23355
  }, [
23080
23356
  open
23081
23357
  ]);
23358
+ // Keep the conversation pinned to the bottom while streaming. The stick-to-
23359
+ // bottom ResizeObserver only reacts to content *height* changes, but tool
23360
+ // results such as a horizontally-growing carousel stream in without changing
23361
+ // height — so we also re-pin on every message/status update. Passing
23362
+ // `preserveScrollPosition` reuses the existing "only if already at the
23363
+ // bottom" gate, so this never fights a user who has scrolled up to read.
23364
+ React.useEffect(function() {
23365
+ if (status === 'streaming' || status === 'submitted') {
23366
+ scrollToBottom({
23367
+ preserveScrollPosition: true
23368
+ });
23369
+ }
23370
+ }, [
23371
+ messages,
23372
+ status,
23373
+ scrollToBottom
23374
+ ]);
23082
23375
  if (error) {
23083
23376
  throw error;
23084
23377
  }
@@ -25029,7 +25322,7 @@
25029
25322
  exports.RelatedProducts = RelatedProducts;
25030
25323
  exports.ReverseHighlight = ReverseHighlight;
25031
25324
  exports.SearchBox = SearchBox;
25032
- exports.SearchIndexToolType = SearchIndexToolType$1;
25325
+ exports.SearchIndexToolType = SearchIndexToolType$2;
25033
25326
  exports.Snippet = Snippet;
25034
25327
  exports.SortBy = SortBy;
25035
25328
  exports.Stats = Stats;