@sisense/sdk-ui 1.34.0 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai.cjs +1 -1
- package/dist/ai.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +3 -3
- package/dist/{use-common-filters-Bw15BNGn.js → use-common-filters-CRL16HJ4.js} +4 -4
- package/dist/{use-common-filters-CqGo6jp3.cjs → use-common-filters-Dx4AeUoy.cjs} +2 -2
- package/package.json +7 -7
package/dist/ai.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ve=Object.defineProperty,_e=Object.defineProperties;var Ue=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var be=(e,n,o)=>n in e?Ve(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o,b=(e,n)=>{for(var o in n||(n={}))ye.call(n,o)&&be(e,o,n[o]);if(U)for(var o of U(n))ve.call(n,o)&&be(e,o,n[o]);return e},v=(e,n)=>_e(e,Ue(n));var we=(e,n)=>{var o={};for(var s in e)ye.call(e,s)&&n.indexOf(s)<0&&(o[s]=e[s]);if(e!=null&&U)for(var s of U(e))n.indexOf(s)<0&&ve.call(e,s)&&(o[s]=e[s]);return o};var N=(e,n,o)=>new Promise((s,r)=>{var i=c=>{try{u(o.next(c))}catch(h){r(h)}},l=c=>{try{u(o.throw(c))}catch(h){r(h)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,l);u((o=o.apply(e,n)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./use-common-filters-CqGo6jp3.cjs"),t=require("./derive-chart-family-C3FH49ux.cjs"),d=require("react"),z=require("./widget-composer-D5_iKTui.cjs"),$=require("react/jsx-runtime");function Ke(e){const n=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(n,o,s.get?s:{enumerable:!0,get:()=>e[o]})}}return n.default=e,Object.freeze(n)}const I=Ke(d);class Je extends a.Subscribable{constructor(n,o){super(),this.client=n,this.setOptions(o),this.bindMethods(),this.updateResult()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(n){var o;const s=this.options;this.options=this.client.defaultMutationOptions(n),a.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 n;(n=this.currentMutation)==null||n.removeObserver(this)}}onMutationUpdate(n){this.updateResult();const o={listeners:!0};n.type==="success"?o.onSuccess=!0:n.type==="error"&&(o.onError=!0),this.notify(o)}getCurrentResult(){return this.currentResult}reset(){this.currentMutation=void 0,this.updateResult(),this.notify({listeners:!0})}mutate(n,o){return this.mutateOptions=o,this.currentMutation&&this.currentMutation.removeObserver(this),this.currentMutation=this.client.getMutationCache().build(this.client,v(b({},this.options),{variables:typeof n!="undefined"?n:this.options.variables})),this.currentMutation.addObserver(this),this.currentMutation.execute()}updateResult(){const n=this.currentMutation?this.currentMutation.state:a.getDefaultState(),o=v(b({},n),{isLoading:n.status==="loading",isSuccess:n.status==="success",isError:n.status==="error",isIdle:n.status==="idle",mutate:this.mutate,reset:this.reset});this.currentResult=o}notify(n){a.notifyManager.batch(()=>{if(this.mutateOptions&&this.hasListeners()){if(n.onSuccess){var o,s,r,i;(o=(s=this.mutateOptions).onSuccess)==null||o.call(s,this.currentResult.data,this.currentResult.variables,this.currentResult.context),(r=(i=this.mutateOptions).onSettled)==null||r.call(i,this.currentResult.data,null,this.currentResult.variables,this.currentResult.context)}else if(n.onError){var l,u,c,h;(l=(u=this.mutateOptions).onError)==null||l.call(u,this.currentResult.error,this.currentResult.variables,this.currentResult.context),(c=(h=this.mutateOptions).onSettled)==null||c.call(h,void 0,this.currentResult.error,this.currentResult.variables,this.currentResult.context)}}n.listeners&&this.listeners.forEach(({listener:g})=>{g(this.currentResult)})})}}function ie(e,n,o){const s=a.parseMutationArgs(e,n),r=a.useQueryClient({context:s.context}),[i]=I.useState(()=>new Je(r,s));I.useEffect(()=>{i.setOptions(s)},[i,s]);const l=a.useSyncExternalStore(I.useCallback(c=>i.subscribe(a.notifyManager.batchCalls(c)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),u=I.useCallback((c,h)=>{i.mutate(c,h).catch(Ye)},[i]);if(l.error&&a.shouldThrowError(i.options.useErrorBoundary,[l.error]))throw l.error;return v(b({},l),{mutate:u,mutateAsync:l.mutate})}function Ye(){}class Te{constructor(n,o=!1){this.volatile=o,this.getChatContexts=()=>N(this,null,function*(){return(yield this.httpClient.get("api/datasources//"))||[]}),this.getNlgInsights=s=>this.httpClient.post("api/v2/ai/nlg/queryResult",s),this.getQueryRecommendations=(s,r)=>this.httpClient.get(`api/v2/ai/recommendations/query/${s}/${r.numOfRecommendations}`),this.getNlqResult=(s,r)=>this.httpClient.post(`api/v2/ai/nlq/query/${s}`,r),this.setLlmConfig=s=>this.httpClient.post("api/v2/settings/ai/llmProvider",s).catch(r=>{console.error("Unable to set llm config",r)}),this.getAllChats=()=>N(this,null,function*(){return this.volatile?[]:this.httpClient.get("api/v2/ai/chats")}),this.getChatById=s=>this.httpClient.get(`api/v2/ai/chats/${s}`),this.createChat=(s,r)=>this.httpClient.post("api/v2/ai/chats",{sourceId:s,volatile:this.volatile,contextDetails:r}),this.postChat=(s,r)=>this.httpClient.post(`api/v2/ai/chats/${s}`,r),this.deleteChatHistory=s=>this.httpClient.delete(`api/v2/ai/chats/${s}/history`),this.sendFeedback=s=>this.httpClient.post("api/v2/ai/feedback",s),this.ai={getNlgInsights:this.getNlgInsights,getNlqResult:this.getNlqResult,getQueryRecommendations:this.getQueryRecommendations,setLlmConfig:this.setLlmConfig,sendFeedback:this.sendFeedback,chat:{getAll:this.getAllChats,getById:this.getChatById,create:this.createChat,post:this.postChat,clearHistory:this.deleteChatHistory}},this.httpClient=n}}const Xe=new a.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnMount:!1}}}),ae=d.createContext(void 0),T=()=>d.useContext(ae),et=({children:e,volatile:n})=>{const{app:o}=t.useSisenseContext(),s=d.useMemo(()=>o?new Te(o.httpClient,n):void 0,[o,n]);return t.jsx(ae.Provider,{value:s,children:t.jsx(a.QueryClientProvider,{client:Xe,children:e})})},Me=d.createContext({}),tt=()=>d.useContext(Me),Re=({children:e})=>{const[n,o]=d.useState({}),s=d.useCallback((l,u)=>{var c;return`${l}_${(c=u==null?void 0:u.dashboardId)!=null?c:""}`},[]),r=d.useCallback((l,u,c)=>{o(h=>v(b({},h),{[s(u,c)]:l}))},[s]),i=d.useCallback((l,u)=>n[s(l,u)],[n,s]);return t.jsx(Me.Provider,{value:{saveChatId:r,getChatId:i},children:e})};function nt({children:e,volatile:n}){return t.jsx(Re,{children:t.jsx(et,{volatile:n,children:e})})}function Le(e){var n,o;if("jaql"in e)return e;{const s=t.convertJaqlDataSource(e.dataSource),{filters:r=[],relations:i}=t.getFilterListAndRelationsJaql(e.filters),{metadata:l,filterRelations:u}=t.getJaqlQueryPayload({dataSource:e.dataSource,attributes:(n=e.dimensions)!=null?n:[],measures:(o=e.measures)!=null?o:[],filters:r,filterRelations:i,highlights:[]},!0),c={jaql:{datasource:s,metadata:l,filterRelations:u}};return e.verbosity&&(c.verbosity=e.verbosity),c}}const Z=(e,n=!0)=>{const o=d.useMemo(()=>Le(e),[e]),s=T(),{data:r,error:i,isError:l,isLoading:u,isSuccess:c,refetch:h}=a.useQuery({queryKey:["getNlgInsights",o,s],queryFn:()=>s==null?void 0:s.ai.getNlgInsights(o),select:g=>{var p;return(p=g==null?void 0:g.data)==null?void 0:p.answer},enabled:!!s&&n});return{isLoading:u,isError:l,isSuccess:c,data:r,error:i,refetch:d.useCallback(()=>{h()},[h])}},Pe=e=>{const s=e,{enabled:n}=s,o=we(s,["enabled"]);return Z(o,n)},ot=a.withTracking("useGetNlgInsights")(Pe),st=a.withTracking("useGetNlgQueryResult")(Pe),rt=["indicator","column","line","table","pie","bar"];function Ee(e){const{dataSource:n,query:o,chartTypes:s}=e;return{contextTitle:typeof n=="string"?n:n.title,request:{text:o,timezone:"UTC",chartTypes:s!=null?s:[...rt]}}}const it=e=>{const{contextTitle:n,request:o}=Ee(e),s=T(),{isLoading:r,isError:i,isSuccess:l,data:u,error:c,refetch:h}=a.useQuery({queryKey:["getNlqResult",n,o,s],queryFn:()=>s==null?void 0:s.ai.getNlqResult(n,o),enabled:!!s&&e.enabled}),g=u?z.toWidgetProps(u,{useCustomizedStyleOptions:e.enableAxisTitlesInWidgetProps||!1}):void 0;return{isLoading:r,isError:i,isSuccess:l,data:g,error:c,refetch:d.useCallback(()=>{h()},[h])}},at=a.withTracking("useGetNlqResult")(it),Ne=4,Ie=e=>{const{contextTitle:n,count:o,enableAxisTitlesInWidgetProps:s,enabled:r}=e,i=T(),l=o!=null?o:Ne,u=(r===void 0||r===!0)&&l>0,{isLoading:c,isError:h,isSuccess:g,data:p,error:C,refetch:x}=a.useQuery({queryKey:["getQueryRecommendations",n,l,i],queryFn:()=>i==null?void 0:i.ai.getQueryRecommendations(n,{numOfRecommendations:l}),enabled:!!i&&u}),y=d.useMemo(()=>p==null?void 0:p.map(f=>v(b({},f),{widgetProps:f.jaql?z.toWidgetProps(f,{useCustomizedStyleOptions:s}):void 0})),[p,s]);return{isLoading:u?c:!1,isError:h,isSuccess:g,data:y!=null?y:void 0,error:C,refetch:d.useCallback(()=>{x()},[x])}},lt=a.withTracking("useGetQueryRecommendations")(Ie),Fe=Object.freeze({enableFollowupQuestions:!1,enableHeader:!0,enableInsights:!0,numOfRecommendations:4,numOfRecentPrompts:5}),Be=d.createContext(b({},Fe)),R=()=>d.useContext(Be),ct=({children:e,value:n})=>{const{t:o}=t.useTranslation(),s=Object.entries(n).reduce((r,[i,l])=>(l!==void 0&&(r[i]=l),r),v(b({},Fe),{inputPromptText:o("ai.config.inputPromptText"),welcomeText:o("ai.config.welcomeText"),suggestionsWelcomeText:o("ai.config.suggestionsWelcomeText")}));return t.jsx(Be.Provider,{value:s,children:e})},le="chatHistory",dt=e=>{const n=T(),{hideHistory:o}=R();return a.useQuery({queryKey:[le,e,n],queryFn:()=>N(exports,null,function*(){if(!n||!e)return;if(o)return[];const s=yield n.ai.chat.getById(e);return s==null?void 0:s.chatHistory}),enabled:!!n&&!!e})},He=e=>{const n=T(),o=a.useQueryClient();return ie({mutationFn:()=>N(exports,null,function*(){if(!(!n||!e))return n.ai.chat.clearHistory(e)}),onError:s=>{console.error("Error when clearing history:",s)},onSettled:()=>{e&&o.setQueriesData([le,e],[])}})},ce=e=>{const{data:n,isLoading:o,isError:s}=dt(e),{mutate:r}=He(e);return d.useEffect(()=>{s&&r()},[s,r]),{history:n,isLoading:o,isError:s}},ut=()=>{const e=T(),{data:n,isLoading:o,fetchStatus:s}=a.useQuery({queryKey:["getDataTopics",e],queryFn:()=>N(exports,null,function*(){if(e)return e.getChatContexts()}),enabled:!!e});return{data:n,isLoading:o,fetchStatus:s}},ht=()=>{const e=T(),{data:n,isLoading:o}=a.useQuery({queryKey:["getAllChats",e],queryFn:()=>e==null?void 0:e.ai.chat.getAll(),enabled:!!e});return{data:n!=null?n:[],isLoading:o}},pt=(e,n,o)=>{const s=a.useQueryClient(),r=T(),i=ie({mutationFn:()=>N(exports,null,function*(){if(!(!r||!e))return r.ai.chat.create(e,o)}),onSuccess:()=>s.invalidateQueries(["getAllChats"])});return d.useEffect(()=>{n&&i.isIdle&&i.mutate()},[n,i]),i},gt=(e,n)=>{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(`${n}${JSON.stringify(e)}`)}},Ct=(e,n)=>{const o=a.useQueryClient(),s=d.useCallback(c=>{e&&o.setQueriesData([le,e],h=>h&&[...h,c])},[o,e]),{t:r}=t.useTranslation(),i=T(),{mutate:l,isLoading:u}=ie({mutationFn:c=>N(exports,null,function*(){if(!(!i||!e))return i.ai.chat.post(e,{text:c,options:{enableFollowup:n}})}),onMutate:c=>{s({content:c,role:"user"})},onError:c=>{c instanceof Error&&(console.error("Error when sending message:",c.message),s({content:r(`ai.errors.${c.interpolationOptions.errorCode}`,{defaultValue:r("ai.errors.unexpectedChatResponse")}),role:"assistant"}))},onSuccess:c=>{if(!c)return;const h=r("ai.errors.unknownResponse");s(gt(c,h))}});return{mutate:l,isLoading:u}},de=(e,n,o=!1)=>{var g;const{data:s,isLoading:r}=ht(),i=tt(),l=i.getChatId(e,n)||((g=s.find(p=>{var C;return p.contextTitle===e&&((C=p.contextDetails)==null?void 0:C.dashboardId)===(n==null?void 0:n.dashboardId)}))==null?void 0:g.chatId),{isError:u,data:c,isSuccess:h}=pt(e,o&&!r&&!l,n);return d.useEffect(()=>{h&&c&&!l&&i.saveChatId(c.chatId,e,n)},[c,h,e,n,l,i]),{chatId:l,isLoading:r,isError:u}},De=e=>d.useMemo(()=>{if(e!=null&&e.length){const n=e[e.length-1];if(ue(n))return JSON.parse(n.content)}return null},[e]),ue=e=>!!e&&"type"in e&&e.type==="nlq",xt=e=>!!e&&"type"in e&&e.type==="text",qe=(e,n)=>{const{t:o}=t.useTranslation(),{enableFollowupQuestions:s}=R(),{chatId:r,isError:i}=de(e,n,!0),[l,u]=d.useState(null),{history:c,isLoading:h,isError:g}=ce(r);d.useEffect(()=>{i?u(new t.TranslatableError("ai.errors.chatUnavailable")):g&&u(new t.TranslatableError("ai.errors.fetchHistory"))},[i,g,o]);const{mutate:p,isLoading:C}=Ct(r,s),x=De(c);return{chatId:r,history:c!=null?c:[],lastNlqResponse:x,sendMessage:p,isAwaitingResponse:C,isLoading:h,lastError:l}},ft=({contextTitle:e,contextDetails:n})=>{const{chatId:o}=de(e,n),{history:s}=ce(o);return De(s)},mt=({contextTitle:e,contextDetails:n})=>{const{chatId:o}=de(e,n),{history:s}=ce(o);return d.useMemo(()=>{if(s!=null&&s.length){const r=s.slice().reverse().find(ue);if(r)return JSON.parse(r.content)}return null},[s])},bt=500,yt=500,vt=500,wt=900,jt=t.newStyled("div",{target:"e1ldv6710",label:"ChatFrame"})("box-sizing:border-box;position:relative;display:flex;flex-direction:column;border:1px solid #c6c9ce;border-radius:",({theme:e})=>e.aiChat.borderRadius,";background-color:",({theme:e})=>e.aiChat.backgroundColor,";overflow:hidden;min-width:",bt,"px;min-height:",yt,"px;width:",({width:e})=>e?je(e):`${vt}px`,";height:",({height:e})=>e?je(e):`${wt}px`,";",({theme:e})=>t.css`
|
|
1
|
+
"use strict";var Ve=Object.defineProperty,_e=Object.defineProperties;var Ue=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var be=(e,n,o)=>n in e?Ve(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o,b=(e,n)=>{for(var o in n||(n={}))ye.call(n,o)&&be(e,o,n[o]);if(U)for(var o of U(n))ve.call(n,o)&&be(e,o,n[o]);return e},v=(e,n)=>_e(e,Ue(n));var we=(e,n)=>{var o={};for(var s in e)ye.call(e,s)&&n.indexOf(s)<0&&(o[s]=e[s]);if(e!=null&&U)for(var s of U(e))n.indexOf(s)<0&&ve.call(e,s)&&(o[s]=e[s]);return o};var N=(e,n,o)=>new Promise((s,r)=>{var i=c=>{try{u(o.next(c))}catch(h){r(h)}},l=c=>{try{u(o.throw(c))}catch(h){r(h)}},u=c=>c.done?s(c.value):Promise.resolve(c.value).then(i,l);u((o=o.apply(e,n)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./use-common-filters-Dx4AeUoy.cjs"),t=require("./derive-chart-family-C3FH49ux.cjs"),d=require("react"),z=require("./widget-composer-D5_iKTui.cjs"),$=require("react/jsx-runtime");function Ke(e){const n=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(n,o,s.get?s:{enumerable:!0,get:()=>e[o]})}}return n.default=e,Object.freeze(n)}const I=Ke(d);class Je extends a.Subscribable{constructor(n,o){super(),this.client=n,this.setOptions(o),this.bindMethods(),this.updateResult()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(n){var o;const s=this.options;this.options=this.client.defaultMutationOptions(n),a.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 n;(n=this.currentMutation)==null||n.removeObserver(this)}}onMutationUpdate(n){this.updateResult();const o={listeners:!0};n.type==="success"?o.onSuccess=!0:n.type==="error"&&(o.onError=!0),this.notify(o)}getCurrentResult(){return this.currentResult}reset(){this.currentMutation=void 0,this.updateResult(),this.notify({listeners:!0})}mutate(n,o){return this.mutateOptions=o,this.currentMutation&&this.currentMutation.removeObserver(this),this.currentMutation=this.client.getMutationCache().build(this.client,v(b({},this.options),{variables:typeof n!="undefined"?n:this.options.variables})),this.currentMutation.addObserver(this),this.currentMutation.execute()}updateResult(){const n=this.currentMutation?this.currentMutation.state:a.getDefaultState(),o=v(b({},n),{isLoading:n.status==="loading",isSuccess:n.status==="success",isError:n.status==="error",isIdle:n.status==="idle",mutate:this.mutate,reset:this.reset});this.currentResult=o}notify(n){a.notifyManager.batch(()=>{if(this.mutateOptions&&this.hasListeners()){if(n.onSuccess){var o,s,r,i;(o=(s=this.mutateOptions).onSuccess)==null||o.call(s,this.currentResult.data,this.currentResult.variables,this.currentResult.context),(r=(i=this.mutateOptions).onSettled)==null||r.call(i,this.currentResult.data,null,this.currentResult.variables,this.currentResult.context)}else if(n.onError){var l,u,c,h;(l=(u=this.mutateOptions).onError)==null||l.call(u,this.currentResult.error,this.currentResult.variables,this.currentResult.context),(c=(h=this.mutateOptions).onSettled)==null||c.call(h,void 0,this.currentResult.error,this.currentResult.variables,this.currentResult.context)}}n.listeners&&this.listeners.forEach(({listener:g})=>{g(this.currentResult)})})}}function ie(e,n,o){const s=a.parseMutationArgs(e,n),r=a.useQueryClient({context:s.context}),[i]=I.useState(()=>new Je(r,s));I.useEffect(()=>{i.setOptions(s)},[i,s]);const l=a.useSyncExternalStore(I.useCallback(c=>i.subscribe(a.notifyManager.batchCalls(c)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),u=I.useCallback((c,h)=>{i.mutate(c,h).catch(Ye)},[i]);if(l.error&&a.shouldThrowError(i.options.useErrorBoundary,[l.error]))throw l.error;return v(b({},l),{mutate:u,mutateAsync:l.mutate})}function Ye(){}class Te{constructor(n,o=!1){this.volatile=o,this.getChatContexts=()=>N(this,null,function*(){return(yield this.httpClient.get("api/datasources//"))||[]}),this.getNlgInsights=s=>this.httpClient.post("api/v2/ai/nlg/queryResult",s),this.getQueryRecommendations=(s,r)=>this.httpClient.get(`api/v2/ai/recommendations/query/${s}/${r.numOfRecommendations}`),this.getNlqResult=(s,r)=>this.httpClient.post(`api/v2/ai/nlq/query/${s}`,r),this.setLlmConfig=s=>this.httpClient.post("api/v2/settings/ai/llmProvider",s).catch(r=>{console.error("Unable to set llm config",r)}),this.getAllChats=()=>N(this,null,function*(){return this.volatile?[]:this.httpClient.get("api/v2/ai/chats")}),this.getChatById=s=>this.httpClient.get(`api/v2/ai/chats/${s}`),this.createChat=(s,r)=>this.httpClient.post("api/v2/ai/chats",{sourceId:s,volatile:this.volatile,contextDetails:r}),this.postChat=(s,r)=>this.httpClient.post(`api/v2/ai/chats/${s}`,r),this.deleteChatHistory=s=>this.httpClient.delete(`api/v2/ai/chats/${s}/history`),this.sendFeedback=s=>this.httpClient.post("api/v2/ai/feedback",s),this.ai={getNlgInsights:this.getNlgInsights,getNlqResult:this.getNlqResult,getQueryRecommendations:this.getQueryRecommendations,setLlmConfig:this.setLlmConfig,sendFeedback:this.sendFeedback,chat:{getAll:this.getAllChats,getById:this.getChatById,create:this.createChat,post:this.postChat,clearHistory:this.deleteChatHistory}},this.httpClient=n}}const Xe=new a.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnMount:!1}}}),ae=d.createContext(void 0),T=()=>d.useContext(ae),et=({children:e,volatile:n})=>{const{app:o}=t.useSisenseContext(),s=d.useMemo(()=>o?new Te(o.httpClient,n):void 0,[o,n]);return t.jsx(ae.Provider,{value:s,children:t.jsx(a.QueryClientProvider,{client:Xe,children:e})})},Me=d.createContext({}),tt=()=>d.useContext(Me),Re=({children:e})=>{const[n,o]=d.useState({}),s=d.useCallback((l,u)=>{var c;return`${l}_${(c=u==null?void 0:u.dashboardId)!=null?c:""}`},[]),r=d.useCallback((l,u,c)=>{o(h=>v(b({},h),{[s(u,c)]:l}))},[s]),i=d.useCallback((l,u)=>n[s(l,u)],[n,s]);return t.jsx(Me.Provider,{value:{saveChatId:r,getChatId:i},children:e})};function nt({children:e,volatile:n}){return t.jsx(Re,{children:t.jsx(et,{volatile:n,children:e})})}function Le(e){var n,o;if("jaql"in e)return e;{const s=t.convertJaqlDataSource(e.dataSource),{filters:r=[],relations:i}=t.getFilterListAndRelationsJaql(e.filters),{metadata:l,filterRelations:u}=t.getJaqlQueryPayload({dataSource:e.dataSource,attributes:(n=e.dimensions)!=null?n:[],measures:(o=e.measures)!=null?o:[],filters:r,filterRelations:i,highlights:[]},!0),c={jaql:{datasource:s,metadata:l,filterRelations:u}};return e.verbosity&&(c.verbosity=e.verbosity),c}}const Z=(e,n=!0)=>{const o=d.useMemo(()=>Le(e),[e]),s=T(),{data:r,error:i,isError:l,isLoading:u,isSuccess:c,refetch:h}=a.useQuery({queryKey:["getNlgInsights",o,s],queryFn:()=>s==null?void 0:s.ai.getNlgInsights(o),select:g=>{var p;return(p=g==null?void 0:g.data)==null?void 0:p.answer},enabled:!!s&&n});return{isLoading:u,isError:l,isSuccess:c,data:r,error:i,refetch:d.useCallback(()=>{h()},[h])}},Pe=e=>{const s=e,{enabled:n}=s,o=we(s,["enabled"]);return Z(o,n)},ot=a.withTracking("useGetNlgInsights")(Pe),st=a.withTracking("useGetNlgQueryResult")(Pe),rt=["indicator","column","line","table","pie","bar"];function Ee(e){const{dataSource:n,query:o,chartTypes:s}=e;return{contextTitle:typeof n=="string"?n:n.title,request:{text:o,timezone:"UTC",chartTypes:s!=null?s:[...rt]}}}const it=e=>{const{contextTitle:n,request:o}=Ee(e),s=T(),{isLoading:r,isError:i,isSuccess:l,data:u,error:c,refetch:h}=a.useQuery({queryKey:["getNlqResult",n,o,s],queryFn:()=>s==null?void 0:s.ai.getNlqResult(n,o),enabled:!!s&&e.enabled}),g=u?z.toWidgetProps(u,{useCustomizedStyleOptions:e.enableAxisTitlesInWidgetProps||!1}):void 0;return{isLoading:r,isError:i,isSuccess:l,data:g,error:c,refetch:d.useCallback(()=>{h()},[h])}},at=a.withTracking("useGetNlqResult")(it),Ne=4,Ie=e=>{const{contextTitle:n,count:o,enableAxisTitlesInWidgetProps:s,enabled:r}=e,i=T(),l=o!=null?o:Ne,u=(r===void 0||r===!0)&&l>0,{isLoading:c,isError:h,isSuccess:g,data:p,error:C,refetch:x}=a.useQuery({queryKey:["getQueryRecommendations",n,l,i],queryFn:()=>i==null?void 0:i.ai.getQueryRecommendations(n,{numOfRecommendations:l}),enabled:!!i&&u}),y=d.useMemo(()=>p==null?void 0:p.map(f=>v(b({},f),{widgetProps:f.jaql?z.toWidgetProps(f,{useCustomizedStyleOptions:s}):void 0})),[p,s]);return{isLoading:u?c:!1,isError:h,isSuccess:g,data:y!=null?y:void 0,error:C,refetch:d.useCallback(()=>{x()},[x])}},lt=a.withTracking("useGetQueryRecommendations")(Ie),Fe=Object.freeze({enableFollowupQuestions:!1,enableHeader:!0,enableInsights:!0,numOfRecommendations:4,numOfRecentPrompts:5}),Be=d.createContext(b({},Fe)),R=()=>d.useContext(Be),ct=({children:e,value:n})=>{const{t:o}=t.useTranslation(),s=Object.entries(n).reduce((r,[i,l])=>(l!==void 0&&(r[i]=l),r),v(b({},Fe),{inputPromptText:o("ai.config.inputPromptText"),welcomeText:o("ai.config.welcomeText"),suggestionsWelcomeText:o("ai.config.suggestionsWelcomeText")}));return t.jsx(Be.Provider,{value:s,children:e})},le="chatHistory",dt=e=>{const n=T(),{hideHistory:o}=R();return a.useQuery({queryKey:[le,e,n],queryFn:()=>N(exports,null,function*(){if(!n||!e)return;if(o)return[];const s=yield n.ai.chat.getById(e);return s==null?void 0:s.chatHistory}),enabled:!!n&&!!e})},He=e=>{const n=T(),o=a.useQueryClient();return ie({mutationFn:()=>N(exports,null,function*(){if(!(!n||!e))return n.ai.chat.clearHistory(e)}),onError:s=>{console.error("Error when clearing history:",s)},onSettled:()=>{e&&o.setQueriesData([le,e],[])}})},ce=e=>{const{data:n,isLoading:o,isError:s}=dt(e),{mutate:r}=He(e);return d.useEffect(()=>{s&&r()},[s,r]),{history:n,isLoading:o,isError:s}},ut=()=>{const e=T(),{data:n,isLoading:o,fetchStatus:s}=a.useQuery({queryKey:["getDataTopics",e],queryFn:()=>N(exports,null,function*(){if(e)return e.getChatContexts()}),enabled:!!e});return{data:n,isLoading:o,fetchStatus:s}},ht=()=>{const e=T(),{data:n,isLoading:o}=a.useQuery({queryKey:["getAllChats",e],queryFn:()=>e==null?void 0:e.ai.chat.getAll(),enabled:!!e});return{data:n!=null?n:[],isLoading:o}},pt=(e,n,o)=>{const s=a.useQueryClient(),r=T(),i=ie({mutationFn:()=>N(exports,null,function*(){if(!(!r||!e))return r.ai.chat.create(e,o)}),onSuccess:()=>s.invalidateQueries(["getAllChats"])});return d.useEffect(()=>{n&&i.isIdle&&i.mutate()},[n,i]),i},gt=(e,n)=>{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(`${n}${JSON.stringify(e)}`)}},Ct=(e,n)=>{const o=a.useQueryClient(),s=d.useCallback(c=>{e&&o.setQueriesData([le,e],h=>h&&[...h,c])},[o,e]),{t:r}=t.useTranslation(),i=T(),{mutate:l,isLoading:u}=ie({mutationFn:c=>N(exports,null,function*(){if(!(!i||!e))return i.ai.chat.post(e,{text:c,options:{enableFollowup:n}})}),onMutate:c=>{s({content:c,role:"user"})},onError:c=>{c instanceof Error&&(console.error("Error when sending message:",c.message),s({content:r(`ai.errors.${c.interpolationOptions.errorCode}`,{defaultValue:r("ai.errors.unexpectedChatResponse")}),role:"assistant"}))},onSuccess:c=>{if(!c)return;const h=r("ai.errors.unknownResponse");s(gt(c,h))}});return{mutate:l,isLoading:u}},de=(e,n,o=!1)=>{var g;const{data:s,isLoading:r}=ht(),i=tt(),l=i.getChatId(e,n)||((g=s.find(p=>{var C;return p.contextTitle===e&&((C=p.contextDetails)==null?void 0:C.dashboardId)===(n==null?void 0:n.dashboardId)}))==null?void 0:g.chatId),{isError:u,data:c,isSuccess:h}=pt(e,o&&!r&&!l,n);return d.useEffect(()=>{h&&c&&!l&&i.saveChatId(c.chatId,e,n)},[c,h,e,n,l,i]),{chatId:l,isLoading:r,isError:u}},De=e=>d.useMemo(()=>{if(e!=null&&e.length){const n=e[e.length-1];if(ue(n))return JSON.parse(n.content)}return null},[e]),ue=e=>!!e&&"type"in e&&e.type==="nlq",xt=e=>!!e&&"type"in e&&e.type==="text",qe=(e,n)=>{const{t:o}=t.useTranslation(),{enableFollowupQuestions:s}=R(),{chatId:r,isError:i}=de(e,n,!0),[l,u]=d.useState(null),{history:c,isLoading:h,isError:g}=ce(r);d.useEffect(()=>{i?u(new t.TranslatableError("ai.errors.chatUnavailable")):g&&u(new t.TranslatableError("ai.errors.fetchHistory"))},[i,g,o]);const{mutate:p,isLoading:C}=Ct(r,s),x=De(c);return{chatId:r,history:c!=null?c:[],lastNlqResponse:x,sendMessage:p,isAwaitingResponse:C,isLoading:h,lastError:l}},ft=({contextTitle:e,contextDetails:n})=>{const{chatId:o}=de(e,n),{history:s}=ce(o);return De(s)},mt=({contextTitle:e,contextDetails:n})=>{const{chatId:o}=de(e,n),{history:s}=ce(o);return d.useMemo(()=>{if(s!=null&&s.length){const r=s.slice().reverse().find(ue);if(r)return JSON.parse(r.content)}return null},[s])},bt=500,yt=500,vt=500,wt=900,jt=t.newStyled("div",{target:"e1ldv6710",label:"ChatFrame"})("box-sizing:border-box;position:relative;display:flex;flex-direction:column;border:1px solid #c6c9ce;border-radius:",({theme:e})=>e.aiChat.borderRadius,";background-color:",({theme:e})=>e.aiChat.backgroundColor,";overflow:hidden;min-width:",bt,"px;min-height:",yt,"px;width:",({width:e})=>e?je(e):`${vt}px`,";height:",({height:e})=>e?je(e):`${wt}px`,";",({theme:e})=>t.css`
|
|
2
2
|
font-size: ${e.aiChat.primaryFontSize[0]};
|
|
3
3
|
line-height: ${e.aiChat.primaryFontSize[1]};
|
|
4
4
|
`," border:",({theme:e})=>e.aiChat.border===!1?"none":e.aiChat.border,";");function je(e){return typeof e=="number"?`${e}px`:e}function kt({spin:e}){return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",className:`${e?"csdk-animate-spin":""}`,children:[t.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z",fill:"#262E3D",fillOpacity:"0.3"}),t.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M20 12C20 16.4183 16.4183 20 12 20C11.2844 20 10.5908 19.906 9.93078 19.7298C9.96227 19.5889 9.97888 19.4423 9.97888 19.2918C9.97888 18.1873 9.08345 17.2918 7.97888 17.2918C6.87431 17.2918 5.97888 18.1873 5.97888 19.2918C5.97888 20.3964 6.87431 21.2918 7.97888 21.2918C8.56576 21.2918 9.0936 21.0391 9.45946 20.6364C10.2652 20.8731 11.1178 21 12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3V4C16.4183 4 20 7.58172 20 12Z",fill:"#22C3C3"})]})}function Y(){return t.jsx("div",{className:"csdk-m-auto","aria-label":"loading spinner",children:t.jsx(kt,{spin:!0})})}function St({theme:e}){return t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{d:"M4 14L0 10L24 0L14 24L10 20L8.47667 16.9533L19 6.4L20 4.00001L17.6099 5L7.04354 15.5218L4 14Z",fill:e.aiChat.icons.color})})}function Tt({theme:e}){const n=e.aiChat.icons.color;return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"25",height:"25",viewBox:"0 0 25 25",fill:"none",children:[t.jsx("path",{d:"M21.4095 11.1195L12.5644 6.0459C12.3247 5.90841 12.0189 5.99143 11.8816 6.23128L10.764 8.18434C10.6275 8.42284 10.709 8.72678 10.9466 8.86491L19.7108 13.9614C19.9464 14.0984 20.2483 14.0215 20.3897 13.7884L21.5883 11.8125C21.734 11.5723 21.6532 11.2592 21.4095 11.1195Z",fill:n}),t.jsx("path",{d:"M18.7329 8.60735L16.1048 7.07819L19.6668 0.928042C19.8041 0.6909 20.1068 0.608502 20.3454 0.743288L22.156 1.7661C22.3992 1.90347 22.4827 2.21344 22.3414 2.45438L18.7329 8.60735Z",fill:n}),t.jsx("path",{d:"M19.8544 14.9048L10.3563 9.43067C10.2184 9.35116 10.0413 9.39515 9.95275 9.52746C7.03423 13.8862 4.07448 15.2337 3.18167 16.0938C3.09276 16.1794 3.08414 16.3141 3.1538 16.416C3.74961 17.2879 5.10497 18.4425 6.05628 19.2048C6.17328 19.2985 6.34145 19.2903 6.44961 19.1865L9.97994 15.7973L7.69329 20.1066C7.61954 20.2456 7.66674 20.4186 7.80041 20.5017C11.6152 22.8708 14.2978 24.0437 16.9604 24.4472C17.1542 24.4766 17.3191 24.3106 17.3033 24.1152C17.007 20.469 19.0807 16.6112 19.8544 14.9048Z",fill:n})]})}const Mt=t.newStyled("div",{target:"e1q6h1ze0",label:"Section"})("display:flex;flex-direction:column;row-gap:4px;"),Rt=t.newStyled("div",{target:"e1q6h1ze1",label:"SectionHeader"})("font-size:11px;line-height:18px;font-weight:300;color:",({theme:e})=>e.aiChat.dropup.headers.textColor,";cursor:pointer;padding:4px 12px;&:hover{background-color:",({theme:e})=>e.aiChat.dropup.headers.hover.backgroundColor,";}"),Lt=t.newStyled("div",{target:"e1q6h1ze2",label:"DropupItem"})("font-size:",({theme:e})=>e.aiChat.primaryFontSize[0],";line-height:",({theme:e})=>e.aiChat.primaryFontSize[1],";color:",({theme:e})=>e.aiChat.dropup.items.textColor,";cursor:pointer;padding:4px 12px;&:hover{background-color:",({theme:e})=>e.aiChat.dropup.items.hover.backgroundColor,";}");function Pt({title:e,items:n,onSelect:o,alwaysExpanded:s=!1}){const[r,i]=d.useState(!1),{themeSettings:l}=t.useThemeContext();return t.jsxs(Mt,{children:[t.jsx(Rt,{onClick:()=>i(u=>!u),theme:l,children:e.toUpperCase()}),(r||s)&&n.map((u,c)=>t.jsx(Lt,{onClick:()=>o(u),theme:l,children:u},c))]})}const Et=t.newStyled("div",{target:"e10x5x4a0",label:"PopupContent"})("font-family:",({theme:e})=>e.typography.fontFamily,";font-size:",({theme:e})=>e.aiChat.primaryFontSize[0],";line-height:",({theme:e})=>e.aiChat.primaryFontSize[1],";background-color:",({theme:e})=>e.aiChat.dropup.backgroundColor,";border-radius:",({theme:e})=>e.aiChat.dropup.borderRadius,";box-shadow:",({theme:e})=>e.aiChat.dropup.boxShadow,";padding-top:8px;padding-bottom:8px;display:flex;flex-direction:column;row-gap:4px;"),Nt=t.newStyled("div",{target:"e10x5x4a1",label:"ErrorMessage"})("font-size:",({theme:e})=>e.aiChat.primaryFontSize[0],";line-height:",({theme:e})=>e.aiChat.primaryFontSize[1],";color:",({theme:e})=>e.aiChat.dropup.items.textColor,";padding:4px 12px;"),se=e=>e.startsWith("/");function It({recentPrompts:e,suggestions:n,isLoading:o,onSelection:s,anchorEl:r,text:i,recommendationsError:l}){const c=[{title:"/recent searches",items:e,onSelect:s},{title:"/ai recommendations",items:n,onSelect:s}].filter(C=>C.title.slice(0,i.length)===i),{themeSettings:h}=t.useThemeContext(),{t:g}=t.useTranslation(),p=c.length===1;return t.jsx(a.Popper,{open:se(i)&&c.length>0,anchorEl:r,placement:"top-start",modifiers:[{name:"offset",options:{offset:[0,4]}}],sx:{zIndex:3},children:t.jsxs(Et,{style:{width:r==null?void 0:r.offsetWidth},theme:h,children:[o&&t.jsx(Y,{}),!o&&!l&&c.map(C=>t.jsx(Pt,v(b({},C),{alwaysExpanded:p}),C.title)),l&&t.jsx(Nt,{theme:h,children:g("ai.errors.recommendationsNotAvailable")})]})})}function G({title:e,placement:n="top",children:o}){const{themeSettings:s}=t.useThemeContext();return t.jsx(a.Tooltip,{title:e,placement:n,disableInteractive:!0,componentsProps:{tooltip:{sx:{bgcolor:s.aiChat.tooltips.backgroundColor,color:s.aiChat.tooltips.textColor,paddingX:"16px",paddingY:"12px",fontSize:"13px",fontFamily:s.typography.fontFamily,fontWeight:400,borderRadius:"4px",boxShadow:s.aiChat.tooltips.boxShadow}},arrow:{sx:{color:s.aiChat.tooltips.backgroundColor}}},arrow:!0,children:o})}const Ft=500,Bt=t.newStyled("div",{target:"e6iwkw10",label:"ChatInputContainer"})("display:flex;flex-direction:row;align-items:flex-end;justify-content:space-between;background-color:",({theme:e})=>e.aiChat.backgroundColor,";"),Ht=t.newStyled("button",{target:"e6iwkw11",label:"ClearHistoryButton"})("height:34px;background-color:inherit;cursor:pointer;border:none;"),Dt=t.newStyled("textarea",{target:"e6iwkw12",label:"TextInput"})("font-size:inherit;line-height:inherit;resize:none;overflow-y:auto;box-sizing:border-box;max-height:88px;width:100%;padding-top:7px;padding-bottom:7px;padding-left:16px;padding-right:16px;margin-left:10px;margin-right:10px;border-width:1px;border-color:rgb(38 46 61 / 0.15);border-radius:0.5rem;&:focus{outline:1px solid ",({theme:e})=>e.aiChat.input.focus.outlineColor,";}font-family:inherit;color:",({theme:e})=>e.aiChat.primaryTextColor,";background-color:",({theme:e})=>e.aiChat.input.backgroundColor,";"),qt=t.newStyled("button",{target:"e6iwkw13",label:"SendMessageButton"})("height:34px;background-color:inherit;border-style:none;color:",({theme:e})=>e.aiChat.primaryTextColor,";",({disabled:e})=>e?t.css`
|
package/dist/ai.js
CHANGED
|
@@ -35,7 +35,7 @@ var W = (e, t, o) => new Promise((r, i) => {
|
|
|
35
35
|
}, c = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(s, a);
|
|
36
36
|
c((o = o.apply(e, t)).next());
|
|
37
37
|
});
|
|
38
|
-
import { bv as wt, bw as kt, bx as Ke, by as St, bz as oe, bA as Mt, bB as Tt, bC as Lt, ba as Je, bb as Ye, aP as K, I as pe, aC as Xe, ai as Rt, bD as It, al as Et, ak as Nt, z as ge, bE as Bt, bF as Ft, aq as _, bG as et, B as Ht, aW as Dt, _ as Pt, bH as qt, x as ve, P as f, C as Ot, bI as At, aD as tt, az as Wt, bJ as zt, ag as te, M as $t, bK as Zt, bL as jt, O as Le, bM as Gt, b6 as Vt, bN as Qt } from "./use-common-filters-
|
|
38
|
+
import { bv as wt, bw as kt, bx as Ke, by as St, bz as oe, bA as Mt, bB as Tt, bC as Lt, ba as Je, bb as Ye, aP as K, I as pe, aC as Xe, ai as Rt, bD as It, al as Et, ak as Nt, z as ge, bE as Bt, bF as Ft, aq as _, bG as et, B as Ht, aW as Dt, _ as Pt, bH as qt, x as ve, P as f, C as Ot, bI as At, aD as tt, az as Wt, bJ as zt, ag as te, M as $t, bK as Zt, bL as jt, O as Le, bM as Gt, b6 as Vt, bN as Qt } from "./use-common-filters-CRL16HJ4.js";
|
|
39
39
|
import { R as _t, a9 as n, a1 as Ut, p as Kt, c0 as Jt, V as w, T as ke, aQ as u, a_ as I, aa as p, W as b, ab as B, _ as G, a7 as ot, aw as Se, aA as Yt, c1 as Xt, c2 as e1, a5 as t1, a6 as o1, r as n1 } from "./derive-chart-family-5CbFzbpu.js";
|
|
40
40
|
import * as z from "react";
|
|
41
41
|
import { createContext as Re, useContext as Ie, useMemo as F, useState as L, useCallback as S, useEffect as ne, useRef as U, useLayoutEffect as ue, memo as r1, forwardRef as i1 } from "react";
|