@indxsearch/intrface 4.0.0-beta.1 → 4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.0-beta.2
4
+
5
+ ### Minor Changes
6
+
7
+ - 2017916: `useAsk()` gives each of the assistant's steps as its parts too, in `stepDetails`: what kind of step it is (`read`, `search` or `pick`), what a search searched with and how many it found, and how many records were picked. Show the steps in your page's own language and words, rather than the English sentence in `steps`.
8
+
3
9
  ## 4.0.0-beta.1
4
10
 
5
11
  ### Major Changes
@@ -65,6 +65,21 @@ export interface AskState {
65
65
  picks?: AskPicks;
66
66
  /** What the agent has done so far ("Searching: Folkehøyskole, by Elevtall"), while it works. */
67
67
  steps: string[];
68
+ /** The same steps as their parts, to say them in the page's own language and words. */
69
+ stepDetails: AskStep[];
70
+ }
71
+ /** A step of the agent's, as its sentence and its parts: `read` (reading the question), `search`
72
+ * (what it searched with and how many it found) or `pick` (how many records it picked). */
73
+ export interface AskStep {
74
+ step: string;
75
+ kind?: 'read' | 'search' | 'pick';
76
+ /** For `search`: the filters, a filter expression, the words and the order it searched with, and
77
+ * how many it found (`more` when that is the cap). */
78
+ search?: AskFilters & {
79
+ filter?: string | null;
80
+ };
81
+ /** For `pick`: how many records it picked. */
82
+ count?: number;
68
83
  }
69
84
  /** What a catalogue's description was searched with: filters, words no filter covers, and the count. */
70
85
  export interface AskFilters {
@@ -124,4 +139,6 @@ export declare function useAsk(): {
124
139
  picks?: AskPicks;
125
140
  /** What the agent has done so far ("Searching: Folkehøyskole, by Elevtall"), while it works. */
126
141
  steps: string[];
142
+ /** The same steps as their parts, to say them in the page's own language and words. */
143
+ stepDetails: AskStep[];
127
144
  };
package/dist/index.cjs.js CHANGED
@@ -2,7 +2,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
2
2
 
3
3
  `))>=0;){let e=r.slice(0,a);r=r.slice(a+2);let t=`message`,n=[];for(let r of e.split(`
4
4
  `))r.startsWith(`event:`)?t=r.slice(6).trim():r.startsWith(`data:`)&&n.push(r.slice(5).trimStart());n.length&&(yield{event:t,data:JSON.parse(n.join(`
5
- `))})}}}finally{t.releaseLock()}}function R(e){let t=new URLSearchParams;e.state.queryId&&t.set(`queryId`,e.state.queryId),e.sessionId&&t.set(`session`,e.sessionId),e.source&&t.set(`source`,e.source),e.count===!1&&t.set(`count`,`false`);let n=t.toString();return n?`?${n}`:``}function z(e){return{...k,...e,hint:e?.hint??k.hint,finished:e?.finished??k.finished,found:e?.found??k.found,refocus:e?.refocus??k.refocus}}var B=.1,V={available:!1,offer:`none`,p:null,answerable:null,text:``,criteria:null,describes:!1,found:null,notFound:!1,held:!1,strictCoverage:!1,refocus:!1,filtersWhileTyping:`off`,mode:`soft`,askAnytime:!1,finished:null,answerNow:null,quick:`none`,stands:!1};function H(e={}){let{enabled:t=!0,pauseMs:n=300,prefetch:r=!0,mode:i,answerAfterMs:a=1e3}=e,o=D(),{url:s,team:l,dataset:u,authenticatedFetch:d,isFetchingInitial:f,authError:p,state:m}=o,h=(0,c.useRef)(o);h.current=o;let g=(e.text??m.query).trim(),[_,v]=(0,c.useState)(!1),[y,b]=(0,c.useState)(V),x=(0,c.useRef)(k),S=(0,c.useRef)(!0),C=(0,c.useRef)(`off`),w=(0,c.useRef)(`soft`),T=(0,c.useRef)(i);T.current=i;let E={get current(){return O(w.current,T.current)}},A=(0,c.useRef)(null),L=(0,c.useRef)(`none`),H=(0,c.useRef)(``),U=(0,c.useRef)(0),W=(0,c.useRef)(0);L.current=y.offer;let G=(0,c.useRef)(null),K=(0,c.useRef)(new Set),q=(0,c.useRef)(0),ee=(0,c.useRef)(g);ee.current=g;let te=(0,c.useRef)(!1);te.current=_;let[J,Y]=(0,c.useState)(0);(0,c.useEffect)(()=>{if(!J)return;let e=setTimeout(()=>Y(0),Math.max(0,J-Date.now()));return()=>clearTimeout(e)},[J]);let ne=`${s}/api/teams/${l}/datasets/${u}/search-or-ask`,re=()=>E.current===`inviting`||E.current===`proactive`?3:4,ie=e=>e!=null&&e>=(x.current.finished??.5),ae=e=>E.current!==`proactive`&&L.current===`strong`&&!!H.current&&e.startsWith(H.current),X=t&&!f&&!p;(0,c.useEffect)(()=>{if(v(!1),!X)return;let e=!1;return(async()=>{try{let t=await d(ne);if(!t.ok)return;let n=await t.json();if(e||!n.available||!n.settings?.enabled)return;C.current=n.settings.filtersWhileTyping??`off`,w.current=n.settings.mode??`soft`,x.current=z(n.settings.thresholds),S.current=n.settings.strictCoverageWhileAsking??!0,v(!0)}catch{}})(),()=>{e=!0}},[X,ne,d]);let oe=(0,c.useRef)(()=>{});oe.current=e=>{if(!r||!te.current||G.current||!e||!N(e,re())||K.current.has(e)||ae(e)||Date.now()<W.current||Date.now()<q.current)return;let t=(async()=>{try{let t=await d(`${ne}/intent`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e,prefetch:!0})});if(t.status===429){let e=Number(t.headers.get(`Retry-After`));q.current=Date.now()+(Number.isFinite(e)&&e>0?e:60)*1e3;return}t.ok&&(K.current.size>200&&K.current.clear(),K.current.add(e))}catch{}})();G.current={text:e,done:t},t.then(()=>{G.current?.done===t&&(G.current=null),ee.current!==e&&oe.current(ee.current)})},(0,c.useEffect)(()=>{if(!_){b(V);return}if(!g){H.current=``,b({...V,available:_});return}if(!N(g,re())){j(g)&&b(e=>({...e,available:_,offer:`none`,text:g}));return}oe.current(g);let e=!1,t=setTimeout(async()=>{if(ae(g)){b(e=>({...e,text:g}));return}if(Date.now()<W.current||(G.current?.text===g&&await G.current.done,e))return;let t=++U.current;H.current=g;try{let e=await d(`${ne}/intent${R(h.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:g})});if(e.status===429){let n=Number(e.headers.get(`Retry-After`));W.current=Date.now()+(Number.isFinite(n)&&n>0?n:60)*1e3;let{code:r}=await e.json().catch(()=>({}));r===`searchOrAskBudgetSpent`&&t===U.current&&(Y(W.current),b(e=>({...e,offer:`none`,answerNow:null,strictCoverage:!1,refocus:!1,notFound:!1})));return}if(e.status===409||e.status===404){v(!1);return}if(!e.ok)return;let{p:n,answerable:r,criteria:i,finished:a,found:o,reason:s,thresholds:c,strictCoverageWhileAsking:l,filtersWhileTyping:u,mode:f,refocus:p}=await e.json();if(u!=null&&(C.current=u),t!==U.current)return;l!=null&&(S.current=l),f!=null&&(w.current=f),c&&(x.current=z(c)),b(e=>{let t=P(e.offer,n,x.current),c=i??null,l=c!=null&&c>=x.current.strong,u=e.offer===`strong`&&!!e.text&&g.startsWith(e.text)||I(g)&&(a==null||ie(a)),d=l&&u?`strong`:l||t===`strong`&&!u?`invite`:t,f=E.current===`strict`&&d===`invite`?`none`:d,m=f===`strong`&&!(l&&c>n),h=o??null,_=x.current.found??0,v=x.current.refocus??0,y=e.refocus&&v>0&&!!e.text&&g.startsWith(e.text)&&Math.max(n,c??0)>=v-B;return{available:!0,offer:f,p:n,answerable:r??null,text:g,criteria:c,describes:l,found:h,notFound:m&&h!=null&&_>0&&h<_,held:s===`paused`,strictCoverage:S.current&&m,refocus:!!p||y,filtersWhileTyping:C.current,mode:E.current,askAnytime:!1,quick:`none`,finished:a??null,answerNow:E.current===`proactive`&&f===`strong`&&ie(a)?g:null,stands:!0}})}catch{}},n);return()=>{e=!0,clearTimeout(t)}},[g,_,ne,d,n]);let[Z,se]=(0,c.useState)(null);(0,c.useEffect)(()=>{se(null);let e=y.answerNow;if(!e||e!==g)return;let t=setTimeout(()=>se(e),Math.max(0,a-n));return()=>clearTimeout(t)},[y.answerNow,g,a,n]);let ce=_&&y.strictCoverage;(0,c.useEffect)(()=>{let{setSearchSettings:e,state:t}=h.current;if(ce){if(A.current)return;let n=t.searchSettings.match??{};A.current=Object.fromEntries(Object.keys(F).map(e=>[e,n[e]])),e({match:{...F}})}else A.current&&=(e({match:{...A.current}}),null)},[ce]);let le=_&&y.refocus&&!y.held&&J===0&&!!y.text&&g.startsWith(y.text);if((0,c.useEffect)(()=>{h.current.setSearchSettings({refocus:le})},[le]),!_)return V;let ue=E.current,de=!!y.text&&g.startsWith(y.text),fe=y.held||J>0;if(fe)return{...y,mode:ue,held:fe,offer:`none`,askAnytime:!1,answerNow:null,quick:`none`,notFound:!1,strictCoverage:!1,refocus:!1,stands:de};let pe=ue===`inviting`||ue===`proactive`,me=pe&&!!g&&(de&&y.p!=null&&y.p>=(x.current.hint??1)||M(g)),he=g?de&&y.offer===`strong`?ue===`proactive`?ie(y.finished)?`thinking`:`hint`:`ready`:de&&y.offer===`invite`?pe?`hint`:`invite`:me?`hint`:ue===`open`||pe?`ask`:`none`:`none`;return{...y,refocus:le,mode:ue,askAnytime:ue===`open`||pe,answerNow:Z!==null&&Z===g&&y.answerNow===g?Z:null,text:(he===`hint`||he===`ask`)&&!de?g:y.text,notFound:de&&y.notFound,quick:he,stands:de}}var U={row:`_row_epo6h_3`,icon:`_icon_epo6h_17`,line:`_line_epo6h_24`,text:`_text_epo6h_41`,question:`_question_epo6h_43`,actions:`_actions_epo6h_52`,enter:`_enter_epo6h_59`},W={invite:`Ask about this`,hint:`For a quick answer, type a bit more`,ready:`Ask the assistant`,thinking:`Thinking`,ask:`Ask`},G=({searchOrAsk:e,onAsk:t,labels:n,className:r=``})=>{let i={...W,...n},a=e.text.trim();if(!e.available||e.quick===`none`||!a)return null;let o=()=>t(a);return(0,u.jsxs)(`div`,{className:`${U.row} ${U[e.quick]} ${r}`,"aria-live":`polite`,children:[(0,u.jsx)(`span`,{className:U.icon,"aria-hidden":`true`,children:(0,u.jsx)(f.Ai_agent,{size:14,color:`currentColor`})}),e.quick===`thinking`&&(0,u.jsx)(d.ShimmerText,{className:U.text,children:i.thinking}),e.quick===`hint`&&(0,u.jsx)(`button`,{type:`button`,className:U.line,onClick:o,children:(0,u.jsx)(d.ShimmerText,{children:i.hint})}),e.quick===`invite`&&(0,u.jsx)(`button`,{type:`button`,className:U.line,onClick:o,children:i.invite}),e.quick===`ask`&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:U.question,children:a}),(0,u.jsxs)(`span`,{className:U.actions,children:[(0,u.jsxs)(`span`,{className:U.enter,children:[(0,u.jsx)(d.Kbd,{children:`↵`}),` to ask`]}),(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:o,children:i.ask})]})]}),e.quick===`ready`&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:U.question,children:a}),(0,u.jsxs)(`span`,{className:U.actions,children:[(0,u.jsxs)(`span`,{className:U.enter,children:[(0,u.jsx)(d.Kbd,{children:`↵`}),` to ask`]}),(0,u.jsx)(d.Button,{variant:`primary`,size:`micro`,onClick:o,children:i.ready})]})]})]})},K={grid:`_grid_1xjna_2`,chip:`_chip_1xjna_21`,chipLabel:`_chipLabel_1xjna_32`},q=(0,c.memo)(({field:e,value:t,onReset:n})=>(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:n,iconRight:(0,u.jsx)(f.X_or_error,{}),variant:`primary`,size:`micro`,className:K.chip,title:`${e}: ${t}`,children:(0,u.jsxs)(`span`,{className:K.chipLabel,children:[e,`: `,t]})})})),ee=(0,c.memo)(({field:e,min:t,max:n,onReset:r})=>(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:r,iconRight:(0,u.jsx)(f.X_or_error,{}),variant:`primary`,size:`micro`,className:K.chip,title:`${e}: ${t} – ${n}`,children:(0,u.jsxs)(`span`,{className:K.chipLabel,children:[e,`: `,t,` – `,n]})})})),te=(0,c.memo)(({field:e,label:t,onReset:n})=>(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:n,iconRight:(0,u.jsx)(f.X_or_error,{}),variant:`primary`,size:`micro`,className:K.chip,title:`${e}: ${t}`,children:(0,u.jsxs)(`span`,{className:K.chipLabel,children:[e,`: `,t]})})}));function J(){let{state:{filters:e,rangeFilters:t,bucketFilters:n},resetFilters:r,resetSingleFilter:i,resetRangeFilter:a,resetBucketFilter:o}=D(),s=(0,c.useMemo)(()=>Object.entries(e).map(([e,t])=>t.map(t=>({field:e,value:t}))).flat(),[e]),l=(0,c.useMemo)(()=>Object.entries(t).map(([e,{min:t,max:n}])=>({field:e,min:t,max:n})),[t]),f=(0,c.useMemo)(()=>Object.entries(n).flatMap(([e,t])=>t.map(t=>({field:e,range:t,label:`${t.min}-${t.max}`}))),[n]);return(0,c.useMemo)(()=>Object.keys(e).length>0||Object.keys(t).length>0||f.length>0,[e,t,f])?(0,u.jsx)(d.FilterPanelBase,{collapsible:!1,title:`Active filters`,children:(0,u.jsxs)(`ul`,{className:K.grid,children:[s.map(({field:e,value:t})=>(0,u.jsx)(q,{field:e,value:t,onReset:()=>i(e,t)},`${e}-${t}`)),l.map(({field:e,min:t,max:n})=>(0,u.jsx)(ee,{field:e,min:t,max:n,onReset:()=>a(e)},e)),f.map(({field:e,range:t,label:n})=>(0,u.jsx)(te,{field:e,label:n,onReset:()=>o(e,t)},`${e}-${t.min}-${t.max}`)),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:r,size:`micro`,variant:`ghost`,children:`Reset`})})]})}):null}var Y={withOffer:`_withOffer_1zrln_2`,offerRow:`_offerRow_1zrln_10`,offerHint:`_offerHint_1zrln_18`,kbd:`_kbd_1zrln_27`,askStrong:`_askStrong_1zrln_42`,thinking:`_thinking_1zrln_45`,offerQuick:`_offerQuick_1zrln_56`,filterChip:`_filterChip_1zrln_59`,filtersPopover:`_filtersPopover_1zrln_63`},ne=({className:e=``,autoFocus:t=!1,inputSize:n=`default`,showClear:r=!0,showFocus:i=!1,showStatus:a=!0,onAsk:o,searchOrAsk:s,askOffer:l=`chip`,onKeyDown:p,...m})=>{let{state:{query:h,filters:g,rangeFilters:_,bucketFilters:v,results:y,isFallback:b,searchSettings:x},setQuery:S,resetFilters:C,picks:w,showPicks:T}=D(),E=!!w,O=Object.values(g).reduce((e,t)=>e+t.length,0)+Object.keys(_).length+Object.values(v??{}).reduce((e,t)=>e+t.length,0),k=h.length>0,A=k&&!E&&y!==null&&y.length===0,j=k&&!E&&y!==null&&y.length>0&&b===!0,M=H({enabled:!!o&&!s}),N=s??M,P=N.quick===`ready`||N.askAnytime,F=c.default.useRef(null);c.default.useEffect(()=>{let e=N.answerNow;o&&e&&e===h.trim()&&F.current!==e&&(F.current=e,o(e,{proactive:!0}))},[N.answerNow,h,o]);let I=F.current!==null&&F.current===h.trim(),L=!o||!k||I?`none`:N.quick,R=N.available&&x.placeholderText===`Type to search`?`Search or ask`:x.placeholderText,z=e=>{p?.(e),!e.defaultPrevented&&e.key===`Enter`&&o&&P&&h.trim()&&(e.preventDefault(),W())},[B,V]=c.default.useState(!1);c.default.useEffect(()=>{O===0&&V(!1)},[O]);let U=()=>{T?.(null),S(``),O>0&&C()},W=()=>{F.current=h.trim(),o(h.trim())},K=(0,u.jsxs)(d.SearchField,{type:`text`,value:h,onChange:e=>S(e.target.value),placeholder:R,autoFocus:t,className:e,showSearchIcon:!0,inputSize:n,showFocusBorder:i,clearable:!1,onKeyDown:z,...m,children:[l===`chip`&&L===`thinking`&&(0,u.jsxs)(`span`,{className:Y.thinking,"aria-live":`polite`,children:[(0,u.jsx)(f.Ai_agent,{}),(0,u.jsx)(d.ShimmerText,{children:`Thinking`})]}),l===`chip`&&(L===`ready`||L===`invite`||L===`hint`||L===`ask`)&&(0,u.jsx)(d.Button,{variant:L===`ready`?`primary`:`ghost`,className:L===`ready`?Y.askStrong:void 0,size:`micro`,iconLeft:(0,u.jsx)(f.Ai_agent,{}),iconRight:L===`ready`?(0,u.jsx)(d.Kbd,{children:`Enter ↵`}):void 0,onClick:W,title:P?`Enter asks`:void 0,children:L===`ready`?`Ask`:L===`hint`?(0,u.jsx)(d.ShimmerText,{children:`For a quick answer, type a bit more`}):L===`invite`?`Ask about this`:`Ask`}),a&&A&&(0,u.jsx)(d.Chip,{children:`No results`}),a&&j&&(0,u.jsx)(d.Tooltip,{content:`No direct match. Showing the nearest results.`,children:(0,u.jsx)(`span`,{children:(0,u.jsx)(d.Chip,{icon:(0,u.jsx)(f.Fuzzy_search,{}),children:`Nearest`})})}),a&&O>0&&(0,u.jsx)(d.Popover,{open:B,onOpenChange:V,align:`end`,sideOffset:6,className:Y.filtersPopover,"aria-label":`Active filters`,trigger:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,className:Y.filterChip,"aria-label":`${O} filter${O===1?``:`s`} active: show them`,title:`${O} filter${O===1?``:`s`} active`,children:(0,u.jsx)(d.Chip,{icon:(0,u.jsx)(f.Filter,{}),color:`var(--CLightBlue)`,textColor:`#080809`,children:O})}),children:(0,u.jsx)(J,{})}),r&&(k||O>0)&&(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:U,"aria-label":O>0?`Clear search and filters`:`Clear search`,children:`Clear`})]});return l!==`below`||!o||!N.available?K:(0,u.jsxs)(`div`,{className:Y.withOffer,children:[K,(0,u.jsx)(`div`,{className:Y.offerRow,children:!I&&(0,u.jsx)(G,{searchOrAsk:N,onAsk:W,className:Y.offerQuick})})]})},re={message:`_message_1mgfk_1`,icon:`_icon_1mgfk_10`,title:`_title_1mgfk_15`,detail:`_detail_1mgfk_20`,technical:`_technical_1mgfk_25`,button:`_button_1mgfk_33`},ie={unreachable:{icon:f.Cloud,title:`Search is unavailable`,detail:`The search server can’t be reached right now.`},unauthorized:{icon:f.Key,title:`Search is unavailable`,detail:`The search key was not accepted.`},forbidden:{icon:f.Lock,title:`Search is unavailable`,detail:`This search key doesn’t have access to these results.`},notFound:{icon:f.Search,title:`Nothing to search here`,detail:`The collection this page searches doesn’t exist.`},notReady:{icon:f.Hour_glass,title:`Search is getting ready`,detail:`Results will appear in a moment.`},unavailable:{icon:f.Warning,title:`Search is unavailable`,detail:`The collection can’t be searched right now.`},rateLimited:{icon:f.Speedometer,title:`Too many searches`,detail:`Wait a moment, then try again.`},server:{icon:f.Warning,title:`Something went wrong`,detail:`The search server ran into a problem.`},setup:{icon:f.Warning,title:`Search isn’t set up`,detail:`This page is missing part of its search setup.`},unknown:{icon:f.Warning,title:`Something went wrong`,detail:`The search couldn’t be completed.`}},ae=({error:e,onRetry:t,hideTechnical:n=!1})=>{let{icon:r,title:i,detail:a}=ie[e.kind];(0,c.useEffect)(()=>{if(e.kind!==`notReady`||!t)return;let n=setTimeout(t,(e.retryAfterSeconds??2)*1e3);return()=>clearTimeout(n)},[e,t]);let o=e.retryable&&e.kind!==`notReady`&&t;return(0,u.jsxs)(`div`,{className:re.message,role:`alert`,children:[(0,u.jsx)(`span`,{className:re.icon,children:(0,u.jsx)(r,{size:70,color:`var(--lv4)`})}),(0,u.jsx)(`div`,{className:re.title,children:i}),(0,u.jsx)(`div`,{className:re.detail,children:a}),!n&&(0,u.jsx)(`code`,{className:re.technical,children:e.technical}),o&&(0,u.jsx)(d.Button,{variant:`secondary`,size:`micro`,className:re.button,onClick:t,children:`Try again`})]})},X={placeholder:`_placeholder_1m5kj_1`,invalid:`_invalid_1m5kj_11`,searchedFor:`_searchedFor_1m5kj_17`,notFound:`_notFound_1m5kj_21`,dimmed:`_dimmed_1m5kj_22`,picksHead:`_picksHead_1m5kj_25`,picksTitle:`_picksTitle_1m5kj_26`,picksCount:`_picksCount_1m5kj_27`,picksSpacer:`_picksSpacer_1m5kj_28`,why:`_why_1m5kj_29`},oe={row:`_row_11svi_1`,content:`_content_11svi_22`,indexNumber:`_indexNumber_11svi_36`,scoreNumber:`_scoreNumber_11svi_44`,skeletonBars:`_skeletonBars_11svi_53`},Z=({skeleton:e=!1,index:t,score:n,showScore:r=!1,children:i,skeletonDelay:a=0,skeletonWidths:o=[62,38]})=>(0,u.jsxs)(`div`,{className:oe.row,children:[t!==void 0&&(0,u.jsx)(`div`,{className:oe.indexNumber,children:t}),(0,u.jsx)(`div`,{className:oe.content,children:e?(0,u.jsxs)(`div`,{className:oe.skeletonBars,children:[(0,u.jsx)(d.Skeleton,{level:3,height:12,width:`${o[0]}%`,delay:a,appear:!1}),(0,u.jsx)(d.Skeleton,{level:3,height:8,width:`${o[1]}%`,delay:a+.05,appear:!1})]}):i}),r&&n!==void 0&&(0,u.jsx)(`div`,{className:oe.scoreNumber,children:n})]}),se={wrapper:`_wrapper_f970z_6`,skeletonAppear:`_skeletonAppear_f970z_1`},ce=[[62,38],[75,45],[58,33],[70,42],[65,50],[55,35],[72,40],[60,30]],le=({rows:e=6})=>(0,u.jsx)(`div`,{className:se.wrapper,children:Array.from({length:e}).map((e,t)=>(0,u.jsx)(Z,{skeleton:!0,skeletonDelay:t*.1,skeletonWidths:ce[t%ce.length]},t))});function ue(e){let t=e.trim().toLowerCase();return t===`true`||t===`false`||t!==``&&!Number.isNaN(Number(t))}function de(e,t){if(!t)return null;let n=[];for(let[e,r]of Object.entries(t))for(let t of r??[])t?.key&&t.key.trim().length>=2&&!ue(t.key)&&n.push({field:e,value:t.key});n.sort((e,t)=>t.value.length-e.value.length);let r=` `+e.toLowerCase()+` `,i=[];for(let e of n){let t=` `+e.value.toLowerCase().trim()+` `,n=r.indexOf(t);n<0||(i.push({field:e.field,value:e.value}),r=r.slice(0,n)+` `+r.slice(n+t.length))}return i.length===0?null:{filters:i,text:r.replace(/[?!.,]+\s*$/,``).replace(/\s+/g,` `).trim(),sort:null}}function fe(e={}){let t=D(),{url:n,team:r,dataset:i,authenticatedFetch:a,setQuery:o,toggleFilter:s,setRangeFilter:l,setSort:u}=t,{auto:d}=e,f=(0,c.useRef)(t);f.current=t;let[p,m]=(0,c.useState)(null),[h,g]=(0,c.useState)(``),[_,v]=(0,c.useState)(!1),y=(0,c.useRef)(0),b=(0,c.useCallback)(async e=>{let t=++y.current;v(!0);try{let o=await a(`${n}/api/teams/${r}/datasets/${i}/search-or-ask/filters${R(f.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e})});if(t!==y.current)return;let s=o.ok?await o.json():null;m(s&&s.filters.length>0?s:null),g(e)}catch{t===y.current&&m(null)}finally{t===y.current&&v(!1)}},[n,r,i,a]),x=(0,c.useCallback)(e=>{o(e.text);let t={...f.current.state.rangeBounds,...f.current.datasetBounds};for(let n of e.filters)n.value==null?l(n.field,n.min??t[n.field]?.min??0,n.max??t[n.field]?.max??2**53-1):s(n.field,n.value);e.sort&&u(e.sort.field,!e.sort.descending),m(null)},[o,s,l,u]),S=(0,c.useCallback)(()=>{y.current++,m(null),v(!1)},[]),C=(0,c.useRef)(new Set),[w,T]=(0,c.useState)(null),E=d?.filtersWhileTyping??`off`,O=!!d&&d.available&&d.describes&&d.offer===`strong`&&E!==`off`,k=d?.text??``,A=(0,c.useRef)(k);A.current=k;let j=t.state.facets,M=t.state.isLoading||t.facetsEnabled&&j==null;return(0,c.useEffect)(()=>{if(!O||!k||M||C.current.has(k))return;C.current.add(k);let e=de(k,j);if(e&&(C.current.add(e.text),x(e),T(k)),E!==`model`)return;let t=e?e.text:k;if(!t)return;let o=()=>A.current===k||A.current===t;(async()=>{let s=++y.current;v(!0);try{let c=await a(`${n}/api/teams/${r}/datasets/${i}/search-or-ask/filters${R(f.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t})});if(s!==y.current||!o())return;let l=c.ok?await c.json():null;l&&l.filters.length>0&&(C.current.add(l.text),x({filters:[...e?.filters??[],...l.filters],text:l.text,sort:l.sort}),T(k))}catch{}finally{s===y.current&&v(!1)}})()},[O,k,E,M,j,x,n,r,i,a]),{suggestion:p,forText:h,loading:_,suggest:b,apply:x,clear:S,appliedText:w}}var pe=/^\[\s*(?:'[^']*'(?:\s*,\s*'[^']*')*)?\s*\]$/;function me(e){let t=e.trim();if(!t.startsWith(`[`)||!t.endsWith(`]`))return;try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(e=>String(e))}catch{}if(!pe.test(t))return;let n=[],r=/'([^']*)'/g,i;for(;(i=r.exec(t))!==null;)n.push(i[1]);return n}function he(e,t,n){let r;try{r=typeof e==`string`?JSON.parse(e):e}catch{return null}let i;if(t&&t.length>0){i={};for(let e of t)e in r&&(i[e]=r[e])}else i={...r};if(n)for(let e in i){let t=i[e];if(typeof t==`string`){let n=me(t);n&&(i[e]=n)}}return i}var ge=({picks:e,fields:t,parseArrayStrings:n,label:r,onShowSearch:i,children:a})=>{let{url:o,team:s,dataset:l,authenticatedFetch:p,count:m}=D(),[h,g]=(0,c.useState)(null);(0,c.useEffect)(()=>{let t=!1;g(null);let n=e.picks.map(e=>e.documentKey);return(async()=>{try{let e=await p(`${o}/api/teams/${s}/datasets/${l}/documents/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}),r=e.ok?await e.json():[];t||g(new Map(n.map((e,t)=>[e,r[t]])))}catch{t||g(new Map)}})(),()=>{t=!0}},[e,o,s,l,p]);let _=(t,n)=>async()=>{if(e.askId)try{await p(`${o}/api/teams/${s}/datasets/${l}/events/select`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({queryId:e.askId,documentKey:t,position:n,...m===!1?{count:!1}:{}})})}catch{}},v=e.search;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`div`,{className:X.picksHead,children:[(0,u.jsxs)(`span`,{className:X.picksTitle,children:[(0,u.jsx)(f.Ai_agent,{size:14,color:`currentColor`}),r]}),(0,u.jsx)(`span`,{className:X.picksCount,children:e.picks.length}),(0,u.jsx)(`span`,{className:X.picksSpacer}),i&&(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:i,children:v?`Show all ${v.found}${v.more?`+`:``} found`:`Show the search instead`})]}),h===null?(0,u.jsx)(le,{rows:Math.max(1,e.picks.length)}):(0,u.jsx)(`div`,{children:e.picks.map(e=>{let r=h.get(e.documentKey),i=r==null?null:he(r,t,n);return i?(0,u.jsxs)(Z,{index:e.n,showScore:!1,children:[a(i,{result:{document:r,documentKey:e.documentKey,score:0,position:e.n},select:_(e.documentKey,e.n)}),e.why&&(0,u.jsxs)(`div`,{className:X.why,children:[(0,u.jsx)(f.Ai_agent,{size:12,color:`currentColor`}),(0,u.jsx)(`span`,{children:e.why})]})]},e.documentKey):null})})]})},_e=({fields:e,resultsPerPage:t,parseArrayStrings:n=!1,searchOrAsk:r,notFoundLabel:i=`These results may not hold what you are asking about`,picks:a,onShowSearch:o,picksLabel:s=`Picked by the assistant`,showScore:l,children:p})=>{let{state:{results:m,resultsSuppressed:h,searchSettings:g,countedTotal:_,query:v,error:y,errorInfo:b},isFetchingInitial:x,authError:S,authErrorInfo:C,retry:w,allowEmptySearch:T,fetchMoreResults:E,selectResult:O,searchText:k,searchAsTyped:A,picks:j,showPicks:M}=D(),{apply:N}=fe(),P=a===void 0?j:a,F=o??(()=>{P?.search&&N(P.search),M?.(null)}),I=(0,c.useRef)(null);P&&I.current?.picks!==P&&(I.current={picks:P,query:v});let L=!!P&&I.current?.query===v,R=t??30,[z,B]=(0,c.useState)(R),V=(0,c.useRef)(0),H=(0,c.useRef)(``);(0,c.useEffect)(()=>{let e=v!==H.current;(!m||m.length<V.current||e)&&B(R),V.current=m?.length??0,H.current=v},[m,R,v]);let U=m??[],W=!!r?.notFound,G=k!=null&&k.trim()!==v.trim()?k:null,K=!!m&&m.length>=g.maxNumberOfRecordsToReturn&&(_===void 0||_>m.length),q=!!m&&(U.length>z||K),ee=()=>{let e=z+R;B(e),m&&e>=m.length&&K&&E(m.length+R)};if(P&&L&&!x&&!S)return(0,u.jsx)(ge,{picks:P,fields:e,parseArrayStrings:n,label:s,onShowSearch:F,children:p});if(x)return T?(0,u.jsx)(le,{rows:R}):(0,u.jsx)(`div`,{className:X.placeholder,children:(0,u.jsx)(f.Indx,{size:200,color:`var(--lv5)`})});let te=S??y;return te?(0,u.jsx)(ae,{error:(S?C:b)??{kind:`unknown`,message:te,technical:te,retryable:!1},onRetry:w}):h||m===null?(0,u.jsx)(`div`,{className:X.placeholder,children:(0,u.jsx)(f.Indx,{size:200,color:`var(--lv5)`})}):U.length===0?null:(0,u.jsxs)(u.Fragment,{children:[G&&(0,u.jsxs)(`div`,{className:X.searchedFor,"aria-live":`polite`,children:[(0,u.jsxs)(`span`,{children:[`Searching for `,(0,u.jsx)(`strong`,{children:G})]}),A&&(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:A,children:`Search for your exact words`})]}),W&&(0,u.jsx)(`p`,{className:X.notFound,"aria-live":`polite`,children:i}),(0,u.jsx)(`div`,{className:W?X.dimmed:void 0,children:U.slice(0,z).map((t,r)=>{let i=t.score,a=he(t.document,e,n);return a?(0,u.jsx)(Z,{index:r,score:i,showScore:l??g.showScore,children:p(a,{result:t,select:()=>O?.(t)??Promise.resolve()})},r):(0,u.jsx)(`div`,{className:X.invalid,children:(0,u.jsx)(`p`,{children:`Invalid JSON`})},r)})}),q&&(0,u.jsx)(`div`,{style:{textAlign:`center`,marginTop:`20px`},children:(0,u.jsx)(d.Button,{variant:`secondary`,size:`micro`,onClick:ee,children:v.trim()===``?`Load more`:_!==void 0&&_>0?`Load results ${z+1}-${Math.min(z+R,m.length,_)} of ${_}`:`Load more`})})]})},ve={row:`_row_ujwhc_1`,title:`_title_ujwhc_8`},ye=({variant:e=`default`,children:t})=>(0,u.jsx)(`div`,{className:[ve.row,e===`title`?ve.title:``].filter(Boolean).join(` `),children:t}),be={listRows:`_listRows_13obt_2`,sliderArea:`_sliderArea_13obt_8`,inputRow:`_inputRow_13obt_15`,histogramRow:`_histogramRow_13obt_22`},xe=[65,80,55,72,60,75,50,68],Se=({title:e,rows:t=5,variant:n=`list`,withHistogram:r=!1,collapsible:i=!0,startCollapsed:a=!1})=>(0,u.jsx)(d.FilterPanelBase,{title:e,collapsible:i,collapsed:a,children:n===`slider`?(0,u.jsxs)(`div`,{className:be.sliderArea,children:[r&&(0,u.jsx)(`div`,{className:be.histogramRow}),(0,u.jsx)(d.Skeleton,{height:6}),(0,u.jsxs)(`div`,{className:be.inputRow,children:[(0,u.jsx)(d.Skeleton,{width:40,height:20,delay:.1}),(0,u.jsx)(d.Skeleton,{width:40,height:20,delay:.15})]})]}):(0,u.jsx)(`div`,{className:be.listRows,children:Array.from({length:t}).map((e,t)=>(0,u.jsx)(d.Skeleton,{width:`${xe[t%xe.length]}%`,delay:t*.05},t))})}),Ce={list:`_list_18vbb_2`,count:`_count_18vbb_7`,countValue:`_countValue_18vbb_17`,chip:`_chip_18vbb_22`,chipLabel:`_chipLabel_18vbb_32`,grid:`_grid_18vbb_40`,active:`_active_18vbb_54`},we={notice:`_notice_4sel0_1`,technical:`_technical_4sel0_9`},Te=({label:e,field:t,missing:n})=>{let r=n.map(e=>e[0].toUpperCase()+e.slice(1)).join(` and `);return(0,c.useEffect)(()=>{console.warn(`[intrface] The panel for "${t}" is hidden: the field is not ${r}. Mark it ${r} in the dataset's field configuration (web console → Fields).`)},[t,r]),(0,u.jsx)(d.FilterPanelBase,{title:e??t,collapsible:!1,children:(0,u.jsxs)(`div`,{className:we.notice,children:[(0,u.jsx)(`span`,{children:`Not available`}),(0,u.jsxs)(`code`,{className:we.technical,children:[t,`: not `,r]})]})})},Ee=({field:e,label:t,preserveBlankFacetState:n=!1,preserveBlankFacetStateOrder:r=!1,sortFacetsBy:i=`histogram`,limit:a=10,collapsible:o=!0,startCollapsed:s=!1,control:l,displayType:f,layout:p=`list`,showActivePanel:m=!1,showCount:h=!0,showNull:g=!1,match:_=`all`,displayIfEmptyQuery:v=!0,displayCondition:y=e=>!0})=>{let{state:{facets:b,filterableFields:x,facetableFields:S,filters:C,query:w},toggleFilter:T,setValueMatch:E,authError:O,isFetchingInitial:k,allowEmptySearch:A}=D(),j=l??f??`checkbox`,M=j===`radio`?`any`:_;(0,c.useEffect)(()=>{E(e,M)},[e,M,E]);let N=(0,c.useRef)(null),[P,F]=(0,c.useState)(a);if((0,c.useEffect)(()=>{F(a)},[b?.[e],a]),!A&&!w||O)return null;if(k||!b)return j===`toggle`?(0,u.jsx)(Se,{rows:1,collapsible:!1}):(0,u.jsx)(Se,{title:t,rows:Math.min(a,6),collapsible:o,startCollapsed:s});if(!y({query:w??``,filters:C,facets:b})||!v&&!w&&Object.keys(C).length<1)return null;if(!x?.includes(e)||!S?.includes(e)){let n=[];return x?.includes(e)||n.push(`filterable`),S?.includes(e)||n.push(`facetable`),(0,u.jsx)(Te,{label:t,field:e,missing:n})}let I=b?.[e]??(j===`toggle`?[]:void 0);if(!I||!Array.isArray(I))return null;let L=C?.[e]??[];n&&!N.current&&I.length>0&&(N.current=I.reduce((e,t)=>(e[t.key]=t.value,e),{}));let R=new Map;n&&N.current&&Object.keys(N.current).forEach(e=>{R.set(e,0)}),I.forEach(e=>{R.set(e.key,e.value)});let z=new Set([`true`,`false`,`null`]),B=Array.from(R.keys()),V=j===`toggle`&&(B.length>0&&B.every(e=>z.has(e))||B.length===0&&L.length>0);if(V&&R.has(`null`)){let e=R.get(`null`)??0,t=R.get(`false`)??0;R.set(`false`,t+e),R.delete(`null`)}if(j===`toggle`&&!V)return(0,u.jsx)(d.FilterPanelBase,{collapsible:!1,children:(0,u.jsx)(`div`,{className:Ce.count,children:(0,u.jsx)(d.ToggleSwitch,{label:t,checked:!1,onChange:()=>{},disabled:!0})})});if(V){let n=R.get(`true`),r=typeof n==`number`?n:null,i=L.includes(`true`),a=r===0&&!i,o=h&&(r??0)>0?`${r}`:``;return(0,u.jsx)(d.FilterPanelBase,{collapsible:!1,children:(0,u.jsxs)(`div`,{className:Ce.count,children:[(0,u.jsx)(d.ToggleSwitch,{label:t,checked:i,onChange:()=>T(e,`true`),disabled:a}),` `,o]})})}let H=Array.from(R.entries());if(g||(H=H.filter(([e])=>e!==`null`)),H.length===0&&!n)return null;if(!r){if(i===`alphabetical`){let e=H.filter(([,e])=>typeof e==`number`&&e>0).sort(([e],[t])=>e.localeCompare(t)),t=H.filter(([,e])=>e===0||e===null).sort(([e],[t])=>e.localeCompare(t));H=[...e,...t]}else if(i===`numeric`){let e=(e,t)=>{let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e.localeCompare(t)},t=H.filter(([,e])=>typeof e==`number`&&e>0).sort(([t],[n])=>e(t,n)),n=H.filter(([,e])=>e===0||e===null).sort(([t],[n])=>e(t,n));H=[...t,...n]}else{let e=H.filter(([,e])=>typeof e==`number`&&e>0),t=H.filter(([,e])=>e===0||e===null);H=[...e,...t]}}let U=typeof a==`number`&&H.length>a,W=U?H.slice(0,P):H,G=(t,n)=>{let r=L.includes(t),i=n===0,a=h&&(n??0)>0?` (${n})`:``,o=h&&(n??0)>0?n:``,s=()=>T(e,t,j===`radio`);switch(j){case`button`:return p===`list`?(0,u.jsxs)(`div`,{className:Ce.count,children:[(0,u.jsx)(d.Button,{variant:r?`primary`:`secondary`,onClick:s,disabled:i,size:`micro`,className:Ce.chip,title:t,children:(0,u.jsx)(`span`,{className:Ce.chipLabel,children:t})}),(0,u.jsx)(`span`,{className:Ce.countValue,children:o})]}):(0,u.jsx)(d.Button,{variant:r?`primary`:`secondary`,onClick:s,disabled:i,size:`micro`,className:Ce.chip,title:`${t}${a}`,children:(0,u.jsx)(`span`,{className:Ce.chipLabel,children:`${t}${a}`})});case`toggle`:return(0,u.jsx)(d.ToggleSwitch,{label:t,checked:r,onChange:s,disabled:i});case`radio`:{let n=(0,u.jsx)(d.RadioButton,{id:`${e}-${t}`,name:e,value:t,label:p===`grid`?`${t}${a}`:t,checked:r,onChange:s,disabled:i});return p===`list`?(0,u.jsxs)(`div`,{className:Ce.count,children:[n,(0,u.jsx)(`span`,{className:Ce.countValue,children:o})]}):n}default:return p===`list`?(0,u.jsxs)(`div`,{className:Ce.count,children:[(0,u.jsx)(d.Checkbox,{label:t,score:``,checked:r,onChange:s,disabled:i}),(0,u.jsx)(`span`,{className:Ce.countValue,children:o})]}):(0,u.jsx)(d.Checkbox,{label:t,score:a,checked:r,onChange:s,disabled:i})}};return(0,u.jsx)(d.FilterPanelBase,{title:t,collapsible:o,collapsed:o?s:!1,className:m&&L.length>0?Ce.active:void 0,children:(0,u.jsxs)(`ul`,{className:p===`grid`?Ce.grid:Ce.list,style:{listStyle:`none`,padding:0,margin:0},children:[W.map(([e,t])=>(0,u.jsx)(`li`,{children:G(e,t)},e)),U&&P<H.length&&(()=>{let e=H.length-P,t=Math.min(50,e);return(0,u.jsx)(`li`,{className:Ce.toggleItem,children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:()=>F(e=>e+50),children:`Show ${t} more of ${H.length} total`})})})()]})})},Q={disabledMessage:`_disabledMessage_adany_1`,histogram:`_histogram_adany_6`,histogramLayer:`_histogramLayer_adany_14`,histogramLive:`_histogramLive_adany_22`,histogramLit:`_histogramLit_adany_23`,histogramFill:`_histogramFill_adany_30`,histogramBar:`_histogramBar_adany_43`,histogramSeparators:`_histogramSeparators_adany_61`,histogramSeparator:`_histogramSeparator_adany_48`,active:`_active_adany_76`};function De(e){if(!Number.isFinite(e))return 0;let t=String(e),n=t.indexOf(`.`);return n===-1?0:Math.min(6,t.length-n-1)}function Oe(e){let t=0;for(let n of e)t=Math.max(t,De(n));return t===0?1:Number((10**-t).toFixed(t))}function ke(e,t){return Number(e.toFixed(De(t)))}function Ae(e,t,n){let r=t+Math.round((e-t)/n)*n;return Number(r.toFixed(De(n)))}function je(e,t,n){let r=Math.ceil(Number(((e-t)/n).toFixed(6)));return Number((t+r*n).toFixed(De(n)))}var Me=({field:e,label:t,expectedMin:n=0,expectedMax:r=1e3,control:i,displayType:a,showActivePanel:o=!1,collapsible:s=!0,startCollapsed:l=!1,showHistogram:f=!1,resolution:p,step:m,stepMarks:h})=>{let{state:{rangeFilters:g,rangeBounds:_,facetStats:v,facets:y,filterableFields:b,facetableFields:x,query:S,facetDebounceDelayMillis:C},setRangeFilter:w,resetRangeFilter:T,allowEmptySearch:E,authError:O,isFetchingInitial:k}=D(),A=i??a??`input`,j=_?.[e]!==void 0,M=_?.[e]??{min:n,max:r},N=M.min,P=M.max,F=v?.[e]??M,I=Math.max(N,Math.min(P,F.min)),L=Math.max(N,Math.min(P,F.max)),R=c.default.useMemo(()=>{if(m)return m;let t=Math.max(De(N),De(P)),n=y?.[e];if(Array.isArray(n))for(let e of n)t=Math.max(t,De(Number(e.key)));return t===0?1:Number((10**-t).toFixed(t))},[m,N,P,y,e]),z=j&&N===P,B=z?n:N,V=z?r:P,H=je(V+R,B,R),U=e=>Math.min(H,Math.max(B,e)),W=g?.[e],G=o&&W!==void 0?Q.active:void 0,K=W?W.min:N,q=W?W.max:P,ee=W!==void 0,te=I!==N||L!==P,[J,Y]=c.default.useState([K,q]),[ne,re]=c.default.useState(!1),[ie,ae]=c.default.useState(!1),[X,oe]=c.default.useState(String(K)),[Z,se]=c.default.useState(String(q)),ce=c.default.useMemo(()=>{let e=De(R);return{width:`calc(${Math.max(3,N.toFixed(e).length,P.toFixed(e).length,X.length,Z.length)+1}ch + 20px)`}},[R,N,P,X,Z]);c.default.useEffect(()=>{oe(String(J[0])),se(String(J[1]))},[J]);let{finalMin:le,finalMax:ue,isValidMin:de,isValidMax:fe}=c.default.useMemo(()=>{let[e,t]=J,n=Math.max(N,Math.min(P,e)),r=Math.max(N,Math.min(P,t)),i=Math.min(n,r),a=Math.max(n,r);return{finalMin:i,finalMax:a,isValidMin:i>=N&&i<=a,isValidMax:a<=P&&a>=i}},[J,N,P]);c.default.useEffect(()=>{if(z)return;if(J[0]===N&&J[1]===P){re(!1),ae(!1);return}let t=C??500,n=setTimeout(()=>{re(!de),ae(!fe)},300),r=setTimeout(()=>{de&&fe&&(le===N&&ue===P?T(e,!1):w(e,le,ue))},t);return()=>{clearTimeout(n),clearTimeout(r)}},[le,ue,de,fe,N,P,e,T,w,C,z]),c.default.useEffect(()=>{Y([K,q]),re(!1),ae(!1)},[K,q,e]);let pe=c.default.useCallback(e=>{let t=ke(Math.min(e[0],e[1]-R),R);return[t,ke(Math.max(e[1]-R,t),R)]},[R]),me=c.default.useCallback(e=>{if(z)return;let[t,n]=pe(e);Y([Math.max(N,Math.min(L,t)),Math.max(I,Math.min(P,n))])},[z,pe,N,P,I,L]),he=c.default.useCallback(t=>{if(z)return;let[n,r]=pe(t),i=Math.max(N,Math.min(L,n)),a=Math.max(I,Math.min(P,r));i===N&&a===P?(Y([N,P]),T(e,!0)):Y([i,a])},[z,pe,N,P,I,L,e,T]),ge=c.default.useRef(null),_e=c.default.useCallback((t,n)=>{if(z)return;let r=ge.current;if(W&&r&&r.start===t&&r.last===n){ge.current=null,Y([N,P]),T(e,!0);return}let i=Ae(Math.max(N,I,t),N,R),a=Math.max(i,Ae(Math.min(P,L,n),N,R));ge.current={start:t,last:n},Y([i,a])},[z,W,N,P,I,L,R,e,T]),ve=c.default.useCallback(()=>{if(z)return;let e=X.trim(),t=e===``?NaN:Number(e);if(isNaN(t)){oe(String(J[0]));return}let n=Math.max(N,Math.min(L,t));n<J[1]?Y([n,J[1]]):Y([N,J[1]]),oe(String(n<J[1]?n:N))},[z,X,J,N,L]),ye=c.default.useCallback(()=>{if(z)return;let e=Z.trim(),t=e===``?NaN:Number(e);if(isNaN(t)){se(String(J[1]));return}let n=Math.max(I,Math.min(P,t));n>J[0]?Y([J[0],n]):Y([J[0],P]),se(String(n>J[0]?n:P))},[z,Z,J,I,P]),be=e=>t=>{t.key===`Enter`&&e()},[xe,Ce]=c.default.useState(null),we=c.default.useRef(null);c.default.useEffect(()=>{if(!f)return;let t=`${N}:${P}`;if(t===we.current&&we.current!==null)return;let n=y?.[e];if(!Array.isArray(n)||n.length===0)return;let r=n.filter(e=>e.value!=null&&!isNaN(Number(e.key))).map(e=>({key:e.key,value:e.value}));r.length>0&&(we.current=t,Ce(r))},[N,P,y,e,f]);let Ee=c.default.useMemo(()=>{if(!f||!xe||xe.length===0)return[];let e=P-N;if(e<=0)return[];let t=p??Math.max(R,ke(Math.ceil(e/20/R)*R,R)),n=Math.ceil(e/t);return Array.from({length:n},(e,r)=>{let i=N+r*t,a=N+(r+1)*t,o=r===n-1,s=xe.filter(e=>{let t=Number(e.key);return t>=i&&(t<a||o&&t<=P)}).reduce((e,t)=>e+t.value,0),c=o?P:ke(a-R,R);return{bucketStart:i,bucketEnd:a,count:s,last:c,barEnd:ke(c+R,R)}}).map((e,t,n)=>({...e,span:(t+1<n.length?n[t+1].bucketStart:Math.max(e.barEnd,H))-e.bucketStart}))},[f,xe,N,P,p,R,H]),Oe=c.default.useMemo(()=>Math.max(...Ee.map(e=>e.count),1),[Ee]);return f&&!k&&!x?.includes(e)&&console.warn(`RangeFilterPanel: showHistogram=true but field "${e}" is not facetable. Add .Facetable = true to this field.`),O?null:k?(0,u.jsx)(Se,{title:t,variant:`slider`,withHistogram:f,collapsible:s,startCollapsed:l}):!E&&!S?null:b?.includes(e)?A===`slider`?(0,u.jsxs)(d.FilterPanelBase,{title:t,collapsed:l,collapsible:s,className:G,children:[z&&(0,u.jsxs)(`div`,{className:Q.disabledMessage,children:[`No adjustable range (all results have the same value: `,N,`).`]}),f&&Ee.length===0&&(0,u.jsx)(`div`,{className:Q.histogram}),f&&Ee.length>0&&(()=>{let[e,t]=L>I&&(I>N||L<P)?[I,L]:[B,V],n=Math.max(le,e),r=Math.min(ue,t),i=H,a=i-B||1,o=e=>Math.max(0,Math.min(1,(e-B)/a)),s=e=>e>=V?0:Math.max(0,Math.min(1,(i-(e+R))/a)),c=o(n),l=r<n?1-c:s(r),d=e=>`calc(10px + (100% - 20px) * ${e})`,f=`inset(0 ${d(l)} 0 ${d(c)})`,p=`inset(0 ${d(s(t))} 0 ${d(o(e))})`,m=n=>n.last<e||n.bucketStart>t,h=Ee.slice(1).map(e=>d((e.bucketStart-B)/a)),g=Ee.map(e=>({...e,height:Math.max(1,Math.ceil(e.count/Oe*20))}));return(0,u.jsxs)(`div`,{className:Q.histogram,children:[(0,u.jsx)(`div`,{className:Q.histogramLayer,children:g.map((e,t)=>(0,u.jsx)(`button`,{type:`button`,className:Q.histogramBar,style:{flexGrow:e.span},"data-testid":`histogram-bar`,disabled:z||m(e),"aria-label":`${e.bucketStart} to ${e.last}: ${e.count}`,title:`${e.bucketStart} to ${e.last}: ${e.count}`,onClick:()=>_e(e.bucketStart,e.last),children:(0,u.jsx)(`span`,{className:Q.histogramFill,style:{height:`${e.height}px`}})},t))}),(0,u.jsx)(`div`,{className:`${Q.histogramLayer} ${Q.histogramLive}`,"aria-hidden":`true`,"data-testid":`histogram-live`,style:{clipPath:p},children:g.map((e,t)=>(0,u.jsx)(`span`,{className:Q.histogramBar,style:{flexGrow:e.span},children:(0,u.jsx)(`span`,{className:Q.histogramFill,style:{height:`${e.height}px`}})},t))}),(0,u.jsx)(`div`,{className:`${Q.histogramLayer} ${Q.histogramLit}`,"aria-hidden":`true`,"data-testid":`histogram-lit`,style:{clipPath:f},children:g.map((e,t)=>(0,u.jsx)(`span`,{className:Q.histogramBar,style:{flexGrow:e.span},children:(0,u.jsx)(`span`,{className:Q.histogramFill,style:{height:`${e.height}px`}})},t))}),(0,u.jsx)(`div`,{className:Q.histogramSeparators,"aria-hidden":`true`,children:h.map((e,t)=>(0,u.jsx)(`span`,{className:Q.histogramSeparator,style:{left:e}},t))})]})})(),(0,u.jsx)(`div`,{style:{padding:`10px 10px 20px 10px`},children:(0,u.jsx)(d.Slider,{min:B,max:H,step:R,stepMarks:h,value:z?[B,H]:[U(Ae(le,B,R)),U(Ae(ue+R,B,R))],isRange:!0,onChange:e=>me(e),onFinalChange:e=>he(e),disabled:z,activeMin:I,activeMax:U(ke(L+R,R)),isFaceted:te,highlightFaceted:ee,"aria-label":t||`Filter by ${e}`})}),(0,u.jsxs)(`div`,{style:{display:`flex`,gap:`10px`,alignItems:`flex-start`,justifyContent:`space-between`},children:[(0,u.jsx)(d.InputField,{label:`Min:`,type:`number`,style:ce,value:z?String(N):X,min:N,max:ke(Math.min(L,J[1]-R),R),onChange:e=>oe(e.target.value),onBlur:ve,onKeyDown:be(ve),disabled:z,isValid:z||!ne}),(0,u.jsx)(d.InputField,{label:`Max:`,type:`number`,style:ce,value:z?String(P):Z,min:ke(Math.max(I,J[0]+R),R),max:P,onChange:e=>se(e.target.value),onBlur:ye,onKeyDown:be(ye),disabled:z,isValid:z||!ie})]})]}):(0,u.jsxs)(d.FilterPanelBase,{title:t,className:G,children:[z&&(0,u.jsxs)(`div`,{className:Q.disabledMessage,children:[`No adjustable range (all results have the same value: `,N,`).`]}),(0,u.jsxs)(`div`,{style:{display:`flex`,gap:`10px`,alignItems:`flex-start`},children:[(0,u.jsx)(d.InputField,{label:`Min:`,type:`number`,style:ce,value:z?String(N):X,min:N,max:ke(Math.min(L,J[1]-R),R),onChange:e=>oe(e.target.value),onBlur:ve,onKeyDown:be(ve),disabled:z,isValid:z||!ne}),(0,u.jsx)(d.InputField,{label:`Max:`,type:`number`,style:ce,value:z?String(P):Z,min:ke(Math.max(I,J[0]+R),R),max:P,onChange:e=>se(e.target.value),onBlur:ye,onKeyDown:be(ye),disabled:z,isValid:z||!ie})]})]}):(0,u.jsx)(Te,{label:t,field:e,missing:[`filterable`]})},Ne={list:`_list_9je85_2`,grid:`_grid_9je85_9`,count:`_count_9je85_22`,countValue:`_countValue_9je85_31`,chip:`_chip_9je85_35`,active:`_active_9je85_41`};function Pe(e,t){if(!t)return null;let n=0,r=!1;for(let i of t){let t=Number(i.key);if(!Number.isNaN(t)&&e.contains(t)){if(typeof i.value!=`number`)return null;n+=i.value,r=!0}}return r?n:0}var Fe=({field:e,label:t,width:n,buckets:r,control:i,displayType:a,layout:o=`list`,showCount:s=!0,showEmpty:l=!1,limit:f,showActivePanel:p=!1,collapsible:m=!0,startCollapsed:h=!1})=>{let{state:{facets:g,filterableFields:_,facetableFields:v,bucketFilters:y,rangeBounds:b,facetStats:x,query:S},toggleBucketFilter:C,authError:w,isFetchingInitial:T,allowEmptySearch:E}=D(),O=i??a??`checkbox`,k=g?.[e],A=y[e]??[],[j,M]=(0,c.useState)(f??1/0);(0,c.useEffect)(()=>{M(f??1/0)},[f,k]);let N=b?.[e]??x?.[e],P=(0,c.useMemo)(()=>{let e=[];if(N&&e.push(N.min,N.max),Array.isArray(k))for(let t of k)e.push(Number(t.key));return Oe(e.filter(Number.isFinite))},[N,k]),F=(0,c.useMemo)(()=>{let e=N?.min??-Number.MAX_VALUE,t=N?.max??Number.MAX_VALUE,i=(n,r,i)=>({label:i??(n===void 0?`up to ${r}`:r===void 0?`${n} and up`:`${n}-${r}`),range:{min:n??e,max:r??t},contains:e=>(n===void 0||e>=n)&&(r===void 0||e<=r)});if(r&&r.length>0)return r.map(e=>i(e.min,e.max,e.label));if(Array.isArray(n)){let e=[...n].sort((e,t)=>e-t),t=[];for(let n=0;n<e.length-1;n++)t.push(i(e[n],ke(e[n+1]-P,P)));return t}if(typeof n==`number`&&n>0&&N){let e=[],t=Math.floor(N.min/n)*n;for(let r=t;r<=N.max;r=ke(r+n,P))e.push(i(ke(r,P),ke(r+n-P,P)));return e}return[]},[r,n,N,P]);if(w)return null;if(T||!g)return(0,u.jsx)(Se,{title:t,rows:Math.max(1,Math.min(F.length||5,8)),collapsible:m,startCollapsed:h});if(!E&&!S)return null;if(!_?.includes(e))return(0,u.jsx)(Te,{label:t,field:e,missing:[`filterable`]});let I=v?.includes(e)&&Array.isArray(k),L=e=>A.some(t=>t.min===e.range.min&&t.max===e.range.max),R=F.map(e=>({bucket:e,count:I?Pe(e,k):null}));if(l||(R=R.filter(e=>e.count!==0||L(e.bucket))),R.length===0)return null;let z=R.slice(0,j),B=(t,n)=>{let r=L(t),i=n===0&&!r,a=s&&(n??0)>0?`${n}`:``,c=()=>C(e,t.range,O===`radio`);if(O===`radio`){let n=(0,u.jsx)(d.RadioButton,{id:`${e}-${t.range.min}-${t.range.max}`,name:e,value:t.label,label:o===`grid`&&a?`${t.label} (${a})`:t.label,checked:r,onChange:c,disabled:i});return o===`list`?(0,u.jsxs)(`div`,{className:Ne.count,children:[n,(0,u.jsx)(`span`,{className:Ne.countValue,children:a})]}):n}if(O===`button`){let e=(0,u.jsx)(d.Button,{variant:r?`primary`:`secondary`,onClick:c,disabled:i,size:`micro`,className:Ne.chip,children:o===`grid`&&a?`${t.label} (${a})`:t.label});return o===`list`?(0,u.jsxs)(`div`,{className:Ne.count,children:[e,(0,u.jsx)(`span`,{className:Ne.countValue,children:a})]}):e}return o===`list`?(0,u.jsxs)(`div`,{className:Ne.count,children:[(0,u.jsx)(d.Checkbox,{label:t.label,score:``,checked:r,onChange:c,disabled:i}),(0,u.jsx)(`span`,{className:Ne.countValue,children:a})]}):(0,u.jsx)(d.Checkbox,{label:t.label,score:a?` (${a})`:``,checked:r,onChange:c,disabled:i})};return(0,u.jsx)(d.FilterPanelBase,{title:t,collapsible:m,collapsed:m?h:!1,className:p&&A.length>0?Ne.active:void 0,children:(0,u.jsxs)(`ul`,{className:o===`grid`?Ne.grid:Ne.list,style:{listStyle:`none`,padding:0,margin:0},children:[z.map(({bucket:e,count:t})=>(0,u.jsx)(`li`,{children:B(e,t)},`${e.range.min}-${e.range.max}`)),z.length<R.length&&(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:()=>M(R.length),children:`Show ${R.length-z.length} more of ${R.length} total`})})]})})},Ie={select:`_select_nwf7i_1`,radioGroup:`_radioGroup_nwf7i_6`},Le=({options:e,noneLabel:t=`None`,control:n,displayType:r,collapsible:i=!0,startCollapsed:a=!1})=>{let o=n??(r===`radio`?`radio`:`select`),{state:{sortableFields:s,sortBy:c,sortAscending:l},setSort:f,isFetchingInitial:p}=D();if(p)return(0,u.jsx)(Se,{title:`Sort by`,rows:o===`radio`?3:1,collapsible:i,startCollapsed:a});if(!s||s.length===0)return null;let m=c?`${c}:${l?`asc`:`desc`}`:`none`,h=e?e.filter(e=>s.includes(e.field)?!0:(console.warn(`[SortByPanel] '${e.field}' is not sortable, so "${e.label}" is left out. Mark the field Sortable in the dataset's field configuration.`),!1)).map(e=>({label:e.label,value:`${e.field}:${e.ascending?`asc`:`desc`}`})):s.flatMap(e=>[{label:`${e} (asc)`,value:`${e}:asc`},{label:`${e} (desc)`,value:`${e}:desc`}]),g=t===null?h:[{label:t,value:`none`},...h],_=e=>{if(e===`none`||e===``)f(null,!0);else{let[t,n]=e.split(`:`);f(t,n===`asc`)}};return(0,u.jsx)(d.FilterPanelBase,{title:`Sort by`,collapsible:i,collapsed:i?a:!1,children:o===`select`?(0,u.jsx)(d.Select,{value:m,onValueChange:_,options:g,placeholder:`Select sort...`,"aria-label":`Sort by`}):(0,u.jsx)(`div`,{className:Ie.radioGroup,children:g.map(e=>(0,u.jsx)(d.RadioButton,{id:`sort-${e.value}`,name:`sort-by`,value:e.value,label:e.label,checked:m===e.value,onChange:e=>_(e.target.value)},e.value))})})},Re={list:`_list_1y4fk_1`},ze={tolerance:l.Tolerance.TwoEdits,rungs:l.Rungs.Fewest,oneEditFrom:3,twoEditsFrom:6,threeEditsFrom:9,typingPrefixFrom:3,typingPrefixOneEditFrom:6,joinedWords:!0},Be={candidatesPerRow:4,fallback:!0,rest:!1},Ve={rerank:!0,share:.2,typingShift:.5,wholeQueryFloor:!0};function He(){let{state:{searchSettings:e},setSearchSettings:t,url:n,team:r,dataset:i,authenticatedFetch:a}=D(),[o,s]=(0,c.useState)(!1),{match:p,candidates:m,ranking:h}=e,[g,_]=(0,c.useState)(null);(0,c.useEffect)(()=>{let e=!0;try{a(`${n}/api/teams/${r}/datasets/${i}/query-parameters`).then(e=>e.ok?e.json():null).then(t=>{e&&t?.effective&&_(t.effective)}).catch(()=>{})}catch{}return()=>{e=!1}},[n,r,i,a]);let v=e=>Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!=null)),y={...ze,...v(g?.match)},b={...Be,...v(g?.candidates)},x={...Ve,...v(g?.ranking)},S=e.mode??g?.mode??l.SearchMode.EditDistance,C=S===l.SearchMode.Bm25f,w=h.rerank??x.rerank,T=C&&!w,E=e.mode!==void 0||[p,m,h].some(e=>Object.values(e??{}).some(e=>e!=null)),O=(e,n)=>{let r=parseInt(n,10);isNaN(r)||t({[e]:r})},k=(e,n)=>{t({[e]:n})},A=e=>t({match:e}),j=e=>t({candidates:e}),M=e=>t({ranking:e}),N=(e,t)=>{let n=parseInt(e,10);isNaN(n)||t(n)},P=(e,t)=>{let n=parseFloat(e);isNaN(n)||t(Math.max(0,Math.min(100,n))/100)};return(0,u.jsx)(d.FilterPanelBase,{collapsed:!0,title:`Settings`,children:(0,u.jsxs)(`ul`,{className:Re.list,children:[(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Select,{label:`Mode`,size:`micro`,value:S,onValueChange:e=>t({mode:e}),options:[{label:`Edit distance`,value:l.SearchMode.EditDistance},{label:`BM25F`,value:l.SearchMode.Bm25f}]})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Rerank (Coverage)`,checked:w,onChange:e=>M({rerank:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Max Results`,type:`number`,value:e.maxNumberOfRecordsToReturn.toString(),onChange:e=>O(`maxNumberOfRecordsToReturn`,e.target.value)})}),(0,u.jsxs)(`li`,{children:[(0,u.jsx)(d.InputField,{label:`Minimum Score (16 bit)`,type:`number`,value:e.minimumScore.toString(),min:`0`,max:`65535`,onChange:e=>{let n=parseFloat(e.target.value);isNaN(n)||t({minimumScore:n})}}),(0,u.jsx)(`div`,{style:{padding:`10px 10px 20px 10px`},children:(0,u.jsx)(d.Slider,{min:0,max:65535,step:1,value:Math.max(0,Math.min(65535,Math.round(e.minimumScore))),onChange:e=>{t({minimumScore:e})},"aria-label":`Minimum score`})})]}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Placeholder text`,type:`text`,value:e.placeholderText,onChange:e=>{t({placeholderText:e.target.value})}})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Show score`,checked:e.showScore,onChange:e=>k(`showScore`,e)})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,iconRight:o?(0,u.jsx)(f.ArrowDown,{}):(0,u.jsx)(f.ArrowRight,{}),onClick:()=>s(e=>!e),children:o?`Hide Match, Candidates and Ranking`:`Show Match, Candidates and Ranking`})}),o&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Select,{label:`Tolerance`,size:`micro`,disabled:C,value:p.tolerance??y.tolerance,onValueChange:e=>A({tolerance:e}),options:[{label:`Exact`,value:l.Tolerance.Exact},{label:`One edit`,value:l.Tolerance.OneEdit},{label:`Two edits`,value:l.Tolerance.TwoEdits},{label:`Three edits`,value:l.Tolerance.ThreeEdits}]})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Every rung`,disabled:C,checked:(p.rungs??y.rungs)===l.Rungs.All,onChange:e=>A({rungs:e?l.Rungs.All:l.Rungs.Fewest})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`One edit from`,type:`number`,disabled:C,value:(p.oneEditFrom??y.oneEditFrom).toString(),onChange:e=>N(e.target.value,e=>A({oneEditFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Two edits from`,type:`number`,disabled:C,value:(p.twoEditsFrom??y.twoEditsFrom).toString(),onChange:e=>N(e.target.value,e=>A({twoEditsFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Three edits from`,type:`number`,disabled:C,value:(p.threeEditsFrom??y.threeEditsFrom).toString(),onChange:e=>N(e.target.value,e=>A({threeEditsFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Typing prefix from`,type:`number`,disabled:C,value:(p.typingPrefixFrom??y.typingPrefixFrom).toString(),onChange:e=>N(e.target.value,e=>A({typingPrefixFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Joined words`,disabled:C,checked:p.joinedWords??y.joinedWords,onChange:e=>A({joinedWords:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Candidates per row`,type:`number`,disabled:T,value:(m.candidatesPerRow??b.candidatesPerRow).toString(),onChange:e=>N(e.target.value,e=>j({candidatesPerRow:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Max candidates (0: per row)`,type:`number`,disabled:T,value:(m.maxCandidates??0).toString(),onChange:e=>N(e.target.value,e=>j({maxCandidates:e>0?e:null}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Fallback (most words when none holds every word)`,disabled:C,checked:m.fallback??b.fallback,onChange:e=>j({fallback:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Rest (BM25F below the counted set)`,disabled:C,checked:m.rest??b.rest,onChange:e=>j({rest:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Coverage share %`,type:`number`,disabled:!w,value:Math.round((h.share??x.share)*100).toString(),onChange:e=>P(e.target.value,e=>M({share:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Typing shift %`,type:`number`,disabled:!w,value:Math.round((h.typingShift??x.typingShift)*100).toString(),onChange:e=>P(e.target.value,e=>M({typingShift:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Whole query floor`,disabled:!w,checked:h.wholeQueryFloor??x.wholeQueryFloor,onChange:e=>M({wholeQueryFloor:e})})}),E&&(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:()=>t({mode:void 0,match:void 0,candidates:void 0,ranking:void 0}),children:`Use the dataset's values`})})]})]})})}var Ue=class extends c.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[SearchErrorBoundary] Caught error:`,e,t)}reset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback(this.state.error,this.reset):(0,u.jsxs)(`div`,{style:{padding:`2rem`,backgroundColor:`#fee`,border:`2px solid #c33`,borderRadius:`8px`,maxWidth:`600px`,margin:`2rem auto`},children:[(0,u.jsx)(`h2`,{style:{color:`#c33`,marginTop:0},children:`⚠️ Search Initialization Error`}),(0,u.jsxs)(`p`,{style:{marginBottom:`1rem`},children:[(0,u.jsx)(`strong`,{children:`Error:`}),` `,this.state.error.message]}),(0,u.jsxs)(`div`,{style:{backgroundColor:`#fff`,padding:`1rem`,borderRadius:`4px`,marginBottom:`1rem`,fontSize:`0.9rem`},children:[(0,u.jsx)(`strong`,{children:`💡 Common fixes:`}),(0,u.jsxs)(`ul`,{style:{marginBottom:0,paddingLeft:`1.5rem`},children:[(0,u.jsx)(`li`,{children:`Check browser console for detailed error messages`}),(0,u.jsx)(`li`,{children:`Verify the url passed to SearchProvider is correct`}),(0,u.jsx)(`li`,{children:`Verify your bearer token is valid (create or check it on the Indx Dashboard)`}),(0,u.jsx)(`li`,{children:`Ensure INDX server is running`}),(0,u.jsx)(`li`,{children:`Check dataset name spelling`})]})]}),(0,u.jsx)(d.Button,{variant:`primary`,size:`micro`,onClick:this.reset,children:`Try Again`})]}):this.props.children}};function We(e,t){let{url:n,team:r,dataset:i,authenticatedFetch:a}=D(),[o,s]=(0,c.useState)(null),[l,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(void 0),m=(0,c.useRef)(0);return(0,c.useEffect)(()=>()=>{m.current++},[n,r,i]),{results:o,isLoading:l,error:d,search:(0,c.useCallback)(async o=>{let c=++m.current,l=()=>c===m.current;u(!0),f(void 0);try{let c=await e(o),u={fieldName:t.fieldName,vector:c,maxResults:t.maxResults??10};t.filter&&(u.filter=t.filter);let d=await a(`${n}/api/teams/${r}/datasets/${i}/search/vector`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u)});if(!d.ok)throw await p.fromResponse(`VectorSearch`,d);let f=await d.json();if(!l())return;if(f.length===0){s([]);return}let m=f.map(e=>e.documentKey),h=await a(`${n}/api/teams/${r}/datasets/${i}/documents/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(m)});if(!h.ok)throw await p.fromResponse(`GetJson`,h);let g=await h.json();if(!l())return;s(g.map((e,t)=>({document:e,documentKey:m[t],score:f[t].score})))}catch(e){if(!l())return;f(e instanceof Error?e.message:`Vector search failed`),s(null)}finally{l()&&u(!1)}},[e,t.fieldName,t.maxResults,t.filter,n,r,i,a])}}function Ge(e,t){let{url:n,team:r,dataset:i,authenticatedFetch:a}=D(),[o,s]=(0,c.useState)(null),[l,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(void 0),m=(0,c.useRef)(0);return(0,c.useEffect)(()=>()=>{m.current++},[n,r,i]),{results:o,isLoading:l,error:d,search:(0,c.useCallback)(async o=>{let c=++m.current,l=()=>c===m.current;u(!0),f(void 0);try{let c=await e(o),u={text:o,embeddingField:t.fieldName,vector:c,maxNumberOfRecordsToReturn:t.maxResults??10,alpha:t.alpha??.5};t.filter&&(u.filter=t.filter),t.timeoutMs&&(u.timeOutLimitMilliseconds=t.timeoutMs);let d=await a(`${n}/api/teams/${r}/datasets/${i}/search/hybrid`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u)});if(!d.ok)throw await p.fromResponse(`HybridSearch`,d);let f=await d.json();if(!l())return;if(f.length===0){s([]);return}let m=f.map(e=>e.documentKey),h=await a(`${n}/api/teams/${r}/datasets/${i}/documents/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(m)});if(!h.ok)throw await p.fromResponse(`GetJson`,h);let g=await h.json();if(!l())return;s(g.map((e,t)=>({document:e,documentKey:m[t],score:f[t].score})))}catch(e){if(!l())return;f(e instanceof Error?e.message:`Hybrid search failed`),s(null)}finally{l()&&u(!1)}},[e,t.fieldName,t.alpha,t.maxResults,t.filter,t.timeoutMs,n,r,i,a])}}var Ke={question:``,status:`idle`,answer:``,sources:[],steps:[]};function qe(){let e=D(),{url:t,team:n,dataset:r,authenticatedFetch:i}=e,a=(0,c.useRef)(e);a.current=e;let[o,s]=(0,c.useState)(Ke),l=(0,c.useRef)(o);l.current=o;let u=(0,c.useRef)(null),d=(0,c.useCallback)(async(e,o=[],c={})=>{let l=e.trim();if(!l)return;u.current?.abort();let d=new AbortController;u.current=d,s({question:l,status:`searching`,answer:``,sources:[],steps:[]});let f=``,p=null,m=()=>{p=null;let e=f;s(t=>t.answer===e?t:{...t,answer:e})},h=()=>{p!==null&&(cancelAnimationFrame(p),p=null),m()},g=(e,t)=>s(n=>({...n,status:`error`,error:{code:e,message:t}}));try{let e=await i(`${t}/api/teams/${n}/datasets/${r}/search-or-ask/ask${R(a.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`text/event-stream`},body:JSON.stringify({question:l,...o.length?{history:o}:{},...c.proactive?{proactive:!0}:{}}),signal:d.signal});if(e.status===429){let t=await e.json().catch(()=>({}));if(c.proactive){s(Ke);return}let n=Number(e.headers.get(`Retry-After`));s(e=>({...e,status:`limited`,limit:t.code===`searchOrAskBudgetSpent`?`budget`:`address`,retryAfterSeconds:t.retryAfterSeconds??(Number.isFinite(n)?n:void 0)}));return}let u=e.headers.get(`Indx-Ask-Id`)??void 0;if(u&&s(e=>({...e,askId:u})),!e.ok||!e.body){let t=await e.json().catch(()=>({}));if(c.proactive){s(Ke);return}let n=e.status===409||e.status===404;g(t.code??`http${e.status}`,n?`Answers are not available here right now. Search still works.`:`The question could not be asked.`);return}for await(let{event:t,data:n}of L(e.body))switch(t){case`status`:{let e=n.step;e&&s(t=>({...t,steps:[...t.steps,e]}));break}case`filters`:s(e=>({...e,filters:n}));break;case`picks`:s(e=>({...e,picks:{...n,askId:e.askId}}));break;case`sources`:s(e=>({...e,status:`writing`,sources:n}));break;case`text`:f||s(e=>e.status===`searching`?{...e,status:`writing`}:e),f+=n.delta,p??=requestAnimationFrame(m);break;case`done`:h(),s(e=>({...e,status:`answered`}));return;case`error`:{h();let e=n;g(e.code,e.message);return}}h(),d.signal.aborted||g(`dropped`,`The connection dropped while the answer was being written.`)}catch(e){if(u.current!==d)return;h(),e.name===`AbortError`?s(e=>e.answer?{...e,status:`answered`}:{...e,status:`idle`}):g(`dropped`,`The connection dropped while the answer was being written.`)}finally{u.current===d&&(u.current=null)}},[t,n,r,i]),f=(0,c.useCallback)(async(e,o)=>{let s=o??l.current.askId;if(s)try{await i(`${t}/api/teams/${n}/datasets/${r}/events/select`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({queryId:s,documentKey:e.documentKey,position:e.n,...a.current.count===!1?{count:!1}:{}})})}catch{}},[t,n,r,i]),p=(0,c.useCallback)(()=>u.current?.abort(),[]),m=(0,c.useCallback)(()=>{u.current?.abort(),s(Ke)},[]);return(0,c.useEffect)(()=>()=>u.current?.abort(),[]),{...o,ask:d,stop:p,reset:m,openSource:f,busy:o.status===`searching`||o.status===`writing`}}var $={panel:`_panel_gjc13_1`,thread:`_thread_gjc13_4`,fill:`_fill_gjc13_5`,answer:`_answer_gjc13_8`,paragraph:`_paragraph_gjc13_9`,action:`_action_gjc13_10`,turn:`_turn_gjc13_11`,heading:`_heading_gjc13_14`,list:`_list_gjc13_15`,inlineCode:`_inlineCode_gjc13_16`,codeBlock:`_codeBlock_gjc13_17`,searched:`_searched_gjc13_22`,searchedLabel:`_searchedLabel_gjc13_23`,steps:`_steps_gjc13_26`,stepDone:`_stepDone_gjc13_27`},Je=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\n]+\*|_[^_\n]+_)|(\[[^\]\n]+\]\(https?:\/\/[^)\s]+\))|(\[\d+\])/g;function Ye(e,t,n){let r=[],i=0,a=0;for(let o of e.matchAll(Je)){o.index>i&&r.push(e.slice(i,o.index));let s=`${n}-${a++}`,[l,d,f,p,m,h]=o;if(d)r.push((0,u.jsx)(`code`,{className:$.inlineCode,children:d.slice(1,-1)},s));else if(f)r.push((0,u.jsx)(`strong`,{children:Ye(f.slice(2,-2),t,s)},s));else if(p)r.push((0,u.jsx)(`em`,{children:Ye(p.slice(1,-1),t,s)},s));else if(m){let[,e,t]=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(m);r.push((0,u.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e},s))}else h?r.push((0,u.jsx)(c.default.Fragment,{children:t(Number(h.slice(1,-1)))},s)):r.push(l);i=o.index+l.length}return i<e.length&&r.push(e.slice(i)),r}function Xe(e){let t=e.replace(/\r\n/g,`
5
+ `))})}}}finally{t.releaseLock()}}function R(e){let t=new URLSearchParams;e.state.queryId&&t.set(`queryId`,e.state.queryId),e.sessionId&&t.set(`session`,e.sessionId),e.source&&t.set(`source`,e.source),e.count===!1&&t.set(`count`,`false`);let n=t.toString();return n?`?${n}`:``}function z(e){return{...k,...e,hint:e?.hint??k.hint,finished:e?.finished??k.finished,found:e?.found??k.found,refocus:e?.refocus??k.refocus}}var B=.1,V={available:!1,offer:`none`,p:null,answerable:null,text:``,criteria:null,describes:!1,found:null,notFound:!1,held:!1,strictCoverage:!1,refocus:!1,filtersWhileTyping:`off`,mode:`soft`,askAnytime:!1,finished:null,answerNow:null,quick:`none`,stands:!1};function H(e={}){let{enabled:t=!0,pauseMs:n=300,prefetch:r=!0,mode:i,answerAfterMs:a=1e3}=e,o=D(),{url:s,team:l,dataset:u,authenticatedFetch:d,isFetchingInitial:f,authError:p,state:m}=o,h=(0,c.useRef)(o);h.current=o;let g=(e.text??m.query).trim(),[_,v]=(0,c.useState)(!1),[y,b]=(0,c.useState)(V),x=(0,c.useRef)(k),S=(0,c.useRef)(!0),C=(0,c.useRef)(`off`),w=(0,c.useRef)(`soft`),T=(0,c.useRef)(i);T.current=i;let E={get current(){return O(w.current,T.current)}},A=(0,c.useRef)(null),L=(0,c.useRef)(`none`),H=(0,c.useRef)(``),U=(0,c.useRef)(0),W=(0,c.useRef)(0);L.current=y.offer;let G=(0,c.useRef)(null),K=(0,c.useRef)(new Set),q=(0,c.useRef)(0),ee=(0,c.useRef)(g);ee.current=g;let te=(0,c.useRef)(!1);te.current=_;let[J,Y]=(0,c.useState)(0);(0,c.useEffect)(()=>{if(!J)return;let e=setTimeout(()=>Y(0),Math.max(0,J-Date.now()));return()=>clearTimeout(e)},[J]);let ne=`${s}/api/teams/${l}/datasets/${u}/search-or-ask`,re=()=>E.current===`inviting`||E.current===`proactive`?3:4,ie=e=>e!=null&&e>=(x.current.finished??.5),ae=e=>E.current!==`proactive`&&L.current===`strong`&&!!H.current&&e.startsWith(H.current),X=t&&!f&&!p;(0,c.useEffect)(()=>{if(v(!1),!X)return;let e=!1;return(async()=>{try{let t=await d(ne);if(!t.ok)return;let n=await t.json();if(e||!n.available||!n.settings?.enabled)return;C.current=n.settings.filtersWhileTyping??`off`,w.current=n.settings.mode??`soft`,x.current=z(n.settings.thresholds),S.current=n.settings.strictCoverageWhileAsking??!0,v(!0)}catch{}})(),()=>{e=!0}},[X,ne,d]);let oe=(0,c.useRef)(()=>{});oe.current=e=>{if(!r||!te.current||G.current||!e||!N(e,re())||K.current.has(e)||ae(e)||Date.now()<W.current||Date.now()<q.current)return;let t=(async()=>{try{let t=await d(`${ne}/intent`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e,prefetch:!0})});if(t.status===429){let e=Number(t.headers.get(`Retry-After`));q.current=Date.now()+(Number.isFinite(e)&&e>0?e:60)*1e3;return}t.ok&&(K.current.size>200&&K.current.clear(),K.current.add(e))}catch{}})();G.current={text:e,done:t},t.then(()=>{G.current?.done===t&&(G.current=null),ee.current!==e&&oe.current(ee.current)})},(0,c.useEffect)(()=>{if(!_){b(V);return}if(!g){H.current=``,b({...V,available:_});return}if(!N(g,re())){j(g)&&b(e=>({...e,available:_,offer:`none`,text:g}));return}oe.current(g);let e=!1,t=setTimeout(async()=>{if(ae(g)){b(e=>({...e,text:g}));return}if(Date.now()<W.current||(G.current?.text===g&&await G.current.done,e))return;let t=++U.current;H.current=g;try{let e=await d(`${ne}/intent${R(h.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:g})});if(e.status===429){let n=Number(e.headers.get(`Retry-After`));W.current=Date.now()+(Number.isFinite(n)&&n>0?n:60)*1e3;let{code:r}=await e.json().catch(()=>({}));r===`searchOrAskBudgetSpent`&&t===U.current&&(Y(W.current),b(e=>({...e,offer:`none`,answerNow:null,strictCoverage:!1,refocus:!1,notFound:!1})));return}if(e.status===409||e.status===404){v(!1);return}if(!e.ok)return;let{p:n,answerable:r,criteria:i,finished:a,found:o,reason:s,thresholds:c,strictCoverageWhileAsking:l,filtersWhileTyping:u,mode:f,refocus:p}=await e.json();if(u!=null&&(C.current=u),t!==U.current)return;l!=null&&(S.current=l),f!=null&&(w.current=f),c&&(x.current=z(c)),b(e=>{let t=P(e.offer,n,x.current),c=i??null,l=c!=null&&c>=x.current.strong,u=e.offer===`strong`&&!!e.text&&g.startsWith(e.text)||I(g)&&(a==null||ie(a)),d=l&&u?`strong`:l||t===`strong`&&!u?`invite`:t,f=E.current===`strict`&&d===`invite`?`none`:d,m=f===`strong`&&!(l&&c>n),h=o??null,_=x.current.found??0,v=x.current.refocus??0,y=e.refocus&&v>0&&!!e.text&&g.startsWith(e.text)&&Math.max(n,c??0)>=v-B;return{available:!0,offer:f,p:n,answerable:r??null,text:g,criteria:c,describes:l,found:h,notFound:m&&h!=null&&_>0&&h<_,held:s===`paused`,strictCoverage:S.current&&m,refocus:!!p||y,filtersWhileTyping:C.current,mode:E.current,askAnytime:!1,quick:`none`,finished:a??null,answerNow:E.current===`proactive`&&f===`strong`&&ie(a)?g:null,stands:!0}})}catch{}},n);return()=>{e=!0,clearTimeout(t)}},[g,_,ne,d,n]);let[Z,se]=(0,c.useState)(null);(0,c.useEffect)(()=>{se(null);let e=y.answerNow;if(!e||e!==g)return;let t=setTimeout(()=>se(e),Math.max(0,a-n));return()=>clearTimeout(t)},[y.answerNow,g,a,n]);let ce=_&&y.strictCoverage;(0,c.useEffect)(()=>{let{setSearchSettings:e,state:t}=h.current;if(ce){if(A.current)return;let n=t.searchSettings.match??{};A.current=Object.fromEntries(Object.keys(F).map(e=>[e,n[e]])),e({match:{...F}})}else A.current&&=(e({match:{...A.current}}),null)},[ce]);let le=_&&y.refocus&&!y.held&&J===0&&!!y.text&&g.startsWith(y.text);if((0,c.useEffect)(()=>{h.current.setSearchSettings({refocus:le})},[le]),!_)return V;let ue=E.current,de=!!y.text&&g.startsWith(y.text),fe=y.held||J>0;if(fe)return{...y,mode:ue,held:fe,offer:`none`,askAnytime:!1,answerNow:null,quick:`none`,notFound:!1,strictCoverage:!1,refocus:!1,stands:de};let pe=ue===`inviting`||ue===`proactive`,me=pe&&!!g&&(de&&y.p!=null&&y.p>=(x.current.hint??1)||M(g)),he=g?de&&y.offer===`strong`?ue===`proactive`?ie(y.finished)?`thinking`:`hint`:`ready`:de&&y.offer===`invite`?pe?`hint`:`invite`:me?`hint`:ue===`open`||pe?`ask`:`none`:`none`;return{...y,refocus:le,mode:ue,askAnytime:ue===`open`||pe,answerNow:Z!==null&&Z===g&&y.answerNow===g?Z:null,text:(he===`hint`||he===`ask`)&&!de?g:y.text,notFound:de&&y.notFound,quick:he,stands:de}}var U={row:`_row_epo6h_3`,icon:`_icon_epo6h_17`,line:`_line_epo6h_24`,text:`_text_epo6h_41`,question:`_question_epo6h_43`,actions:`_actions_epo6h_52`,enter:`_enter_epo6h_59`},W={invite:`Ask about this`,hint:`For a quick answer, type a bit more`,ready:`Ask the assistant`,thinking:`Thinking`,ask:`Ask`},G=({searchOrAsk:e,onAsk:t,labels:n,className:r=``})=>{let i={...W,...n},a=e.text.trim();if(!e.available||e.quick===`none`||!a)return null;let o=()=>t(a);return(0,u.jsxs)(`div`,{className:`${U.row} ${U[e.quick]} ${r}`,"aria-live":`polite`,children:[(0,u.jsx)(`span`,{className:U.icon,"aria-hidden":`true`,children:(0,u.jsx)(f.Ai_agent,{size:14,color:`currentColor`})}),e.quick===`thinking`&&(0,u.jsx)(d.ShimmerText,{className:U.text,children:i.thinking}),e.quick===`hint`&&(0,u.jsx)(`button`,{type:`button`,className:U.line,onClick:o,children:(0,u.jsx)(d.ShimmerText,{children:i.hint})}),e.quick===`invite`&&(0,u.jsx)(`button`,{type:`button`,className:U.line,onClick:o,children:i.invite}),e.quick===`ask`&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:U.question,children:a}),(0,u.jsxs)(`span`,{className:U.actions,children:[(0,u.jsxs)(`span`,{className:U.enter,children:[(0,u.jsx)(d.Kbd,{children:`↵`}),` to ask`]}),(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:o,children:i.ask})]})]}),e.quick===`ready`&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`span`,{className:U.question,children:a}),(0,u.jsxs)(`span`,{className:U.actions,children:[(0,u.jsxs)(`span`,{className:U.enter,children:[(0,u.jsx)(d.Kbd,{children:`↵`}),` to ask`]}),(0,u.jsx)(d.Button,{variant:`primary`,size:`micro`,onClick:o,children:i.ready})]})]})]})},K={grid:`_grid_1xjna_2`,chip:`_chip_1xjna_21`,chipLabel:`_chipLabel_1xjna_32`},q=(0,c.memo)(({field:e,value:t,onReset:n})=>(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:n,iconRight:(0,u.jsx)(f.X_or_error,{}),variant:`primary`,size:`micro`,className:K.chip,title:`${e}: ${t}`,children:(0,u.jsxs)(`span`,{className:K.chipLabel,children:[e,`: `,t]})})})),ee=(0,c.memo)(({field:e,min:t,max:n,onReset:r})=>(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:r,iconRight:(0,u.jsx)(f.X_or_error,{}),variant:`primary`,size:`micro`,className:K.chip,title:`${e}: ${t} – ${n}`,children:(0,u.jsxs)(`span`,{className:K.chipLabel,children:[e,`: `,t,` – `,n]})})})),te=(0,c.memo)(({field:e,label:t,onReset:n})=>(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:n,iconRight:(0,u.jsx)(f.X_or_error,{}),variant:`primary`,size:`micro`,className:K.chip,title:`${e}: ${t}`,children:(0,u.jsxs)(`span`,{className:K.chipLabel,children:[e,`: `,t]})})}));function J(){let{state:{filters:e,rangeFilters:t,bucketFilters:n},resetFilters:r,resetSingleFilter:i,resetRangeFilter:a,resetBucketFilter:o}=D(),s=(0,c.useMemo)(()=>Object.entries(e).map(([e,t])=>t.map(t=>({field:e,value:t}))).flat(),[e]),l=(0,c.useMemo)(()=>Object.entries(t).map(([e,{min:t,max:n}])=>({field:e,min:t,max:n})),[t]),f=(0,c.useMemo)(()=>Object.entries(n).flatMap(([e,t])=>t.map(t=>({field:e,range:t,label:`${t.min}-${t.max}`}))),[n]);return(0,c.useMemo)(()=>Object.keys(e).length>0||Object.keys(t).length>0||f.length>0,[e,t,f])?(0,u.jsx)(d.FilterPanelBase,{collapsible:!1,title:`Active filters`,children:(0,u.jsxs)(`ul`,{className:K.grid,children:[s.map(({field:e,value:t})=>(0,u.jsx)(q,{field:e,value:t,onReset:()=>i(e,t)},`${e}-${t}`)),l.map(({field:e,min:t,max:n})=>(0,u.jsx)(ee,{field:e,min:t,max:n,onReset:()=>a(e)},e)),f.map(({field:e,range:t,label:n})=>(0,u.jsx)(te,{field:e,label:n,onReset:()=>o(e,t)},`${e}-${t.min}-${t.max}`)),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{onClick:r,size:`micro`,variant:`ghost`,children:`Reset`})})]})}):null}var Y={withOffer:`_withOffer_1zrln_2`,offerRow:`_offerRow_1zrln_10`,offerHint:`_offerHint_1zrln_18`,kbd:`_kbd_1zrln_27`,askStrong:`_askStrong_1zrln_42`,thinking:`_thinking_1zrln_45`,offerQuick:`_offerQuick_1zrln_56`,filterChip:`_filterChip_1zrln_59`,filtersPopover:`_filtersPopover_1zrln_63`},ne=({className:e=``,autoFocus:t=!1,inputSize:n=`default`,showClear:r=!0,showFocus:i=!1,showStatus:a=!0,onAsk:o,searchOrAsk:s,askOffer:l=`chip`,onKeyDown:p,...m})=>{let{state:{query:h,filters:g,rangeFilters:_,bucketFilters:v,results:y,isFallback:b,searchSettings:x},setQuery:S,resetFilters:C,picks:w,showPicks:T}=D(),E=!!w,O=Object.values(g).reduce((e,t)=>e+t.length,0)+Object.keys(_).length+Object.values(v??{}).reduce((e,t)=>e+t.length,0),k=h.length>0,A=k&&!E&&y!==null&&y.length===0,j=k&&!E&&y!==null&&y.length>0&&b===!0,M=H({enabled:!!o&&!s}),N=s??M,P=N.quick===`ready`||N.askAnytime,F=c.default.useRef(null);c.default.useEffect(()=>{let e=N.answerNow;o&&e&&e===h.trim()&&F.current!==e&&(F.current=e,o(e,{proactive:!0}))},[N.answerNow,h,o]);let I=F.current!==null&&F.current===h.trim(),L=!o||!k||I?`none`:N.quick,R=N.available&&x.placeholderText===`Type to search`?`Search or ask`:x.placeholderText,z=e=>{p?.(e),!e.defaultPrevented&&e.key===`Enter`&&o&&P&&h.trim()&&(e.preventDefault(),W())},[B,V]=c.default.useState(!1);c.default.useEffect(()=>{O===0&&V(!1)},[O]);let U=()=>{T?.(null),S(``),O>0&&C()},W=()=>{F.current=h.trim(),o(h.trim())},K=(0,u.jsxs)(d.SearchField,{type:`text`,value:h,onChange:e=>S(e.target.value),placeholder:R,autoFocus:t,className:e,showSearchIcon:!0,inputSize:n,showFocusBorder:i,clearable:!1,onKeyDown:z,...m,children:[l===`chip`&&L===`thinking`&&(0,u.jsxs)(`span`,{className:Y.thinking,"aria-live":`polite`,children:[(0,u.jsx)(f.Ai_agent,{}),(0,u.jsx)(d.ShimmerText,{children:`Thinking`})]}),l===`chip`&&(L===`ready`||L===`invite`||L===`hint`||L===`ask`)&&(0,u.jsx)(d.Button,{variant:L===`ready`?`primary`:`ghost`,className:L===`ready`?Y.askStrong:void 0,size:`micro`,iconLeft:(0,u.jsx)(f.Ai_agent,{}),iconRight:L===`ready`?(0,u.jsx)(d.Kbd,{children:`Enter ↵`}):void 0,onClick:W,title:P?`Enter asks`:void 0,children:L===`ready`?`Ask`:L===`hint`?(0,u.jsx)(d.ShimmerText,{children:`For a quick answer, type a bit more`}):L===`invite`?`Ask about this`:`Ask`}),a&&A&&(0,u.jsx)(d.Chip,{children:`No results`}),a&&j&&(0,u.jsx)(d.Tooltip,{content:`No direct match. Showing the nearest results.`,children:(0,u.jsx)(`span`,{children:(0,u.jsx)(d.Chip,{icon:(0,u.jsx)(f.Fuzzy_search,{}),children:`Nearest`})})}),a&&O>0&&(0,u.jsx)(d.Popover,{open:B,onOpenChange:V,align:`end`,sideOffset:6,className:Y.filtersPopover,"aria-label":`Active filters`,trigger:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,className:Y.filterChip,"aria-label":`${O} filter${O===1?``:`s`} active: show them`,title:`${O} filter${O===1?``:`s`} active`,children:(0,u.jsx)(d.Chip,{icon:(0,u.jsx)(f.Filter,{}),color:`var(--CLightBlue)`,textColor:`#080809`,children:O})}),children:(0,u.jsx)(J,{})}),r&&(k||O>0)&&(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:U,"aria-label":O>0?`Clear search and filters`:`Clear search`,children:`Clear`})]});return l!==`below`||!o||!N.available?K:(0,u.jsxs)(`div`,{className:Y.withOffer,children:[K,(0,u.jsx)(`div`,{className:Y.offerRow,children:!I&&(0,u.jsx)(G,{searchOrAsk:N,onAsk:W,className:Y.offerQuick})})]})},re={message:`_message_1mgfk_1`,icon:`_icon_1mgfk_10`,title:`_title_1mgfk_15`,detail:`_detail_1mgfk_20`,technical:`_technical_1mgfk_25`,button:`_button_1mgfk_33`},ie={unreachable:{icon:f.Cloud,title:`Search is unavailable`,detail:`The search server can’t be reached right now.`},unauthorized:{icon:f.Key,title:`Search is unavailable`,detail:`The search key was not accepted.`},forbidden:{icon:f.Lock,title:`Search is unavailable`,detail:`This search key doesn’t have access to these results.`},notFound:{icon:f.Search,title:`Nothing to search here`,detail:`The collection this page searches doesn’t exist.`},notReady:{icon:f.Hour_glass,title:`Search is getting ready`,detail:`Results will appear in a moment.`},unavailable:{icon:f.Warning,title:`Search is unavailable`,detail:`The collection can’t be searched right now.`},rateLimited:{icon:f.Speedometer,title:`Too many searches`,detail:`Wait a moment, then try again.`},server:{icon:f.Warning,title:`Something went wrong`,detail:`The search server ran into a problem.`},setup:{icon:f.Warning,title:`Search isn’t set up`,detail:`This page is missing part of its search setup.`},unknown:{icon:f.Warning,title:`Something went wrong`,detail:`The search couldn’t be completed.`}},ae=({error:e,onRetry:t,hideTechnical:n=!1})=>{let{icon:r,title:i,detail:a}=ie[e.kind];(0,c.useEffect)(()=>{if(e.kind!==`notReady`||!t)return;let n=setTimeout(t,(e.retryAfterSeconds??2)*1e3);return()=>clearTimeout(n)},[e,t]);let o=e.retryable&&e.kind!==`notReady`&&t;return(0,u.jsxs)(`div`,{className:re.message,role:`alert`,children:[(0,u.jsx)(`span`,{className:re.icon,children:(0,u.jsx)(r,{size:70,color:`var(--lv4)`})}),(0,u.jsx)(`div`,{className:re.title,children:i}),(0,u.jsx)(`div`,{className:re.detail,children:a}),!n&&(0,u.jsx)(`code`,{className:re.technical,children:e.technical}),o&&(0,u.jsx)(d.Button,{variant:`secondary`,size:`micro`,className:re.button,onClick:t,children:`Try again`})]})},X={placeholder:`_placeholder_1m5kj_1`,invalid:`_invalid_1m5kj_11`,searchedFor:`_searchedFor_1m5kj_17`,notFound:`_notFound_1m5kj_21`,dimmed:`_dimmed_1m5kj_22`,picksHead:`_picksHead_1m5kj_25`,picksTitle:`_picksTitle_1m5kj_26`,picksCount:`_picksCount_1m5kj_27`,picksSpacer:`_picksSpacer_1m5kj_28`,why:`_why_1m5kj_29`},oe={row:`_row_11svi_1`,content:`_content_11svi_22`,indexNumber:`_indexNumber_11svi_36`,scoreNumber:`_scoreNumber_11svi_44`,skeletonBars:`_skeletonBars_11svi_53`},Z=({skeleton:e=!1,index:t,score:n,showScore:r=!1,children:i,skeletonDelay:a=0,skeletonWidths:o=[62,38]})=>(0,u.jsxs)(`div`,{className:oe.row,children:[t!==void 0&&(0,u.jsx)(`div`,{className:oe.indexNumber,children:t}),(0,u.jsx)(`div`,{className:oe.content,children:e?(0,u.jsxs)(`div`,{className:oe.skeletonBars,children:[(0,u.jsx)(d.Skeleton,{level:3,height:12,width:`${o[0]}%`,delay:a,appear:!1}),(0,u.jsx)(d.Skeleton,{level:3,height:8,width:`${o[1]}%`,delay:a+.05,appear:!1})]}):i}),r&&n!==void 0&&(0,u.jsx)(`div`,{className:oe.scoreNumber,children:n})]}),se={wrapper:`_wrapper_f970z_6`,skeletonAppear:`_skeletonAppear_f970z_1`},ce=[[62,38],[75,45],[58,33],[70,42],[65,50],[55,35],[72,40],[60,30]],le=({rows:e=6})=>(0,u.jsx)(`div`,{className:se.wrapper,children:Array.from({length:e}).map((e,t)=>(0,u.jsx)(Z,{skeleton:!0,skeletonDelay:t*.1,skeletonWidths:ce[t%ce.length]},t))});function ue(e){let t=e.trim().toLowerCase();return t===`true`||t===`false`||t!==``&&!Number.isNaN(Number(t))}function de(e,t){if(!t)return null;let n=[];for(let[e,r]of Object.entries(t))for(let t of r??[])t?.key&&t.key.trim().length>=2&&!ue(t.key)&&n.push({field:e,value:t.key});n.sort((e,t)=>t.value.length-e.value.length);let r=` `+e.toLowerCase()+` `,i=[];for(let e of n){let t=` `+e.value.toLowerCase().trim()+` `,n=r.indexOf(t);n<0||(i.push({field:e.field,value:e.value}),r=r.slice(0,n)+` `+r.slice(n+t.length))}return i.length===0?null:{filters:i,text:r.replace(/[?!.,]+\s*$/,``).replace(/\s+/g,` `).trim(),sort:null}}function fe(e={}){let t=D(),{url:n,team:r,dataset:i,authenticatedFetch:a,setQuery:o,toggleFilter:s,setRangeFilter:l,setSort:u}=t,{auto:d}=e,f=(0,c.useRef)(t);f.current=t;let[p,m]=(0,c.useState)(null),[h,g]=(0,c.useState)(``),[_,v]=(0,c.useState)(!1),y=(0,c.useRef)(0),b=(0,c.useCallback)(async e=>{let t=++y.current;v(!0);try{let o=await a(`${n}/api/teams/${r}/datasets/${i}/search-or-ask/filters${R(f.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e})});if(t!==y.current)return;let s=o.ok?await o.json():null;m(s&&s.filters.length>0?s:null),g(e)}catch{t===y.current&&m(null)}finally{t===y.current&&v(!1)}},[n,r,i,a]),x=(0,c.useCallback)(e=>{o(e.text);let t={...f.current.state.rangeBounds,...f.current.datasetBounds};for(let n of e.filters)n.value==null?l(n.field,n.min??t[n.field]?.min??0,n.max??t[n.field]?.max??2**53-1):s(n.field,n.value);e.sort&&u(e.sort.field,!e.sort.descending),m(null)},[o,s,l,u]),S=(0,c.useCallback)(()=>{y.current++,m(null),v(!1)},[]),C=(0,c.useRef)(new Set),[w,T]=(0,c.useState)(null),E=d?.filtersWhileTyping??`off`,O=!!d&&d.available&&d.describes&&d.offer===`strong`&&E!==`off`,k=d?.text??``,A=(0,c.useRef)(k);A.current=k;let j=t.state.facets,M=t.state.isLoading||t.facetsEnabled&&j==null;return(0,c.useEffect)(()=>{if(!O||!k||M||C.current.has(k))return;C.current.add(k);let e=de(k,j);if(e&&(C.current.add(e.text),x(e),T(k)),E!==`model`)return;let t=e?e.text:k;if(!t)return;let o=()=>A.current===k||A.current===t;(async()=>{let s=++y.current;v(!0);try{let c=await a(`${n}/api/teams/${r}/datasets/${i}/search-or-ask/filters${R(f.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t})});if(s!==y.current||!o())return;let l=c.ok?await c.json():null;l&&l.filters.length>0&&(C.current.add(l.text),x({filters:[...e?.filters??[],...l.filters],text:l.text,sort:l.sort}),T(k))}catch{}finally{s===y.current&&v(!1)}})()},[O,k,E,M,j,x,n,r,i,a]),{suggestion:p,forText:h,loading:_,suggest:b,apply:x,clear:S,appliedText:w}}var pe=/^\[\s*(?:'[^']*'(?:\s*,\s*'[^']*')*)?\s*\]$/;function me(e){let t=e.trim();if(!t.startsWith(`[`)||!t.endsWith(`]`))return;try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(e=>String(e))}catch{}if(!pe.test(t))return;let n=[],r=/'([^']*)'/g,i;for(;(i=r.exec(t))!==null;)n.push(i[1]);return n}function he(e,t,n){let r;try{r=typeof e==`string`?JSON.parse(e):e}catch{return null}let i;if(t&&t.length>0){i={};for(let e of t)e in r&&(i[e]=r[e])}else i={...r};if(n)for(let e in i){let t=i[e];if(typeof t==`string`){let n=me(t);n&&(i[e]=n)}}return i}var ge=({picks:e,fields:t,parseArrayStrings:n,label:r,onShowSearch:i,children:a})=>{let{url:o,team:s,dataset:l,authenticatedFetch:p,count:m}=D(),[h,g]=(0,c.useState)(null);(0,c.useEffect)(()=>{let t=!1;g(null);let n=e.picks.map(e=>e.documentKey);return(async()=>{try{let e=await p(`${o}/api/teams/${s}/datasets/${l}/documents/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)}),r=e.ok?await e.json():[];t||g(new Map(n.map((e,t)=>[e,r[t]])))}catch{t||g(new Map)}})(),()=>{t=!0}},[e,o,s,l,p]);let _=(t,n)=>async()=>{if(e.askId)try{await p(`${o}/api/teams/${s}/datasets/${l}/events/select`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({queryId:e.askId,documentKey:t,position:n,...m===!1?{count:!1}:{}})})}catch{}},v=e.search;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`div`,{className:X.picksHead,children:[(0,u.jsxs)(`span`,{className:X.picksTitle,children:[(0,u.jsx)(f.Ai_agent,{size:14,color:`currentColor`}),r]}),(0,u.jsx)(`span`,{className:X.picksCount,children:e.picks.length}),(0,u.jsx)(`span`,{className:X.picksSpacer}),i&&(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:i,children:v?`Show all ${v.found}${v.more?`+`:``} found`:`Show the search instead`})]}),h===null?(0,u.jsx)(le,{rows:Math.max(1,e.picks.length)}):(0,u.jsx)(`div`,{children:e.picks.map(e=>{let r=h.get(e.documentKey),i=r==null?null:he(r,t,n);return i?(0,u.jsxs)(Z,{index:e.n,showScore:!1,children:[a(i,{result:{document:r,documentKey:e.documentKey,score:0,position:e.n},select:_(e.documentKey,e.n)}),e.why&&(0,u.jsxs)(`div`,{className:X.why,children:[(0,u.jsx)(f.Ai_agent,{size:12,color:`currentColor`}),(0,u.jsx)(`span`,{children:e.why})]})]},e.documentKey):null})})]})},_e=({fields:e,resultsPerPage:t,parseArrayStrings:n=!1,searchOrAsk:r,notFoundLabel:i=`These results may not hold what you are asking about`,picks:a,onShowSearch:o,picksLabel:s=`Picked by the assistant`,showScore:l,children:p})=>{let{state:{results:m,resultsSuppressed:h,searchSettings:g,countedTotal:_,query:v,error:y,errorInfo:b},isFetchingInitial:x,authError:S,authErrorInfo:C,retry:w,allowEmptySearch:T,fetchMoreResults:E,selectResult:O,searchText:k,searchAsTyped:A,picks:j,showPicks:M}=D(),{apply:N}=fe(),P=a===void 0?j:a,F=o??(()=>{P?.search&&N(P.search),M?.(null)}),I=(0,c.useRef)(null);P&&I.current?.picks!==P&&(I.current={picks:P,query:v});let L=!!P&&I.current?.query===v,R=t??30,[z,B]=(0,c.useState)(R),V=(0,c.useRef)(0),H=(0,c.useRef)(``);(0,c.useEffect)(()=>{let e=v!==H.current;(!m||m.length<V.current||e)&&B(R),V.current=m?.length??0,H.current=v},[m,R,v]);let U=m??[],W=!!r?.notFound,G=k!=null&&k.trim()!==v.trim()?k:null,K=!!m&&m.length>=g.maxNumberOfRecordsToReturn&&(_===void 0||_>m.length),q=!!m&&(U.length>z||K),ee=()=>{let e=z+R;B(e),m&&e>=m.length&&K&&E(m.length+R)};if(P&&L&&!x&&!S)return(0,u.jsx)(ge,{picks:P,fields:e,parseArrayStrings:n,label:s,onShowSearch:F,children:p});if(x)return T?(0,u.jsx)(le,{rows:R}):(0,u.jsx)(`div`,{className:X.placeholder,children:(0,u.jsx)(f.Indx,{size:200,color:`var(--lv5)`})});let te=S??y;return te?(0,u.jsx)(ae,{error:(S?C:b)??{kind:`unknown`,message:te,technical:te,retryable:!1},onRetry:w}):h||m===null?(0,u.jsx)(`div`,{className:X.placeholder,children:(0,u.jsx)(f.Indx,{size:200,color:`var(--lv5)`})}):U.length===0?null:(0,u.jsxs)(u.Fragment,{children:[G&&(0,u.jsxs)(`div`,{className:X.searchedFor,"aria-live":`polite`,children:[(0,u.jsxs)(`span`,{children:[`Searching for `,(0,u.jsx)(`strong`,{children:G})]}),A&&(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:A,children:`Search for your exact words`})]}),W&&(0,u.jsx)(`p`,{className:X.notFound,"aria-live":`polite`,children:i}),(0,u.jsx)(`div`,{className:W?X.dimmed:void 0,children:U.slice(0,z).map((t,r)=>{let i=t.score,a=he(t.document,e,n);return a?(0,u.jsx)(Z,{index:r,score:i,showScore:l??g.showScore,children:p(a,{result:t,select:()=>O?.(t)??Promise.resolve()})},r):(0,u.jsx)(`div`,{className:X.invalid,children:(0,u.jsx)(`p`,{children:`Invalid JSON`})},r)})}),q&&(0,u.jsx)(`div`,{style:{textAlign:`center`,marginTop:`20px`},children:(0,u.jsx)(d.Button,{variant:`secondary`,size:`micro`,onClick:ee,children:v.trim()===``?`Load more`:_!==void 0&&_>0?`Load results ${z+1}-${Math.min(z+R,m.length,_)} of ${_}`:`Load more`})})]})},ve={row:`_row_ujwhc_1`,title:`_title_ujwhc_8`},ye=({variant:e=`default`,children:t})=>(0,u.jsx)(`div`,{className:[ve.row,e===`title`?ve.title:``].filter(Boolean).join(` `),children:t}),be={listRows:`_listRows_13obt_2`,sliderArea:`_sliderArea_13obt_8`,inputRow:`_inputRow_13obt_15`,histogramRow:`_histogramRow_13obt_22`},xe=[65,80,55,72,60,75,50,68],Se=({title:e,rows:t=5,variant:n=`list`,withHistogram:r=!1,collapsible:i=!0,startCollapsed:a=!1})=>(0,u.jsx)(d.FilterPanelBase,{title:e,collapsible:i,collapsed:a,children:n===`slider`?(0,u.jsxs)(`div`,{className:be.sliderArea,children:[r&&(0,u.jsx)(`div`,{className:be.histogramRow}),(0,u.jsx)(d.Skeleton,{height:6}),(0,u.jsxs)(`div`,{className:be.inputRow,children:[(0,u.jsx)(d.Skeleton,{width:40,height:20,delay:.1}),(0,u.jsx)(d.Skeleton,{width:40,height:20,delay:.15})]})]}):(0,u.jsx)(`div`,{className:be.listRows,children:Array.from({length:t}).map((e,t)=>(0,u.jsx)(d.Skeleton,{width:`${xe[t%xe.length]}%`,delay:t*.05},t))})}),Ce={list:`_list_18vbb_2`,count:`_count_18vbb_7`,countValue:`_countValue_18vbb_17`,chip:`_chip_18vbb_22`,chipLabel:`_chipLabel_18vbb_32`,grid:`_grid_18vbb_40`,active:`_active_18vbb_54`},we={notice:`_notice_4sel0_1`,technical:`_technical_4sel0_9`},Te=({label:e,field:t,missing:n})=>{let r=n.map(e=>e[0].toUpperCase()+e.slice(1)).join(` and `);return(0,c.useEffect)(()=>{console.warn(`[intrface] The panel for "${t}" is hidden: the field is not ${r}. Mark it ${r} in the dataset's field configuration (web console → Fields).`)},[t,r]),(0,u.jsx)(d.FilterPanelBase,{title:e??t,collapsible:!1,children:(0,u.jsxs)(`div`,{className:we.notice,children:[(0,u.jsx)(`span`,{children:`Not available`}),(0,u.jsxs)(`code`,{className:we.technical,children:[t,`: not `,r]})]})})},Ee=({field:e,label:t,preserveBlankFacetState:n=!1,preserveBlankFacetStateOrder:r=!1,sortFacetsBy:i=`histogram`,limit:a=10,collapsible:o=!0,startCollapsed:s=!1,control:l,displayType:f,layout:p=`list`,showActivePanel:m=!1,showCount:h=!0,showNull:g=!1,match:_=`all`,displayIfEmptyQuery:v=!0,displayCondition:y=e=>!0})=>{let{state:{facets:b,filterableFields:x,facetableFields:S,filters:C,query:w},toggleFilter:T,setValueMatch:E,authError:O,isFetchingInitial:k,allowEmptySearch:A}=D(),j=l??f??`checkbox`,M=j===`radio`?`any`:_;(0,c.useEffect)(()=>{E(e,M)},[e,M,E]);let N=(0,c.useRef)(null),[P,F]=(0,c.useState)(a);if((0,c.useEffect)(()=>{F(a)},[b?.[e],a]),!A&&!w||O)return null;if(k||!b)return j===`toggle`?(0,u.jsx)(Se,{rows:1,collapsible:!1}):(0,u.jsx)(Se,{title:t,rows:Math.min(a,6),collapsible:o,startCollapsed:s});if(!y({query:w??``,filters:C,facets:b})||!v&&!w&&Object.keys(C).length<1)return null;if(!x?.includes(e)||!S?.includes(e)){let n=[];return x?.includes(e)||n.push(`filterable`),S?.includes(e)||n.push(`facetable`),(0,u.jsx)(Te,{label:t,field:e,missing:n})}let I=b?.[e]??(j===`toggle`?[]:void 0);if(!I||!Array.isArray(I))return null;let L=C?.[e]??[];n&&!N.current&&I.length>0&&(N.current=I.reduce((e,t)=>(e[t.key]=t.value,e),{}));let R=new Map;n&&N.current&&Object.keys(N.current).forEach(e=>{R.set(e,0)}),I.forEach(e=>{R.set(e.key,e.value)});let z=new Set([`true`,`false`,`null`]),B=Array.from(R.keys()),V=j===`toggle`&&(B.length>0&&B.every(e=>z.has(e))||B.length===0&&L.length>0);if(V&&R.has(`null`)){let e=R.get(`null`)??0,t=R.get(`false`)??0;R.set(`false`,t+e),R.delete(`null`)}if(j===`toggle`&&!V)return(0,u.jsx)(d.FilterPanelBase,{collapsible:!1,children:(0,u.jsx)(`div`,{className:Ce.count,children:(0,u.jsx)(d.ToggleSwitch,{label:t,checked:!1,onChange:()=>{},disabled:!0})})});if(V){let n=R.get(`true`),r=typeof n==`number`?n:null,i=L.includes(`true`),a=r===0&&!i,o=h&&(r??0)>0?`${r}`:``;return(0,u.jsx)(d.FilterPanelBase,{collapsible:!1,children:(0,u.jsxs)(`div`,{className:Ce.count,children:[(0,u.jsx)(d.ToggleSwitch,{label:t,checked:i,onChange:()=>T(e,`true`),disabled:a}),` `,o]})})}let H=Array.from(R.entries());if(g||(H=H.filter(([e])=>e!==`null`)),H.length===0&&!n)return null;if(!r){if(i===`alphabetical`){let e=H.filter(([,e])=>typeof e==`number`&&e>0).sort(([e],[t])=>e.localeCompare(t)),t=H.filter(([,e])=>e===0||e===null).sort(([e],[t])=>e.localeCompare(t));H=[...e,...t]}else if(i===`numeric`){let e=(e,t)=>{let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e.localeCompare(t)},t=H.filter(([,e])=>typeof e==`number`&&e>0).sort(([t],[n])=>e(t,n)),n=H.filter(([,e])=>e===0||e===null).sort(([t],[n])=>e(t,n));H=[...t,...n]}else{let e=H.filter(([,e])=>typeof e==`number`&&e>0),t=H.filter(([,e])=>e===0||e===null);H=[...e,...t]}}let U=typeof a==`number`&&H.length>a,W=U?H.slice(0,P):H,G=(t,n)=>{let r=L.includes(t),i=n===0,a=h&&(n??0)>0?` (${n})`:``,o=h&&(n??0)>0?n:``,s=()=>T(e,t,j===`radio`);switch(j){case`button`:return p===`list`?(0,u.jsxs)(`div`,{className:Ce.count,children:[(0,u.jsx)(d.Button,{variant:r?`primary`:`secondary`,onClick:s,disabled:i,size:`micro`,className:Ce.chip,title:t,children:(0,u.jsx)(`span`,{className:Ce.chipLabel,children:t})}),(0,u.jsx)(`span`,{className:Ce.countValue,children:o})]}):(0,u.jsx)(d.Button,{variant:r?`primary`:`secondary`,onClick:s,disabled:i,size:`micro`,className:Ce.chip,title:`${t}${a}`,children:(0,u.jsx)(`span`,{className:Ce.chipLabel,children:`${t}${a}`})});case`toggle`:return(0,u.jsx)(d.ToggleSwitch,{label:t,checked:r,onChange:s,disabled:i});case`radio`:{let n=(0,u.jsx)(d.RadioButton,{id:`${e}-${t}`,name:e,value:t,label:p===`grid`?`${t}${a}`:t,checked:r,onChange:s,disabled:i});return p===`list`?(0,u.jsxs)(`div`,{className:Ce.count,children:[n,(0,u.jsx)(`span`,{className:Ce.countValue,children:o})]}):n}default:return p===`list`?(0,u.jsxs)(`div`,{className:Ce.count,children:[(0,u.jsx)(d.Checkbox,{label:t,score:``,checked:r,onChange:s,disabled:i}),(0,u.jsx)(`span`,{className:Ce.countValue,children:o})]}):(0,u.jsx)(d.Checkbox,{label:t,score:a,checked:r,onChange:s,disabled:i})}};return(0,u.jsx)(d.FilterPanelBase,{title:t,collapsible:o,collapsed:o?s:!1,className:m&&L.length>0?Ce.active:void 0,children:(0,u.jsxs)(`ul`,{className:p===`grid`?Ce.grid:Ce.list,style:{listStyle:`none`,padding:0,margin:0},children:[W.map(([e,t])=>(0,u.jsx)(`li`,{children:G(e,t)},e)),U&&P<H.length&&(()=>{let e=H.length-P,t=Math.min(50,e);return(0,u.jsx)(`li`,{className:Ce.toggleItem,children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:()=>F(e=>e+50),children:`Show ${t} more of ${H.length} total`})})})()]})})},Q={disabledMessage:`_disabledMessage_adany_1`,histogram:`_histogram_adany_6`,histogramLayer:`_histogramLayer_adany_14`,histogramLive:`_histogramLive_adany_22`,histogramLit:`_histogramLit_adany_23`,histogramFill:`_histogramFill_adany_30`,histogramBar:`_histogramBar_adany_43`,histogramSeparators:`_histogramSeparators_adany_61`,histogramSeparator:`_histogramSeparator_adany_48`,active:`_active_adany_76`};function De(e){if(!Number.isFinite(e))return 0;let t=String(e),n=t.indexOf(`.`);return n===-1?0:Math.min(6,t.length-n-1)}function Oe(e){let t=0;for(let n of e)t=Math.max(t,De(n));return t===0?1:Number((10**-t).toFixed(t))}function ke(e,t){return Number(e.toFixed(De(t)))}function Ae(e,t,n){let r=t+Math.round((e-t)/n)*n;return Number(r.toFixed(De(n)))}function je(e,t,n){let r=Math.ceil(Number(((e-t)/n).toFixed(6)));return Number((t+r*n).toFixed(De(n)))}var Me=({field:e,label:t,expectedMin:n=0,expectedMax:r=1e3,control:i,displayType:a,showActivePanel:o=!1,collapsible:s=!0,startCollapsed:l=!1,showHistogram:f=!1,resolution:p,step:m,stepMarks:h})=>{let{state:{rangeFilters:g,rangeBounds:_,facetStats:v,facets:y,filterableFields:b,facetableFields:x,query:S,facetDebounceDelayMillis:C},setRangeFilter:w,resetRangeFilter:T,allowEmptySearch:E,authError:O,isFetchingInitial:k}=D(),A=i??a??`input`,j=_?.[e]!==void 0,M=_?.[e]??{min:n,max:r},N=M.min,P=M.max,F=v?.[e]??M,I=Math.max(N,Math.min(P,F.min)),L=Math.max(N,Math.min(P,F.max)),R=c.default.useMemo(()=>{if(m)return m;let t=Math.max(De(N),De(P)),n=y?.[e];if(Array.isArray(n))for(let e of n)t=Math.max(t,De(Number(e.key)));return t===0?1:Number((10**-t).toFixed(t))},[m,N,P,y,e]),z=j&&N===P,B=z?n:N,V=z?r:P,H=je(V+R,B,R),U=e=>Math.min(H,Math.max(B,e)),W=g?.[e],G=o&&W!==void 0?Q.active:void 0,K=W?W.min:N,q=W?W.max:P,ee=W!==void 0,te=I!==N||L!==P,[J,Y]=c.default.useState([K,q]),[ne,re]=c.default.useState(!1),[ie,ae]=c.default.useState(!1),[X,oe]=c.default.useState(String(K)),[Z,se]=c.default.useState(String(q)),ce=c.default.useMemo(()=>{let e=De(R);return{width:`calc(${Math.max(3,N.toFixed(e).length,P.toFixed(e).length,X.length,Z.length)+1}ch + 20px)`}},[R,N,P,X,Z]);c.default.useEffect(()=>{oe(String(J[0])),se(String(J[1]))},[J]);let{finalMin:le,finalMax:ue,isValidMin:de,isValidMax:fe}=c.default.useMemo(()=>{let[e,t]=J,n=Math.max(N,Math.min(P,e)),r=Math.max(N,Math.min(P,t)),i=Math.min(n,r),a=Math.max(n,r);return{finalMin:i,finalMax:a,isValidMin:i>=N&&i<=a,isValidMax:a<=P&&a>=i}},[J,N,P]);c.default.useEffect(()=>{if(z)return;if(J[0]===N&&J[1]===P){re(!1),ae(!1);return}let t=C??500,n=setTimeout(()=>{re(!de),ae(!fe)},300),r=setTimeout(()=>{de&&fe&&(le===N&&ue===P?T(e,!1):w(e,le,ue))},t);return()=>{clearTimeout(n),clearTimeout(r)}},[le,ue,de,fe,N,P,e,T,w,C,z]),c.default.useEffect(()=>{Y([K,q]),re(!1),ae(!1)},[K,q,e]);let pe=c.default.useCallback(e=>{let t=ke(Math.min(e[0],e[1]-R),R);return[t,ke(Math.max(e[1]-R,t),R)]},[R]),me=c.default.useCallback(e=>{if(z)return;let[t,n]=pe(e);Y([Math.max(N,Math.min(L,t)),Math.max(I,Math.min(P,n))])},[z,pe,N,P,I,L]),he=c.default.useCallback(t=>{if(z)return;let[n,r]=pe(t),i=Math.max(N,Math.min(L,n)),a=Math.max(I,Math.min(P,r));i===N&&a===P?(Y([N,P]),T(e,!0)):Y([i,a])},[z,pe,N,P,I,L,e,T]),ge=c.default.useRef(null),_e=c.default.useCallback((t,n)=>{if(z)return;let r=ge.current;if(W&&r&&r.start===t&&r.last===n){ge.current=null,Y([N,P]),T(e,!0);return}let i=Ae(Math.max(N,I,t),N,R),a=Math.max(i,Ae(Math.min(P,L,n),N,R));ge.current={start:t,last:n},Y([i,a])},[z,W,N,P,I,L,R,e,T]),ve=c.default.useCallback(()=>{if(z)return;let e=X.trim(),t=e===``?NaN:Number(e);if(isNaN(t)){oe(String(J[0]));return}let n=Math.max(N,Math.min(L,t));n<J[1]?Y([n,J[1]]):Y([N,J[1]]),oe(String(n<J[1]?n:N))},[z,X,J,N,L]),ye=c.default.useCallback(()=>{if(z)return;let e=Z.trim(),t=e===``?NaN:Number(e);if(isNaN(t)){se(String(J[1]));return}let n=Math.max(I,Math.min(P,t));n>J[0]?Y([J[0],n]):Y([J[0],P]),se(String(n>J[0]?n:P))},[z,Z,J,I,P]),be=e=>t=>{t.key===`Enter`&&e()},[xe,Ce]=c.default.useState(null),we=c.default.useRef(null);c.default.useEffect(()=>{if(!f)return;let t=`${N}:${P}`;if(t===we.current&&we.current!==null)return;let n=y?.[e];if(!Array.isArray(n)||n.length===0)return;let r=n.filter(e=>e.value!=null&&!isNaN(Number(e.key))).map(e=>({key:e.key,value:e.value}));r.length>0&&(we.current=t,Ce(r))},[N,P,y,e,f]);let Ee=c.default.useMemo(()=>{if(!f||!xe||xe.length===0)return[];let e=P-N;if(e<=0)return[];let t=p??Math.max(R,ke(Math.ceil(e/20/R)*R,R)),n=Math.ceil(e/t);return Array.from({length:n},(e,r)=>{let i=N+r*t,a=N+(r+1)*t,o=r===n-1,s=xe.filter(e=>{let t=Number(e.key);return t>=i&&(t<a||o&&t<=P)}).reduce((e,t)=>e+t.value,0),c=o?P:ke(a-R,R);return{bucketStart:i,bucketEnd:a,count:s,last:c,barEnd:ke(c+R,R)}}).map((e,t,n)=>({...e,span:(t+1<n.length?n[t+1].bucketStart:Math.max(e.barEnd,H))-e.bucketStart}))},[f,xe,N,P,p,R,H]),Oe=c.default.useMemo(()=>Math.max(...Ee.map(e=>e.count),1),[Ee]);return f&&!k&&!x?.includes(e)&&console.warn(`RangeFilterPanel: showHistogram=true but field "${e}" is not facetable. Add .Facetable = true to this field.`),O?null:k?(0,u.jsx)(Se,{title:t,variant:`slider`,withHistogram:f,collapsible:s,startCollapsed:l}):!E&&!S?null:b?.includes(e)?A===`slider`?(0,u.jsxs)(d.FilterPanelBase,{title:t,collapsed:l,collapsible:s,className:G,children:[z&&(0,u.jsxs)(`div`,{className:Q.disabledMessage,children:[`No adjustable range (all results have the same value: `,N,`).`]}),f&&Ee.length===0&&(0,u.jsx)(`div`,{className:Q.histogram}),f&&Ee.length>0&&(()=>{let[e,t]=L>I&&(I>N||L<P)?[I,L]:[B,V],n=Math.max(le,e),r=Math.min(ue,t),i=H,a=i-B||1,o=e=>Math.max(0,Math.min(1,(e-B)/a)),s=e=>e>=V?0:Math.max(0,Math.min(1,(i-(e+R))/a)),c=o(n),l=r<n?1-c:s(r),d=e=>`calc(10px + (100% - 20px) * ${e})`,f=`inset(0 ${d(l)} 0 ${d(c)})`,p=`inset(0 ${d(s(t))} 0 ${d(o(e))})`,m=n=>n.last<e||n.bucketStart>t,h=Ee.slice(1).map(e=>d((e.bucketStart-B)/a)),g=Ee.map(e=>({...e,height:Math.max(1,Math.ceil(e.count/Oe*20))}));return(0,u.jsxs)(`div`,{className:Q.histogram,children:[(0,u.jsx)(`div`,{className:Q.histogramLayer,children:g.map((e,t)=>(0,u.jsx)(`button`,{type:`button`,className:Q.histogramBar,style:{flexGrow:e.span},"data-testid":`histogram-bar`,disabled:z||m(e),"aria-label":`${e.bucketStart} to ${e.last}: ${e.count}`,title:`${e.bucketStart} to ${e.last}: ${e.count}`,onClick:()=>_e(e.bucketStart,e.last),children:(0,u.jsx)(`span`,{className:Q.histogramFill,style:{height:`${e.height}px`}})},t))}),(0,u.jsx)(`div`,{className:`${Q.histogramLayer} ${Q.histogramLive}`,"aria-hidden":`true`,"data-testid":`histogram-live`,style:{clipPath:p},children:g.map((e,t)=>(0,u.jsx)(`span`,{className:Q.histogramBar,style:{flexGrow:e.span},children:(0,u.jsx)(`span`,{className:Q.histogramFill,style:{height:`${e.height}px`}})},t))}),(0,u.jsx)(`div`,{className:`${Q.histogramLayer} ${Q.histogramLit}`,"aria-hidden":`true`,"data-testid":`histogram-lit`,style:{clipPath:f},children:g.map((e,t)=>(0,u.jsx)(`span`,{className:Q.histogramBar,style:{flexGrow:e.span},children:(0,u.jsx)(`span`,{className:Q.histogramFill,style:{height:`${e.height}px`}})},t))}),(0,u.jsx)(`div`,{className:Q.histogramSeparators,"aria-hidden":`true`,children:h.map((e,t)=>(0,u.jsx)(`span`,{className:Q.histogramSeparator,style:{left:e}},t))})]})})(),(0,u.jsx)(`div`,{style:{padding:`10px 10px 20px 10px`},children:(0,u.jsx)(d.Slider,{min:B,max:H,step:R,stepMarks:h,value:z?[B,H]:[U(Ae(le,B,R)),U(Ae(ue+R,B,R))],isRange:!0,onChange:e=>me(e),onFinalChange:e=>he(e),disabled:z,activeMin:I,activeMax:U(ke(L+R,R)),isFaceted:te,highlightFaceted:ee,"aria-label":t||`Filter by ${e}`})}),(0,u.jsxs)(`div`,{style:{display:`flex`,gap:`10px`,alignItems:`flex-start`,justifyContent:`space-between`},children:[(0,u.jsx)(d.InputField,{label:`Min:`,type:`number`,style:ce,value:z?String(N):X,min:N,max:ke(Math.min(L,J[1]-R),R),onChange:e=>oe(e.target.value),onBlur:ve,onKeyDown:be(ve),disabled:z,isValid:z||!ne}),(0,u.jsx)(d.InputField,{label:`Max:`,type:`number`,style:ce,value:z?String(P):Z,min:ke(Math.max(I,J[0]+R),R),max:P,onChange:e=>se(e.target.value),onBlur:ye,onKeyDown:be(ye),disabled:z,isValid:z||!ie})]})]}):(0,u.jsxs)(d.FilterPanelBase,{title:t,className:G,children:[z&&(0,u.jsxs)(`div`,{className:Q.disabledMessage,children:[`No adjustable range (all results have the same value: `,N,`).`]}),(0,u.jsxs)(`div`,{style:{display:`flex`,gap:`10px`,alignItems:`flex-start`},children:[(0,u.jsx)(d.InputField,{label:`Min:`,type:`number`,style:ce,value:z?String(N):X,min:N,max:ke(Math.min(L,J[1]-R),R),onChange:e=>oe(e.target.value),onBlur:ve,onKeyDown:be(ve),disabled:z,isValid:z||!ne}),(0,u.jsx)(d.InputField,{label:`Max:`,type:`number`,style:ce,value:z?String(P):Z,min:ke(Math.max(I,J[0]+R),R),max:P,onChange:e=>se(e.target.value),onBlur:ye,onKeyDown:be(ye),disabled:z,isValid:z||!ie})]})]}):(0,u.jsx)(Te,{label:t,field:e,missing:[`filterable`]})},Ne={list:`_list_9je85_2`,grid:`_grid_9je85_9`,count:`_count_9je85_22`,countValue:`_countValue_9je85_31`,chip:`_chip_9je85_35`,active:`_active_9je85_41`};function Pe(e,t){if(!t)return null;let n=0,r=!1;for(let i of t){let t=Number(i.key);if(!Number.isNaN(t)&&e.contains(t)){if(typeof i.value!=`number`)return null;n+=i.value,r=!0}}return r?n:0}var Fe=({field:e,label:t,width:n,buckets:r,control:i,displayType:a,layout:o=`list`,showCount:s=!0,showEmpty:l=!1,limit:f,showActivePanel:p=!1,collapsible:m=!0,startCollapsed:h=!1})=>{let{state:{facets:g,filterableFields:_,facetableFields:v,bucketFilters:y,rangeBounds:b,facetStats:x,query:S},toggleBucketFilter:C,authError:w,isFetchingInitial:T,allowEmptySearch:E}=D(),O=i??a??`checkbox`,k=g?.[e],A=y[e]??[],[j,M]=(0,c.useState)(f??1/0);(0,c.useEffect)(()=>{M(f??1/0)},[f,k]);let N=b?.[e]??x?.[e],P=(0,c.useMemo)(()=>{let e=[];if(N&&e.push(N.min,N.max),Array.isArray(k))for(let t of k)e.push(Number(t.key));return Oe(e.filter(Number.isFinite))},[N,k]),F=(0,c.useMemo)(()=>{let e=N?.min??-Number.MAX_VALUE,t=N?.max??Number.MAX_VALUE,i=(n,r,i)=>({label:i??(n===void 0?`up to ${r}`:r===void 0?`${n} and up`:`${n}-${r}`),range:{min:n??e,max:r??t},contains:e=>(n===void 0||e>=n)&&(r===void 0||e<=r)});if(r&&r.length>0)return r.map(e=>i(e.min,e.max,e.label));if(Array.isArray(n)){let e=[...n].sort((e,t)=>e-t),t=[];for(let n=0;n<e.length-1;n++)t.push(i(e[n],ke(e[n+1]-P,P)));return t}if(typeof n==`number`&&n>0&&N){let e=[],t=Math.floor(N.min/n)*n;for(let r=t;r<=N.max;r=ke(r+n,P))e.push(i(ke(r,P),ke(r+n-P,P)));return e}return[]},[r,n,N,P]);if(w)return null;if(T||!g)return(0,u.jsx)(Se,{title:t,rows:Math.max(1,Math.min(F.length||5,8)),collapsible:m,startCollapsed:h});if(!E&&!S)return null;if(!_?.includes(e))return(0,u.jsx)(Te,{label:t,field:e,missing:[`filterable`]});let I=v?.includes(e)&&Array.isArray(k),L=e=>A.some(t=>t.min===e.range.min&&t.max===e.range.max),R=F.map(e=>({bucket:e,count:I?Pe(e,k):null}));if(l||(R=R.filter(e=>e.count!==0||L(e.bucket))),R.length===0)return null;let z=R.slice(0,j),B=(t,n)=>{let r=L(t),i=n===0&&!r,a=s&&(n??0)>0?`${n}`:``,c=()=>C(e,t.range,O===`radio`);if(O===`radio`){let n=(0,u.jsx)(d.RadioButton,{id:`${e}-${t.range.min}-${t.range.max}`,name:e,value:t.label,label:o===`grid`&&a?`${t.label} (${a})`:t.label,checked:r,onChange:c,disabled:i});return o===`list`?(0,u.jsxs)(`div`,{className:Ne.count,children:[n,(0,u.jsx)(`span`,{className:Ne.countValue,children:a})]}):n}if(O===`button`){let e=(0,u.jsx)(d.Button,{variant:r?`primary`:`secondary`,onClick:c,disabled:i,size:`micro`,className:Ne.chip,children:o===`grid`&&a?`${t.label} (${a})`:t.label});return o===`list`?(0,u.jsxs)(`div`,{className:Ne.count,children:[e,(0,u.jsx)(`span`,{className:Ne.countValue,children:a})]}):e}return o===`list`?(0,u.jsxs)(`div`,{className:Ne.count,children:[(0,u.jsx)(d.Checkbox,{label:t.label,score:``,checked:r,onChange:c,disabled:i}),(0,u.jsx)(`span`,{className:Ne.countValue,children:a})]}):(0,u.jsx)(d.Checkbox,{label:t.label,score:a?` (${a})`:``,checked:r,onChange:c,disabled:i})};return(0,u.jsx)(d.FilterPanelBase,{title:t,collapsible:m,collapsed:m?h:!1,className:p&&A.length>0?Ne.active:void 0,children:(0,u.jsxs)(`ul`,{className:o===`grid`?Ne.grid:Ne.list,style:{listStyle:`none`,padding:0,margin:0},children:[z.map(({bucket:e,count:t})=>(0,u.jsx)(`li`,{children:B(e,t)},`${e.range.min}-${e.range.max}`)),z.length<R.length&&(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:()=>M(R.length),children:`Show ${R.length-z.length} more of ${R.length} total`})})]})})},Ie={select:`_select_nwf7i_1`,radioGroup:`_radioGroup_nwf7i_6`},Le=({options:e,noneLabel:t=`None`,control:n,displayType:r,collapsible:i=!0,startCollapsed:a=!1})=>{let o=n??(r===`radio`?`radio`:`select`),{state:{sortableFields:s,sortBy:c,sortAscending:l},setSort:f,isFetchingInitial:p}=D();if(p)return(0,u.jsx)(Se,{title:`Sort by`,rows:o===`radio`?3:1,collapsible:i,startCollapsed:a});if(!s||s.length===0)return null;let m=c?`${c}:${l?`asc`:`desc`}`:`none`,h=e?e.filter(e=>s.includes(e.field)?!0:(console.warn(`[SortByPanel] '${e.field}' is not sortable, so "${e.label}" is left out. Mark the field Sortable in the dataset's field configuration.`),!1)).map(e=>({label:e.label,value:`${e.field}:${e.ascending?`asc`:`desc`}`})):s.flatMap(e=>[{label:`${e} (asc)`,value:`${e}:asc`},{label:`${e} (desc)`,value:`${e}:desc`}]),g=t===null?h:[{label:t,value:`none`},...h],_=e=>{if(e===`none`||e===``)f(null,!0);else{let[t,n]=e.split(`:`);f(t,n===`asc`)}};return(0,u.jsx)(d.FilterPanelBase,{title:`Sort by`,collapsible:i,collapsed:i?a:!1,children:o===`select`?(0,u.jsx)(d.Select,{value:m,onValueChange:_,options:g,placeholder:`Select sort...`,"aria-label":`Sort by`}):(0,u.jsx)(`div`,{className:Ie.radioGroup,children:g.map(e=>(0,u.jsx)(d.RadioButton,{id:`sort-${e.value}`,name:`sort-by`,value:e.value,label:e.label,checked:m===e.value,onChange:e=>_(e.target.value)},e.value))})})},Re={list:`_list_1y4fk_1`},ze={tolerance:l.Tolerance.TwoEdits,rungs:l.Rungs.Fewest,oneEditFrom:3,twoEditsFrom:6,threeEditsFrom:9,typingPrefixFrom:3,typingPrefixOneEditFrom:6,joinedWords:!0},Be={candidatesPerRow:4,fallback:!0,rest:!1},Ve={rerank:!0,share:.2,typingShift:.5,wholeQueryFloor:!0};function He(){let{state:{searchSettings:e},setSearchSettings:t,url:n,team:r,dataset:i,authenticatedFetch:a}=D(),[o,s]=(0,c.useState)(!1),{match:p,candidates:m,ranking:h}=e,[g,_]=(0,c.useState)(null);(0,c.useEffect)(()=>{let e=!0;try{a(`${n}/api/teams/${r}/datasets/${i}/query-parameters`).then(e=>e.ok?e.json():null).then(t=>{e&&t?.effective&&_(t.effective)}).catch(()=>{})}catch{}return()=>{e=!1}},[n,r,i,a]);let v=e=>Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!=null)),y={...ze,...v(g?.match)},b={...Be,...v(g?.candidates)},x={...Ve,...v(g?.ranking)},S=e.mode??g?.mode??l.SearchMode.EditDistance,C=S===l.SearchMode.Bm25f,w=h.rerank??x.rerank,T=C&&!w,E=e.mode!==void 0||[p,m,h].some(e=>Object.values(e??{}).some(e=>e!=null)),O=(e,n)=>{let r=parseInt(n,10);isNaN(r)||t({[e]:r})},k=(e,n)=>{t({[e]:n})},A=e=>t({match:e}),j=e=>t({candidates:e}),M=e=>t({ranking:e}),N=(e,t)=>{let n=parseInt(e,10);isNaN(n)||t(n)},P=(e,t)=>{let n=parseFloat(e);isNaN(n)||t(Math.max(0,Math.min(100,n))/100)};return(0,u.jsx)(d.FilterPanelBase,{collapsed:!0,title:`Settings`,children:(0,u.jsxs)(`ul`,{className:Re.list,children:[(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Select,{label:`Mode`,size:`micro`,value:S,onValueChange:e=>t({mode:e}),options:[{label:`Edit distance`,value:l.SearchMode.EditDistance},{label:`BM25F`,value:l.SearchMode.Bm25f}]})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Rerank (Coverage)`,checked:w,onChange:e=>M({rerank:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Max Results`,type:`number`,value:e.maxNumberOfRecordsToReturn.toString(),onChange:e=>O(`maxNumberOfRecordsToReturn`,e.target.value)})}),(0,u.jsxs)(`li`,{children:[(0,u.jsx)(d.InputField,{label:`Minimum Score (16 bit)`,type:`number`,value:e.minimumScore.toString(),min:`0`,max:`65535`,onChange:e=>{let n=parseFloat(e.target.value);isNaN(n)||t({minimumScore:n})}}),(0,u.jsx)(`div`,{style:{padding:`10px 10px 20px 10px`},children:(0,u.jsx)(d.Slider,{min:0,max:65535,step:1,value:Math.max(0,Math.min(65535,Math.round(e.minimumScore))),onChange:e=>{t({minimumScore:e})},"aria-label":`Minimum score`})})]}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Placeholder text`,type:`text`,value:e.placeholderText,onChange:e=>{t({placeholderText:e.target.value})}})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Show score`,checked:e.showScore,onChange:e=>k(`showScore`,e)})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,iconRight:o?(0,u.jsx)(f.ArrowDown,{}):(0,u.jsx)(f.ArrowRight,{}),onClick:()=>s(e=>!e),children:o?`Hide Match, Candidates and Ranking`:`Show Match, Candidates and Ranking`})}),o&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Select,{label:`Tolerance`,size:`micro`,disabled:C,value:p.tolerance??y.tolerance,onValueChange:e=>A({tolerance:e}),options:[{label:`Exact`,value:l.Tolerance.Exact},{label:`One edit`,value:l.Tolerance.OneEdit},{label:`Two edits`,value:l.Tolerance.TwoEdits},{label:`Three edits`,value:l.Tolerance.ThreeEdits}]})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Every rung`,disabled:C,checked:(p.rungs??y.rungs)===l.Rungs.All,onChange:e=>A({rungs:e?l.Rungs.All:l.Rungs.Fewest})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`One edit from`,type:`number`,disabled:C,value:(p.oneEditFrom??y.oneEditFrom).toString(),onChange:e=>N(e.target.value,e=>A({oneEditFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Two edits from`,type:`number`,disabled:C,value:(p.twoEditsFrom??y.twoEditsFrom).toString(),onChange:e=>N(e.target.value,e=>A({twoEditsFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Three edits from`,type:`number`,disabled:C,value:(p.threeEditsFrom??y.threeEditsFrom).toString(),onChange:e=>N(e.target.value,e=>A({threeEditsFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Typing prefix from`,type:`number`,disabled:C,value:(p.typingPrefixFrom??y.typingPrefixFrom).toString(),onChange:e=>N(e.target.value,e=>A({typingPrefixFrom:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Joined words`,disabled:C,checked:p.joinedWords??y.joinedWords,onChange:e=>A({joinedWords:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Candidates per row`,type:`number`,disabled:T,value:(m.candidatesPerRow??b.candidatesPerRow).toString(),onChange:e=>N(e.target.value,e=>j({candidatesPerRow:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Max candidates (0: per row)`,type:`number`,disabled:T,value:(m.maxCandidates??0).toString(),onChange:e=>N(e.target.value,e=>j({maxCandidates:e>0?e:null}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Fallback (most words when none holds every word)`,disabled:C,checked:m.fallback??b.fallback,onChange:e=>j({fallback:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Rest (BM25F below the counted set)`,disabled:C,checked:m.rest??b.rest,onChange:e=>j({rest:e})})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Coverage share %`,type:`number`,disabled:!w,value:Math.round((h.share??x.share)*100).toString(),onChange:e=>P(e.target.value,e=>M({share:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.InputField,{label:`Typing shift %`,type:`number`,disabled:!w,value:Math.round((h.typingShift??x.typingShift)*100).toString(),onChange:e=>P(e.target.value,e=>M({typingShift:e}))})}),(0,u.jsx)(`li`,{children:(0,u.jsx)(d.ToggleSwitch,{label:`Whole query floor`,disabled:!w,checked:h.wholeQueryFloor??x.wholeQueryFloor,onChange:e=>M({wholeQueryFloor:e})})}),E&&(0,u.jsx)(`li`,{children:(0,u.jsx)(d.Button,{variant:`ghost`,size:`micro`,onClick:()=>t({mode:void 0,match:void 0,candidates:void 0,ranking:void 0}),children:`Use the dataset's values`})})]})]})})}var Ue=class extends c.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[SearchErrorBoundary] Caught error:`,e,t)}reset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback(this.state.error,this.reset):(0,u.jsxs)(`div`,{style:{padding:`2rem`,backgroundColor:`#fee`,border:`2px solid #c33`,borderRadius:`8px`,maxWidth:`600px`,margin:`2rem auto`},children:[(0,u.jsx)(`h2`,{style:{color:`#c33`,marginTop:0},children:`⚠️ Search Initialization Error`}),(0,u.jsxs)(`p`,{style:{marginBottom:`1rem`},children:[(0,u.jsx)(`strong`,{children:`Error:`}),` `,this.state.error.message]}),(0,u.jsxs)(`div`,{style:{backgroundColor:`#fff`,padding:`1rem`,borderRadius:`4px`,marginBottom:`1rem`,fontSize:`0.9rem`},children:[(0,u.jsx)(`strong`,{children:`💡 Common fixes:`}),(0,u.jsxs)(`ul`,{style:{marginBottom:0,paddingLeft:`1.5rem`},children:[(0,u.jsx)(`li`,{children:`Check browser console for detailed error messages`}),(0,u.jsx)(`li`,{children:`Verify the url passed to SearchProvider is correct`}),(0,u.jsx)(`li`,{children:`Verify your bearer token is valid (create or check it on the Indx Dashboard)`}),(0,u.jsx)(`li`,{children:`Ensure INDX server is running`}),(0,u.jsx)(`li`,{children:`Check dataset name spelling`})]})]}),(0,u.jsx)(d.Button,{variant:`primary`,size:`micro`,onClick:this.reset,children:`Try Again`})]}):this.props.children}};function We(e,t){let{url:n,team:r,dataset:i,authenticatedFetch:a}=D(),[o,s]=(0,c.useState)(null),[l,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(void 0),m=(0,c.useRef)(0);return(0,c.useEffect)(()=>()=>{m.current++},[n,r,i]),{results:o,isLoading:l,error:d,search:(0,c.useCallback)(async o=>{let c=++m.current,l=()=>c===m.current;u(!0),f(void 0);try{let c=await e(o),u={fieldName:t.fieldName,vector:c,maxResults:t.maxResults??10};t.filter&&(u.filter=t.filter);let d=await a(`${n}/api/teams/${r}/datasets/${i}/search/vector`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u)});if(!d.ok)throw await p.fromResponse(`VectorSearch`,d);let f=await d.json();if(!l())return;if(f.length===0){s([]);return}let m=f.map(e=>e.documentKey),h=await a(`${n}/api/teams/${r}/datasets/${i}/documents/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(m)});if(!h.ok)throw await p.fromResponse(`GetJson`,h);let g=await h.json();if(!l())return;s(g.map((e,t)=>({document:e,documentKey:m[t],score:f[t].score})))}catch(e){if(!l())return;f(e instanceof Error?e.message:`Vector search failed`),s(null)}finally{l()&&u(!1)}},[e,t.fieldName,t.maxResults,t.filter,n,r,i,a])}}function Ge(e,t){let{url:n,team:r,dataset:i,authenticatedFetch:a}=D(),[o,s]=(0,c.useState)(null),[l,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(void 0),m=(0,c.useRef)(0);return(0,c.useEffect)(()=>()=>{m.current++},[n,r,i]),{results:o,isLoading:l,error:d,search:(0,c.useCallback)(async o=>{let c=++m.current,l=()=>c===m.current;u(!0),f(void 0);try{let c=await e(o),u={text:o,embeddingField:t.fieldName,vector:c,maxNumberOfRecordsToReturn:t.maxResults??10,alpha:t.alpha??.5};t.filter&&(u.filter=t.filter),t.timeoutMs&&(u.timeOutLimitMilliseconds=t.timeoutMs);let d=await a(`${n}/api/teams/${r}/datasets/${i}/search/hybrid`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u)});if(!d.ok)throw await p.fromResponse(`HybridSearch`,d);let f=await d.json();if(!l())return;if(f.length===0){s([]);return}let m=f.map(e=>e.documentKey),h=await a(`${n}/api/teams/${r}/datasets/${i}/documents/lookup`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(m)});if(!h.ok)throw await p.fromResponse(`GetJson`,h);let g=await h.json();if(!l())return;s(g.map((e,t)=>({document:e,documentKey:m[t],score:f[t].score})))}catch(e){if(!l())return;f(e instanceof Error?e.message:`Hybrid search failed`),s(null)}finally{l()&&u(!1)}},[e,t.fieldName,t.alpha,t.maxResults,t.filter,t.timeoutMs,n,r,i,a])}}var Ke={question:``,status:`idle`,answer:``,sources:[],steps:[],stepDetails:[]};function qe(){let e=D(),{url:t,team:n,dataset:r,authenticatedFetch:i}=e,a=(0,c.useRef)(e);a.current=e;let[o,s]=(0,c.useState)(Ke),l=(0,c.useRef)(o);l.current=o;let u=(0,c.useRef)(null),d=(0,c.useCallback)(async(e,o=[],c={})=>{let l=e.trim();if(!l)return;u.current?.abort();let d=new AbortController;u.current=d,s({question:l,status:`searching`,answer:``,sources:[],steps:[],stepDetails:[]});let f=``,p=null,m=()=>{p=null;let e=f;s(t=>t.answer===e?t:{...t,answer:e})},h=()=>{p!==null&&(cancelAnimationFrame(p),p=null),m()},g=(e,t)=>s(n=>({...n,status:`error`,error:{code:e,message:t}}));try{let e=await i(`${t}/api/teams/${n}/datasets/${r}/search-or-ask/ask${R(a.current)}`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`text/event-stream`},body:JSON.stringify({question:l,...o.length?{history:o}:{},...c.proactive?{proactive:!0}:{}}),signal:d.signal});if(e.status===429){let t=await e.json().catch(()=>({}));if(c.proactive){s(Ke);return}let n=Number(e.headers.get(`Retry-After`));s(e=>({...e,status:`limited`,limit:t.code===`searchOrAskBudgetSpent`?`budget`:`address`,retryAfterSeconds:t.retryAfterSeconds??(Number.isFinite(n)?n:void 0)}));return}let u=e.headers.get(`Indx-Ask-Id`)??void 0;if(u&&s(e=>({...e,askId:u})),!e.ok||!e.body){let t=await e.json().catch(()=>({}));if(c.proactive){s(Ke);return}let n=e.status===409||e.status===404;g(t.code??`http${e.status}`,n?`Answers are not available here right now. Search still works.`:`The question could not be asked.`);return}for await(let{event:t,data:n}of L(e.body))switch(t){case`status`:{let e=n;e.step&&s(t=>({...t,steps:[...t.steps,e.step],stepDetails:[...t.stepDetails,e]}));break}case`filters`:s(e=>({...e,filters:n}));break;case`picks`:s(e=>({...e,picks:{...n,askId:e.askId}}));break;case`sources`:s(e=>({...e,status:`writing`,sources:n}));break;case`text`:f||s(e=>e.status===`searching`?{...e,status:`writing`}:e),f+=n.delta,p??=requestAnimationFrame(m);break;case`done`:h(),s(e=>({...e,status:`answered`}));return;case`error`:{h();let e=n;g(e.code,e.message);return}}h(),d.signal.aborted||g(`dropped`,`The connection dropped while the answer was being written.`)}catch(e){if(u.current!==d)return;h(),e.name===`AbortError`?s(e=>e.answer?{...e,status:`answered`}:{...e,status:`idle`}):g(`dropped`,`The connection dropped while the answer was being written.`)}finally{u.current===d&&(u.current=null)}},[t,n,r,i]),f=(0,c.useCallback)(async(e,o)=>{let s=o??l.current.askId;if(s)try{await i(`${t}/api/teams/${n}/datasets/${r}/events/select`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({queryId:s,documentKey:e.documentKey,position:e.n,...a.current.count===!1?{count:!1}:{}})})}catch{}},[t,n,r,i]),p=(0,c.useCallback)(()=>u.current?.abort(),[]),m=(0,c.useCallback)(()=>{u.current?.abort(),s(Ke)},[]);return(0,c.useEffect)(()=>()=>u.current?.abort(),[]),{...o,ask:d,stop:p,reset:m,openSource:f,busy:o.status===`searching`||o.status===`writing`}}var $={panel:`_panel_gjc13_1`,thread:`_thread_gjc13_4`,fill:`_fill_gjc13_5`,answer:`_answer_gjc13_8`,paragraph:`_paragraph_gjc13_9`,action:`_action_gjc13_10`,turn:`_turn_gjc13_11`,heading:`_heading_gjc13_14`,list:`_list_gjc13_15`,inlineCode:`_inlineCode_gjc13_16`,codeBlock:`_codeBlock_gjc13_17`,searched:`_searched_gjc13_22`,searchedLabel:`_searchedLabel_gjc13_23`,steps:`_steps_gjc13_26`,stepDone:`_stepDone_gjc13_27`},Je=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\n]+\*|_[^_\n]+_)|(\[[^\]\n]+\]\(https?:\/\/[^)\s]+\))|(\[\d+\])/g;function Ye(e,t,n){let r=[],i=0,a=0;for(let o of e.matchAll(Je)){o.index>i&&r.push(e.slice(i,o.index));let s=`${n}-${a++}`,[l,d,f,p,m,h]=o;if(d)r.push((0,u.jsx)(`code`,{className:$.inlineCode,children:d.slice(1,-1)},s));else if(f)r.push((0,u.jsx)(`strong`,{children:Ye(f.slice(2,-2),t,s)},s));else if(p)r.push((0,u.jsx)(`em`,{children:Ye(p.slice(1,-1),t,s)},s));else if(m){let[,e,t]=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(m);r.push((0,u.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e},s))}else h?r.push((0,u.jsx)(c.default.Fragment,{children:t(Number(h.slice(1,-1)))},s)):r.push(l);i=o.index+l.length}return i<e.length&&r.push(e.slice(i)),r}function Xe(e){let t=e.replace(/\r\n/g,`
6
6
  `).split(`
7
7
  `),n=[],r=[],i=()=>{r.length&&(n.push({kind:`paragraph`,text:r.join(` `)}),r=[])};for(let e=0;e<t.length;e++){let a=t[e],o=/^\s*```\s*([\w+#-]*)\s*$/.exec(a);if(o){i();let r=[];for(e++;e<t.length&&!/^\s*```\s*$/.test(t[e]);e++)r.push(t[e]);n.push({kind:`code`,lang:o[1]??``,text:r.join(`
8
8
  `)});continue}let s=/^(#{1,4})\s+(.*)$/.exec(a);if(s){i(),n.push({kind:`heading`,level:s[1].length,text:s[2]});continue}let c=/^\s*(?:([-*+])|(\d+)[.)])\s+(.*)$/.exec(a);if(c){i();let e=!!c[2],t=n[n.length-1];t?.kind===`list`&&t.ordered===e?t.items.push(c[3]):n.push({kind:`list`,ordered:e,items:[c[3]]});continue}if(a.trim()===``){i();continue}let l=n[n.length-1];r.length===0&&l?.kind===`list`&&/^\s{2,}\S/.test(a)?l.items[l.items.length-1]+=` `+a.trim():r.push(a.trim())}return i(),n}function Ze(e,t){return Xe(e).map((e,n)=>{let r=`b${n}`;switch(e.kind){case`code`:return(0,u.jsx)(`pre`,{className:$.codeBlock,"data-lang":e.lang||void 0,children:(0,u.jsx)(`code`,{children:e.text})},r);case`heading`:return(0,u.jsx)(`p`,{className:$.heading,children:Ye(e.text,t,r)},r);case`list`:{let n=e.ordered?`ol`:`ul`;return(0,u.jsx)(n,{className:$.list,children:e.items.map((e,n)=>(0,u.jsx)(`li`,{children:Ye(e,t,`${r}-${n}`)},n))},r)}default:return(0,u.jsx)(`p`,{className:$.paragraph,children:Ye(e.text,t,r)},r)}})}var Qe=/\[(\d+)\]/g,$e=new Set([`nothingFound`,`searchOrAskDisabled`,`searchOrAskUnavailable`,`http404`]);function et(e){let t=e.field.split(`.`)[0];return e.value===`true`?t:e.value===`false`?`not ${t}`:e.value==null?e.min!=null&&e.max!=null?e.min===e.max?`${t} ${e.min}`:`${t} ${e.min}–${e.max}`:e.min==null?`${t} ≤ ${e.max}`:`${t} ≥ ${e.min}`:e.value}var tt=({question:e,proactive:t=!1,followUps:n=!1,onSourceClick:r,label:i=`Answer`,renderAnswer:a=Ze,onFollowUp:o,onStatusChange:s,onFilters:l,onPicks:p,listPicks:m=!0,filterLabel:h=et,fill:g=!1,className:_=``})=>{let v=qe(),{showPicks:y}=D(),b=(0,c.useRef)(y);b.current=y,(0,c.useEffect)(()=>()=>b.current?.(null),[]);let{ask:x,reset:S,stop:C,status:w,openSource:T}=v,[E,O]=(0,c.useState)(!1),[k,A]=(0,c.useState)([]),[j,M]=(0,c.useState)(``),N=(0,c.useRef)([]),P=(0,c.useRef)(null),F=(0,c.useRef)(null),I=(0,c.useRef)(!0);(0,c.useEffect)(()=>{A([]),N.current=[],b.current?.(null),e?.trim()?x(e,[],{proactive:t}):S()},[e,x,S]),(0,c.useEffect)(()=>{s?.(w)},[w,s]);let L=(0,c.useRef)(void 0);(0,c.useEffect)(()=>{v.filters&&v.filters!==L.current&&(L.current=v.filters,l?.(v.filters))},[v.filters,l]);let R=(0,c.useRef)(void 0);(0,c.useEffect)(()=>{if(v.picks&&v.picks!==R.current){R.current=v.picks;let e={...v.picks,askId:v.picks.askId??v.askId};p?.(e),m&&!t&&y?.(e)}},[v.picks,v.askId,p,m,t,y]),(0,c.useEffect)(()=>{let e=F.current;g&&e&&I.current&&(e.scrollTop=e.scrollHeight)},[g,v.answer,v.steps.length,w,k.length]);let z=()=>{let e=F.current;e&&(I.current=e.scrollHeight-e.scrollTop-e.clientHeight<40)},B=e=>e&&(0,u.jsxs)(`div`,{className:$.searched,children:[(0,u.jsxs)(`span`,{className:$.searchedLabel,children:[e.more?`${e.found}+`:e.found,` found`]}),e.filters.map((e,t)=>(0,u.jsx)(d.Chip,{children:h(e)},t)),e.text&&(0,u.jsxs)(`span`,{className:$.searchedLabel,children:[`“`,e.text,`”`]}),e.sort&&(0,u.jsxs)(`span`,{className:$.searchedLabel,children:[`sorted by `,e.sort.field.split(`.`)[0],`, `,e.sort.descending?`largest`:`smallest`,` first`]})]});if(w===`idle`&&k.length===0)return null;let V=(e,t)=>n=>{n.preventDefault(),T(e,t),r?.(e)},H=(e,t)=>n=>{let i=e.find(e=>e.n===n);return(0,u.jsx)(d.CitationRef,{n,title:i?.title,onClick:i&&r?V(i,t):void 0})},U=(e,t,n)=>{let r=new Set([...e.matchAll(Qe)].map(e=>Number(e[1])));return n&&r.size>0?t.filter(e=>r.has(e.n)):t.slice(0,3)},W=(e,t,n,i,a=!1)=>{let o=a?t:U(e,t,n);return o.length>0&&(0,u.jsx)(d.CitationList,{label:a?`Picked`:void 0,items:o.map(e=>({n:e.n,title:e.title,onClick:r?V(e,i):void 0}))})},G=()=>{navigator.clipboard?.writeText(v.answer.replace(Qe,``)).catch(()=>{}),O(!0),setTimeout(()=>O(!1),2e3)},K=e=>{if(!v.busy&&e.trim()){if(w===`answered`&&v.answer){let e={question:v.question,answer:v.answer,sources:v.sources,askId:v.askId,filters:v.filters,picks:v.picks};A(t=>[...t,e]),N.current=[...N.current,{question:e.question,answer:e.answer,...e.picks?{shown:{picks:e.picks.picks.map(e=>({documentKey:e.documentKey,title:e.title}))}}:e.filters?{shown:{filters:e.filters.filters,text:e.filters.text,sort:e.filters.sort??null}}:{}}]}M(``),x(e,N.current)}},q=n?()=>P.current?.focus():o;return(0,u.jsxs)(`div`,{className:`${$.panel} ${g?$.fill:``} ${_}`,"aria-live":`polite`,"aria-busy":v.busy,children:[(0,u.jsxs)(`div`,{ref:F,className:$.thread,onScroll:g?z:void 0,children:[k.map((e,t)=>(0,u.jsxs)(`div`,{className:$.turn,children:[(0,u.jsx)(d.UserMessage,{children:e.question}),(0,u.jsxs)(d.AssistantMessage,{label:i,children:[B(e.filters),(0,u.jsx)(`div`,{className:$.answer,children:a(e.answer,H(e.sources,e.askId))}),W(e.answer,e.sources,!0,e.askId,!!e.picks)]})]},t)),w!==`idle`&&(0,u.jsxs)(`div`,{className:$.turn,children:[(0,u.jsx)(d.UserMessage,{children:v.question}),(0,u.jsxs)(d.AssistantMessage,{label:i,children:[B(v.filters),v.answer&&(0,u.jsx)(`div`,{className:$.answer,children:a(v.answer,H(v.sources))}),w===`searching`&&v.steps.length>0&&(0,u.jsxs)(`div`,{className:$.steps,children:[v.steps.slice(0,-1).map((e,t)=>(0,u.jsx)(`span`,{className:$.stepDone,children:e},t)),(0,u.jsxs)(d.StreamStatus,{children:[v.steps[v.steps.length-1],`…`]})]}),w===`searching`&&v.steps.length===0&&(0,u.jsx)(d.StreamStatus,{children:`Searching…`}),w===`writing`&&(0,u.jsx)(d.StreamStatus,{spinner:`grow`,children:`Writing…`}),w===`error`&&(0,u.jsxs)(d.Alert,{variant:`default`,icon:null,children:[(0,u.jsx)(d.AlertTitle,{children:v.error?.code===`nothingFound`?`Nothing to answer from`:`The answer did not come through`}),(0,u.jsx)(d.AlertDescription,{children:v.error?.code===`nothingFound`?`The search found no records about this. Try other words, or search instead.`:v.error?.message}),!$e.has(v.error?.code??``)&&(0,u.jsx)(`div`,{className:$.action,children:(0,u.jsx)(d.Button,{variant:`secondary`,size:`micro`,iconLeft:(0,u.jsx)(f.Refresh,{}),onClick:()=>x(v.question,N.current),children:`Try again`})})]}),w===`limited`&&v.limit===`budget`&&(0,u.jsxs)(d.Alert,{variant:`default`,icon:null,children:[(0,u.jsx)(d.AlertTitle,{children:`No more answers today`}),(0,u.jsx)(d.AlertDescription,{children:`This site has answered all the questions it can for today. Search still works, and asking is back tomorrow.`})]}),w===`limited`&&v.limit!==`budget`&&(0,u.jsxs)(d.Alert,{variant:`default`,icon:null,children:[(0,u.jsx)(d.AlertTitle,{children:`Too many questions for now`}),(0,u.jsxs)(d.AlertDescription,{children:[`You can ask again in about `,v.retryAfterSeconds&&v.retryAfterSeconds>90?`${Math.ceil(v.retryAfterSeconds/60)} minutes`:`a minute`,`. Search still works in the meantime.`]})]}),w!==`error`&&w!==`limited`&&W(v.answer,v.sources,w===`answered`,void 0,!!v.picks),w===`answered`&&(0,u.jsx)(d.AnswerActions,{onCopy:G,copied:E,onFollowUp:q})]})]})]}),n&&(0,u.jsx)(d.Composer,{ref:P,value:j,onChange:M,onSend:K,onStop:C,streaming:v.busy,placeholder:`Ask a follow-up…`,"aria-label":`Ask a follow-up`})]})};exports.ActiveFiltersPanel=J,exports.AskPanel=tt,exports.BucketFilterPanel=Fe,exports.DEFAULT_THRESHOLDS=k,exports.FilterPanelSkeleton=Se,exports.IndxApiError=p,exports.QuickAnswer=G,exports.RangeFilterPanel=Me,exports.STRICT_MATCH=F,exports.SearchContext=T,exports.SearchErrorBoundary=Ue,exports.SearchInput=ne,exports.SearchProvider=E,exports.SearchResult=Z,exports.SearchResultRow=ye,exports.SearchResults=_e,exports.SearchResultsMessage=ae,exports.SearchResultsSkeleton=le,exports.SearchSettingsPanel=He,exports.SearchSetupError=m,exports.SortByPanel=Le,exports.ValueFilterPanel=Ee,exports.describeSearchError=h,exports.isIdentifier=j,exports.localFilters=de,exports.nextOffer=P,exports.pageMode=O,exports.triggers=N,exports.useAsk=qe,exports.useFilterSuggestion=fe,exports.useHybridSearch=Ge,exports.useSearch=D,exports.useSearchContext=D,exports.useSearchOrAsk=H,exports.useVectorSearch=We;
package/dist/index.d.ts CHANGED
@@ -38,7 +38,7 @@ export type { UseSearchOrAskOptions, SearchOrAskState, QuickState } from './hook
38
38
  export { useFilterSuggestion } from './hooks/useFilterSuggestion';
39
39
  export type { FilterSuggestion, FilterSuggestionResult } from './hooks/useFilterSuggestion';
40
40
  export { useAsk } from './hooks/useAsk';
41
- export type { AskSource, AskStatus, AskState, AskTurn, AskFilters, AskPick, AskPicks } from './hooks/useAsk';
41
+ export type { AskSource, AskStatus, AskState, AskStep, AskTurn, AskFilters, AskPick, AskPicks } from './hooks/useAsk';
42
42
  export { AskPanel } from './components/AskPanel';
43
43
  export { QuickAnswer } from './components/QuickAnswer';
44
44
  export type { QuickAnswerProps } from './components/QuickAnswer';
package/dist/index.es.js CHANGED
@@ -3358,7 +3358,8 @@ var It = {
3358
3358
  status: "idle",
3359
3359
  answer: "",
3360
3360
  sources: [],
3361
- steps: []
3361
+ steps: [],
3362
+ stepDetails: []
3362
3363
  };
3363
3364
  function Lt() {
3364
3365
  let e = ye(), { url: t, team: n, dataset: r, authenticatedFetch: a } = e, s = c(e);
@@ -3375,7 +3376,8 @@ function Lt() {
3375
3376
  status: "searching",
3376
3377
  answer: "",
3377
3378
  sources: [],
3378
- steps: []
3379
+ steps: [],
3380
+ stepDetails: []
3379
3381
  });
3380
3382
  let u = "", f = null, m = () => {
3381
3383
  f = null;
@@ -3439,10 +3441,11 @@ function Lt() {
3439
3441
  }
3440
3442
  for await (let { event: t, data: n } of ke(e.body)) switch (t) {
3441
3443
  case "status": {
3442
- let e = n.step;
3443
- e && d((t) => ({
3444
+ let e = n;
3445
+ e.step && d((t) => ({
3444
3446
  ...t,
3445
- steps: [...t.steps, e]
3447
+ steps: [...t.steps, e.step],
3448
+ stepDetails: [...t.stepDetails, e]
3446
3449
  }));
3447
3450
  break;
3448
3451
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indxsearch/intrface",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "Indx Search interface components for React. Provides ready-to-use filter panels, search inputs, faceted navigation, and sorting components. Built on @indxsearch/systm.",
5
5
  "keywords": [
6
6
  "indx",