@sisense/sdk-ui 1.17.0 → 1.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai.cjs +1 -1
- package/dist/ai.js +1 -1
- package/dist/index.cjs +38 -38
- package/dist/index.js +375 -374
- package/dist/{useQuery-ChZNmTT3.cjs → useQuery-CFlf48eQ.cjs} +34 -34
- package/dist/{useQuery-C6PPvTP0.js → useQuery-DLPVGDKo.js} +1071 -1049
- package/package.json +7 -7
package/dist/ai.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ne=Object.defineProperty,Ie=Object.defineProperties;var Oe=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var X=(e,t,o)=>t in e?Ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,w=(e,t)=>{for(var o in t||(t={}))de.call(t,o)&&X(e,o,t[o]);if(Z)for(var o of Z(t))ue.call(t,o)&&X(e,o,t[o]);return e},M=(e,t)=>Ie(e,Oe(t));var he=(e,t)=>{var o={};for(var s in e)de.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(e!=null&&Z)for(var s of Z(e))t.indexOf(s)<0&&ue.call(e,s)&&(o[s]=e[s]);return o};var S=(e,t,o)=>(X(e,typeof t!="symbol"?t+"":t,o),o);var I=(e,t,o)=>new Promise((s,i)=>{var a=d=>{try{u(o.next(d))}catch(h){i(h)}},l=d=>{try{u(o.throw(d))}catch(h){i(h)}},u=d=>d.done?s(d.value):Promise.resolve(d.value).then(a,l);u((o=o.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./useQuery-ChZNmTT3.cjs"),n=require("react/jsx-runtime"),c=require("react"),k=require("./get-widget-options-D4UHj7o5.cjs");function We(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const s=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,s.get?s:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const B=We(c);class Ae extends r.Subscribable{constructor(t,o){super(),this.client=t,this.setOptions(o),this.bindMethods(),this.updateResult()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var o;const s=this.options;this.options=this.client.defaultMutationOptions(t),r.shallowEqualObjects(s,this.options)||this.client.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.currentMutation,observer:this}),(o=this.currentMutation)==null||o.setOptions(this.options)}onUnsubscribe(){if(!this.hasListeners()){var t;(t=this.currentMutation)==null||t.removeObserver(this)}}onMutationUpdate(t){this.updateResult();const o={listeners:!0};t.type==="success"?o.onSuccess=!0:t.type==="error"&&(o.onError=!0),this.notify(o)}getCurrentResult(){return this.currentResult}reset(){this.currentMutation=void 0,this.updateResult(),this.notify({listeners:!0})}mutate(t,o){return this.mutateOptions=o,this.currentMutation&&this.currentMutation.removeObserver(this),this.currentMutation=this.client.getMutationCache().build(this.client,M(w({},this.options),{variables:typeof t!="undefined"?t:this.options.variables})),this.currentMutation.addObserver(this),this.currentMutation.execute()}updateResult(){const t=this.currentMutation?this.currentMutation.state:r.getDefaultState(),o=M(w({},t),{isLoading:t.status==="loading",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset});this.currentResult=o}notify(t){r.notifyManager.batch(()=>{if(this.mutateOptions&&this.hasListeners()){if(t.onSuccess){var o,s,i,a;(o=(s=this.mutateOptions).onSuccess)==null||o.call(s,this.currentResult.data,this.currentResult.variables,this.currentResult.context),(i=(a=this.mutateOptions).onSettled)==null||i.call(a,this.currentResult.data,null,this.currentResult.variables,this.currentResult.context)}else if(t.onError){var l,u,d,h;(l=(u=this.mutateOptions).onError)==null||l.call(u,this.currentResult.error,this.currentResult.variables,this.currentResult.context),(d=(h=this.mutateOptions).onSettled)==null||d.call(h,void 0,this.currentResult.error,this.currentResult.variables,this.currentResult.context)}}t.listeners&&this.listeners.forEach(({listener:g})=>{g(this.currentResult)})})}}function oe(e,t,o){const s=r.parseMutationArgs(e,t),i=r.useQueryClient({context:s.context}),[a]=B.useState(()=>new Ae(i,s));B.useEffect(()=>{a.setOptions(s)},[a,s]);const l=r.useSyncExternalStore(B.useCallback(d=>a.subscribe(r.notifyManager.batchCalls(d)),[a]),()=>a.getCurrentResult(),()=>a.getCurrentResult()),u=B.useCallback((d,h)=>{a.mutate(d,h).catch(qe)},[a]);if(l.error&&r.shouldThrowError(a.options.useErrorBoundary,[l.error]))throw l.error;return M(w({},l),{mutate:u,mutateAsync:l.mutate})}function qe(){}class ze{constructor(t){S(this,"httpClient");S(this,"getChatContexts",()=>I(this,null,function*(){return(yield this.httpClient.get("api/datasources?sharedWith=r,w"))||[]}));S(this,"getNlgQueryResult",t=>this.httpClient.post("api/v2/ai/nlg/queryResult",t));S(this,"getQueryRecommendations",(t,o)=>this.httpClient.get(`api/v2/ai/recommendations/query/${t}/${o.numOfRecommendations}`));S(this,"setLlmConfig",t=>this.httpClient.post("api/v2/settings/ai/llmProvider",t).catch(o=>{console.error("Unable to set llm config",o)}));S(this,"getAllChats",()=>this.httpClient.get("api/v2/ai/chats"));S(this,"getChatById",t=>this.httpClient.get(`api/v2/ai/chats/${t}`));S(this,"createChat",t=>this.httpClient.post("api/v2/ai/chats",{sourceId:t}));S(this,"postChat",(t,o)=>this.httpClient.post(`api/v2/ai/chats/${t}`,o));S(this,"deleteChatHistory",t=>this.httpClient.delete(`api/v2/ai/chats/${t}/history`));S(this,"sendFeedback",t=>this.httpClient.post("api/v2/ai/feedback",t));S(this,"getDataSourceFields",t=>this.httpClient.post(`api/datasources/${encodeURIComponent(t)}/fields/search`,{offset:0,count:9999}));S(this,"ai",{getNlgQueryResult:this.getNlgQueryResult,getQueryRecommendations:this.getQueryRecommendations,setLlmConfig:this.setLlmConfig,sendFeedback:this.sendFeedback,getDataSourceFields:this.getDataSourceFields,chat:{getAll:this.getAllChats,getById:this.getChatById,create:this.createChat,post:this.postChat,clearHistory:this.deleteChatHistory}});this.httpClient=t}}const Qe=new r.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnMount:!1}}}),fe=c.createContext(void 0),H=()=>c.useContext(fe),Ve=({children:e})=>{const{app:t}=r.useSisenseContext(),o=c.useMemo(()=>t?new ze(t.httpClient):void 0,[t]);return n.jsx(fe.Provider,{value:o,children:n.jsx(r.QueryClientProvider,{client:Qe,children:e})})};function Ze({children:e}){return n.jsx(Ve,{children:e})}const re=(e,t=!0)=>{const o=c.useMemo(()=>{var g,p;if("jaql"in e)return e;{let C;k.isDataSourceInfo(e.dataSource)?C={title:e.dataSource.title,live:e.dataSource.type==="live"}:C=e.dataSource;const{filters:v=[],relations:y}=k.getFilterListAndRelations(e.filters),{metadata:x,filterRelations:f}=r.getJaqlQueryPayload({dataSource:e.dataSource,attributes:(g=e.dimensions)!=null?g:[],measures:(p=e.measures)!=null?p:[],filters:v,filterRelations:y,highlights:[]},!0);return{jaql:{datasource:C,metadata:x,filterRelations:f}}}},[e]),s=H(),{data:i,error:a,isError:l,isLoading:u,isSuccess:d,refetch:h}=r.useQuery({queryKey:["getNlgQueryResult",o,s],queryFn:()=>s==null?void 0:s.ai.getNlgQueryResult(o),select:g=>{var p;return(p=g==null?void 0:g.data)==null?void 0:p.answer},enabled:!!s&&t});return{isLoading:u,isError:l,isSuccess:d,data:i,error:a,refetch:c.useCallback(()=>{h()},[h])}},Ge=e=>{const s=e,{enabled:t}=s,o=he(s,["enabled"]);return re(o,t)},_e=r.withTracking("useGetNlgQueryResult")(Ge),me=Object.freeze({enableFollowupQuestions:!1,enableHeader:!0,enableInsights:!0,numOfRecommendations:4,numOfRecentPrompts:5,inputPromptText:'Ask a question or type "/" for ideas',welcomeText:"Welcome to the Analytics Assistant! I can help you explore and gain insights from your data.",suggestionsWelcomeText:"Some questions you may have:"}),be=c.createContext(w({},me)),P=()=>c.useContext(be),Ue=({children:e,value:t})=>{const o=Object.entries(t).reduce((s,[i,a])=>(a!==void 0&&(s[i]=a),s),w({},me));return n.jsx(be.Provider,{value:o,children:e})},ye=e=>{const{contextTitle:t,count:o}=e,s=H(),{numOfRecommendations:i}=P(),a=o!=null?o:i,{isLoading:l,isError:u,isSuccess:d,data:h,error:g,refetch:p}=r.useQuery({queryKey:["getQueryRecommendations",t,a,s],queryFn:()=>s==null?void 0:s.ai.getQueryRecommendations(t,{numOfRecommendations:a}),enabled:!!s});return{isLoading:l,isError:u,isSuccess:d,data:h!=null?h:[],error:g,refetch:c.useCallback(()=>{p()},[p])}},Ke=r.withTracking("useGetQueryRecommendations")(ye),se="Oh snap, something went wrong. Please try again later.",Ye="Oh snap, something went wrong. Please try again later or try asking a different question.",Je="Something went wrong and we were unable to retrieve the chat thread. Let's start over!",ve="Chat unavailable. Please try again later.",ie="chatHistory",Xe=e=>{const t=H(),{hideHistory:o}=P();return r.useQuery({queryKey:[ie,e,t],queryFn:()=>I(exports,null,function*(){if(!t||!e)return;if(o)return[];const s=yield t.ai.chat.getById(e);return s==null?void 0:s.chatHistory}),enabled:!!t&&!!e})},we=e=>{const t=H(),o=r.useQueryClient();return oe({mutationFn:()=>I(exports,null,function*(){if(!(!t||!e))return t.ai.chat.clearHistory(e)}),onError:s=>{console.error("Error when clearing history:",s)},onSettled:()=>{e&&o.setQueriesData([ie,e],[])}})},ke=e=>{const{data:t,isLoading:o,isError:s}=Xe(e),{mutate:i}=we(e);return c.useEffect(()=>{s&&i()},[s,i]),{history:t,isLoading:o,isError:s}},je=()=>{const e=H(),{data:t,isLoading:o,fetchStatus:s}=r.useQuery({queryKey:["getDataTopics",e],queryFn:()=>I(exports,null,function*(){if(e)return e.getChatContexts()}),enabled:!!e});return{data:t,isLoading:o,fetchStatus:s}},Se=()=>{const e=H(),{data:t,isLoading:o}=r.useQuery({queryKey:["getAllChats",e],queryFn:()=>e==null?void 0:e.ai.chat.getAll(),enabled:!!e});return{data:t!=null?t:[],isLoading:o}},et=(e,t)=>{const o=r.useQueryClient(),s=H(),i=oe({mutationFn:()=>I(exports,null,function*(){if(!(!s||!e))return s.ai.chat.create(e)}),onSuccess:()=>o.invalidateQueries(["getAllChats"])});return c.useEffect(()=>{t&&i.isIdle&&i.mutate()},[t,i]),i},tt=e=>{switch(e.responseType=e.responseType.toLowerCase(),e.responseType){case"nlq":return{content:JSON.stringify(e.data),role:"assistant",type:"nlq"};case"text":case"error":return{content:e.data.answer,role:"assistant"};default:throw Error(`Received unknown responseType, raw response=${JSON.stringify(e)}`)}},nt=e=>{const t=r.useQueryClient(),o=c.useCallback(u=>{e&&t.setQueriesData([ie,e],d=>d&&[...d,u])},[t,e]),{enableFollowupQuestions:s}=P(),i=H(),{mutate:a,isLoading:l}=oe({mutationFn:u=>I(exports,null,function*(){if(!(!i||!e))return i.ai.chat.post(e,{text:u,options:{enableFollowup:s}})}),onMutate:u=>{o({content:u,role:"user"})},onError:u=>{u instanceof Error&&(console.error("Error when sending message:",u.message),o({content:Ye,role:"assistant"}))},onSuccess:u=>{u&&o(tt(u))}});return{mutate:a,isLoading:l}},ae=e=>!!e&&"type"in e&&e.type==="nlq",Te=e=>{var T,L;const{data:t,isLoading:o}=je(),{data:s,isLoading:i}=Se(),a=(T=t==null?void 0:t.find(j=>j.title===e))==null?void 0:T.title,l=(L=s.find(j=>j.contextTitle===a))==null?void 0:L.chatId,u=o||!!a,d=i||!!l,[h,g]=c.useState(null),{isError:p}=et(a,u&&!d),{history:C,isLoading:v,isError:y}=ke(l);c.useEffect(()=>{p?g(new Error(ve)):y&&g(new Error(Je))},[p,y]);const{mutate:x,isLoading:f}=nt(l),m=c.useMemo(()=>{if(C!=null&&C.length){const j=C[C.length-1];if(ae(j))return JSON.parse(j.content)}return null},[C]);return{chatId:l,history:C!=null?C:[],lastNlqResponse:m,sendMessage:x,isAwaitingResponse:f,isLoading:v,lastError:h}},ot=({contextTitle:e})=>{var i;const{data:t}=Se(),o=(i=t.find(a=>a.contextTitle===e))==null?void 0:i.chatId,{history:s}=ke(o);return c.useMemo(()=>{if(s!=null&&s.length){const a=s[s.length-1];if(ae(a))return JSON.parse(a.content)}return null},[s])},rt=e=>{const t=H(),{data:o,isLoading:s}=r.useQuery({queryKey:["getDataSourceFields",e,t],queryFn:()=>e?t==null?void 0:t.ai.getDataSourceFields(e):void 0,select:i=>i,enabled:!!t&&!!e});return{data:o,isLoading:s}},st=500,it=500,at=500,lt=900,ct=r.newStyled.div`
|
|
1
|
+
"use strict";var Ne=Object.defineProperty,Ie=Object.defineProperties;var Oe=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var X=(e,t,o)=>t in e?Ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,w=(e,t)=>{for(var o in t||(t={}))de.call(t,o)&&X(e,o,t[o]);if(Z)for(var o of Z(t))ue.call(t,o)&&X(e,o,t[o]);return e},M=(e,t)=>Ie(e,Oe(t));var he=(e,t)=>{var o={};for(var s in e)de.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(e!=null&&Z)for(var s of Z(e))t.indexOf(s)<0&&ue.call(e,s)&&(o[s]=e[s]);return o};var S=(e,t,o)=>(X(e,typeof t!="symbol"?t+"":t,o),o);var I=(e,t,o)=>new Promise((s,i)=>{var a=d=>{try{u(o.next(d))}catch(h){i(h)}},l=d=>{try{u(o.throw(d))}catch(h){i(h)}},u=d=>d.done?s(d.value):Promise.resolve(d.value).then(a,l);u((o=o.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./useQuery-CFlf48eQ.cjs"),n=require("react/jsx-runtime"),c=require("react"),k=require("./get-widget-options-D4UHj7o5.cjs");function We(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const s=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,s.get?s:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const B=We(c);class Ae extends r.Subscribable{constructor(t,o){super(),this.client=t,this.setOptions(o),this.bindMethods(),this.updateResult()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var o;const s=this.options;this.options=this.client.defaultMutationOptions(t),r.shallowEqualObjects(s,this.options)||this.client.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.currentMutation,observer:this}),(o=this.currentMutation)==null||o.setOptions(this.options)}onUnsubscribe(){if(!this.hasListeners()){var t;(t=this.currentMutation)==null||t.removeObserver(this)}}onMutationUpdate(t){this.updateResult();const o={listeners:!0};t.type==="success"?o.onSuccess=!0:t.type==="error"&&(o.onError=!0),this.notify(o)}getCurrentResult(){return this.currentResult}reset(){this.currentMutation=void 0,this.updateResult(),this.notify({listeners:!0})}mutate(t,o){return this.mutateOptions=o,this.currentMutation&&this.currentMutation.removeObserver(this),this.currentMutation=this.client.getMutationCache().build(this.client,M(w({},this.options),{variables:typeof t!="undefined"?t:this.options.variables})),this.currentMutation.addObserver(this),this.currentMutation.execute()}updateResult(){const t=this.currentMutation?this.currentMutation.state:r.getDefaultState(),o=M(w({},t),{isLoading:t.status==="loading",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset});this.currentResult=o}notify(t){r.notifyManager.batch(()=>{if(this.mutateOptions&&this.hasListeners()){if(t.onSuccess){var o,s,i,a;(o=(s=this.mutateOptions).onSuccess)==null||o.call(s,this.currentResult.data,this.currentResult.variables,this.currentResult.context),(i=(a=this.mutateOptions).onSettled)==null||i.call(a,this.currentResult.data,null,this.currentResult.variables,this.currentResult.context)}else if(t.onError){var l,u,d,h;(l=(u=this.mutateOptions).onError)==null||l.call(u,this.currentResult.error,this.currentResult.variables,this.currentResult.context),(d=(h=this.mutateOptions).onSettled)==null||d.call(h,void 0,this.currentResult.error,this.currentResult.variables,this.currentResult.context)}}t.listeners&&this.listeners.forEach(({listener:g})=>{g(this.currentResult)})})}}function oe(e,t,o){const s=r.parseMutationArgs(e,t),i=r.useQueryClient({context:s.context}),[a]=B.useState(()=>new Ae(i,s));B.useEffect(()=>{a.setOptions(s)},[a,s]);const l=r.useSyncExternalStore(B.useCallback(d=>a.subscribe(r.notifyManager.batchCalls(d)),[a]),()=>a.getCurrentResult(),()=>a.getCurrentResult()),u=B.useCallback((d,h)=>{a.mutate(d,h).catch(qe)},[a]);if(l.error&&r.shouldThrowError(a.options.useErrorBoundary,[l.error]))throw l.error;return M(w({},l),{mutate:u,mutateAsync:l.mutate})}function qe(){}class ze{constructor(t){S(this,"httpClient");S(this,"getChatContexts",()=>I(this,null,function*(){return(yield this.httpClient.get("api/datasources?sharedWith=r,w"))||[]}));S(this,"getNlgQueryResult",t=>this.httpClient.post("api/v2/ai/nlg/queryResult",t));S(this,"getQueryRecommendations",(t,o)=>this.httpClient.get(`api/v2/ai/recommendations/query/${t}/${o.numOfRecommendations}`));S(this,"setLlmConfig",t=>this.httpClient.post("api/v2/settings/ai/llmProvider",t).catch(o=>{console.error("Unable to set llm config",o)}));S(this,"getAllChats",()=>this.httpClient.get("api/v2/ai/chats"));S(this,"getChatById",t=>this.httpClient.get(`api/v2/ai/chats/${t}`));S(this,"createChat",t=>this.httpClient.post("api/v2/ai/chats",{sourceId:t}));S(this,"postChat",(t,o)=>this.httpClient.post(`api/v2/ai/chats/${t}`,o));S(this,"deleteChatHistory",t=>this.httpClient.delete(`api/v2/ai/chats/${t}/history`));S(this,"sendFeedback",t=>this.httpClient.post("api/v2/ai/feedback",t));S(this,"getDataSourceFields",t=>this.httpClient.post(`api/datasources/${encodeURIComponent(t)}/fields/search`,{offset:0,count:9999}));S(this,"ai",{getNlgQueryResult:this.getNlgQueryResult,getQueryRecommendations:this.getQueryRecommendations,setLlmConfig:this.setLlmConfig,sendFeedback:this.sendFeedback,getDataSourceFields:this.getDataSourceFields,chat:{getAll:this.getAllChats,getById:this.getChatById,create:this.createChat,post:this.postChat,clearHistory:this.deleteChatHistory}});this.httpClient=t}}const Qe=new r.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnMount:!1}}}),fe=c.createContext(void 0),H=()=>c.useContext(fe),Ve=({children:e})=>{const{app:t}=r.useSisenseContext(),o=c.useMemo(()=>t?new ze(t.httpClient):void 0,[t]);return n.jsx(fe.Provider,{value:o,children:n.jsx(r.QueryClientProvider,{client:Qe,children:e})})};function Ze({children:e}){return n.jsx(Ve,{children:e})}const re=(e,t=!0)=>{const o=c.useMemo(()=>{var g,p;if("jaql"in e)return e;{let C;k.isDataSourceInfo(e.dataSource)?C={title:e.dataSource.title,live:e.dataSource.type==="live"}:C=e.dataSource;const{filters:v=[],relations:y}=k.getFilterListAndRelations(e.filters),{metadata:x,filterRelations:f}=r.getJaqlQueryPayload({dataSource:e.dataSource,attributes:(g=e.dimensions)!=null?g:[],measures:(p=e.measures)!=null?p:[],filters:v,filterRelations:y,highlights:[]},!0);return{jaql:{datasource:C,metadata:x,filterRelations:f}}}},[e]),s=H(),{data:i,error:a,isError:l,isLoading:u,isSuccess:d,refetch:h}=r.useQuery({queryKey:["getNlgQueryResult",o,s],queryFn:()=>s==null?void 0:s.ai.getNlgQueryResult(o),select:g=>{var p;return(p=g==null?void 0:g.data)==null?void 0:p.answer},enabled:!!s&&t});return{isLoading:u,isError:l,isSuccess:d,data:i,error:a,refetch:c.useCallback(()=>{h()},[h])}},Ge=e=>{const s=e,{enabled:t}=s,o=he(s,["enabled"]);return re(o,t)},_e=r.withTracking("useGetNlgQueryResult")(Ge),me=Object.freeze({enableFollowupQuestions:!1,enableHeader:!0,enableInsights:!0,numOfRecommendations:4,numOfRecentPrompts:5,inputPromptText:'Ask a question or type "/" for ideas',welcomeText:"Welcome to the Analytics Assistant! I can help you explore and gain insights from your data.",suggestionsWelcomeText:"Some questions you may have:"}),be=c.createContext(w({},me)),P=()=>c.useContext(be),Ue=({children:e,value:t})=>{const o=Object.entries(t).reduce((s,[i,a])=>(a!==void 0&&(s[i]=a),s),w({},me));return n.jsx(be.Provider,{value:o,children:e})},ye=e=>{const{contextTitle:t,count:o}=e,s=H(),{numOfRecommendations:i}=P(),a=o!=null?o:i,{isLoading:l,isError:u,isSuccess:d,data:h,error:g,refetch:p}=r.useQuery({queryKey:["getQueryRecommendations",t,a,s],queryFn:()=>s==null?void 0:s.ai.getQueryRecommendations(t,{numOfRecommendations:a}),enabled:!!s});return{isLoading:l,isError:u,isSuccess:d,data:h!=null?h:[],error:g,refetch:c.useCallback(()=>{p()},[p])}},Ke=r.withTracking("useGetQueryRecommendations")(ye),se="Oh snap, something went wrong. Please try again later.",Ye="Oh snap, something went wrong. Please try again later or try asking a different question.",Je="Something went wrong and we were unable to retrieve the chat thread. Let's start over!",ve="Chat unavailable. Please try again later.",ie="chatHistory",Xe=e=>{const t=H(),{hideHistory:o}=P();return r.useQuery({queryKey:[ie,e,t],queryFn:()=>I(exports,null,function*(){if(!t||!e)return;if(o)return[];const s=yield t.ai.chat.getById(e);return s==null?void 0:s.chatHistory}),enabled:!!t&&!!e})},we=e=>{const t=H(),o=r.useQueryClient();return oe({mutationFn:()=>I(exports,null,function*(){if(!(!t||!e))return t.ai.chat.clearHistory(e)}),onError:s=>{console.error("Error when clearing history:",s)},onSettled:()=>{e&&o.setQueriesData([ie,e],[])}})},ke=e=>{const{data:t,isLoading:o,isError:s}=Xe(e),{mutate:i}=we(e);return c.useEffect(()=>{s&&i()},[s,i]),{history:t,isLoading:o,isError:s}},je=()=>{const e=H(),{data:t,isLoading:o,fetchStatus:s}=r.useQuery({queryKey:["getDataTopics",e],queryFn:()=>I(exports,null,function*(){if(e)return e.getChatContexts()}),enabled:!!e});return{data:t,isLoading:o,fetchStatus:s}},Se=()=>{const e=H(),{data:t,isLoading:o}=r.useQuery({queryKey:["getAllChats",e],queryFn:()=>e==null?void 0:e.ai.chat.getAll(),enabled:!!e});return{data:t!=null?t:[],isLoading:o}},et=(e,t)=>{const o=r.useQueryClient(),s=H(),i=oe({mutationFn:()=>I(exports,null,function*(){if(!(!s||!e))return s.ai.chat.create(e)}),onSuccess:()=>o.invalidateQueries(["getAllChats"])});return c.useEffect(()=>{t&&i.isIdle&&i.mutate()},[t,i]),i},tt=e=>{switch(e.responseType=e.responseType.toLowerCase(),e.responseType){case"nlq":return{content:JSON.stringify(e.data),role:"assistant",type:"nlq"};case"text":case"error":return{content:e.data.answer,role:"assistant"};default:throw Error(`Received unknown responseType, raw response=${JSON.stringify(e)}`)}},nt=e=>{const t=r.useQueryClient(),o=c.useCallback(u=>{e&&t.setQueriesData([ie,e],d=>d&&[...d,u])},[t,e]),{enableFollowupQuestions:s}=P(),i=H(),{mutate:a,isLoading:l}=oe({mutationFn:u=>I(exports,null,function*(){if(!(!i||!e))return i.ai.chat.post(e,{text:u,options:{enableFollowup:s}})}),onMutate:u=>{o({content:u,role:"user"})},onError:u=>{u instanceof Error&&(console.error("Error when sending message:",u.message),o({content:Ye,role:"assistant"}))},onSuccess:u=>{u&&o(tt(u))}});return{mutate:a,isLoading:l}},ae=e=>!!e&&"type"in e&&e.type==="nlq",Te=e=>{var T,L;const{data:t,isLoading:o}=je(),{data:s,isLoading:i}=Se(),a=(T=t==null?void 0:t.find(j=>j.title===e))==null?void 0:T.title,l=(L=s.find(j=>j.contextTitle===a))==null?void 0:L.chatId,u=o||!!a,d=i||!!l,[h,g]=c.useState(null),{isError:p}=et(a,u&&!d),{history:C,isLoading:v,isError:y}=ke(l);c.useEffect(()=>{p?g(new Error(ve)):y&&g(new Error(Je))},[p,y]);const{mutate:x,isLoading:f}=nt(l),m=c.useMemo(()=>{if(C!=null&&C.length){const j=C[C.length-1];if(ae(j))return JSON.parse(j.content)}return null},[C]);return{chatId:l,history:C!=null?C:[],lastNlqResponse:m,sendMessage:x,isAwaitingResponse:f,isLoading:v,lastError:h}},ot=({contextTitle:e})=>{var i;const{data:t}=Se(),o=(i=t.find(a=>a.contextTitle===e))==null?void 0:i.chatId,{history:s}=ke(o);return c.useMemo(()=>{if(s!=null&&s.length){const a=s[s.length-1];if(ae(a))return JSON.parse(a.content)}return null},[s])},rt=e=>{const t=H(),{data:o,isLoading:s}=r.useQuery({queryKey:["getDataSourceFields",e,t],queryFn:()=>e?t==null?void 0:t.ai.getDataSourceFields(e):void 0,select:i=>i,enabled:!!t&&!!e});return{data:o,isLoading:s}},st=500,it=500,at=500,lt=900,ct=r.newStyled.div`
|
|
2
2
|
box-sizing: border-box;
|
|
3
3
|
position: relative;
|
|
4
4
|
display: flex;
|
package/dist/ai.js
CHANGED
|
@@ -36,7 +36,7 @@ var Z = (e, t, n) => new Promise((r, i) => {
|
|
|
36
36
|
}, c = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(s, a);
|
|
37
37
|
c((n = n.apply(e, t)).next());
|
|
38
38
|
});
|
|
39
|
-
import { aW as ht, aX as pt, aY as Ie, aZ as gt, a_ as K, a$ as Ct, b0 as ft, b1 as mt, aD as bt, l as xt, aE as yt, g as vt, aL as _, w as Oe, n as u, c as L, m as b, al as We, V as wt, b2 as kt, Z as St, Y as Rt, $ as ae, b3 as Lt, b4 as Mt, a8 as G, a1 as Q, b5 as Pe, aa as $t, b6 as Et, a3 as Tt, b7 as Ht, a5 as ge, a6 as g, a9 as Bt, b8 as Dt, b9 as Ae, ba as Ft, aj as Nt, M as Te, O as He, ao as It, F as qe } from "./useQuery-
|
|
39
|
+
import { aW as ht, aX as pt, aY as Ie, aZ as gt, a_ as K, a$ as Ct, b0 as ft, b1 as mt, aD as bt, l as xt, aE as yt, g as vt, aL as _, w as Oe, n as u, c as L, m as b, al as We, V as wt, b2 as kt, Z as St, Y as Rt, $ as ae, b3 as Lt, b4 as Mt, a8 as G, a1 as Q, b5 as Pe, aa as $t, b6 as Et, a3 as Tt, b7 as Ht, a5 as ge, a6 as g, a9 as Bt, b8 as Dt, b9 as Ae, ba as Ft, aj as Nt, M as Te, O as He, ao as It, F as qe } from "./useQuery-DLPVGDKo.js";
|
|
40
40
|
import { jsx as o, jsxs as p, Fragment as H } from "react/jsx-runtime";
|
|
41
41
|
import * as q from "react";
|
|
42
42
|
import { createContext as xe, useMemo as F, useContext as ze, useCallback as E, useEffect as le, useState as k, useRef as U, useLayoutEffect as ie, Component as Ot, createElement as me, isValidElement as Wt, memo as Pt, forwardRef as At } from "react";
|