@chatsystem/client 1.1.72 → 1.1.74
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -155,7 +155,7 @@ Valid keys: `+JSON.stringify(Object.keys(p),null," "));var z=Ne(ee,ae,Q,ne,W+".
|
|
|
155
155
|
md:h-[clamp(420px,70dvh,640px)]
|
|
156
156
|
md:rounded-xl
|
|
157
157
|
bg-white shadow-xl flex flex-col overflow-hidden
|
|
158
|
-
`,children:[_.jsxs("div",{className:"relative bg-violet-700 py-2 text-white text-center flex justify-center items-center",children:[_.jsx("span",{className:"font-medium",children:"Assistant"}),_.jsx(zx,{setIsWidgetOpen:e.setIsWidgetOpen})]}),_.jsx(hc,{appToken:e.appToken})]})),Yx=({isWidgetOpen:e,appToken:t,setIsWidgetOpen:n})=>{const r=k.useRef(null);return _.jsx("div",{children:_.jsx(Oa,{nodeRef:r,in:e,timeout:200,classNames:"menuTransition",unmountOnExit:!0,children:_.jsx($x,{ref:r,props:{appToken:t,setIsWidgetOpen:n}})})})},Tc=()=>({hasFetchedSettings:!1,hasDisplayedCSS:!1}),Gx=()=>{const[e,t]=k.useState(Tc());return{appInternalContext:e,setAppInternalContext:t,setHasFetchedSettings:()=>{t(i=>({...i,hasFetchedSettings:!0}))},setHasDisplayedCss:()=>{t(i=>({...i,hasDisplayedCSS:!0}))}}},xc=k.createContext({appInternalContext:Tc(),setAppInternalContext:()=>{},setHasFetchedSettings:()=>{}}),Vx=({displayMode:e,appToken:t})=>{const[n,r]=k.useState(!1),{appInternalContext:i}=k.useContext(xc);return _.jsxs(_.Fragment,{children:[e===fn.LAUNCHER&&i.hasFetchedSettings&&_.jsxs(_.Fragment,{children:[_.jsx(Uc,{isWidgetOpen:n,setIsWidgetOpen:r}),_.jsx(Yx,{isWidgetOpen:n,appToken:t,setIsWidgetOpen:r})]}),e===fn.CHATBOX&&i.hasFetchedSettings&&_.jsx("div",{className:"chatBox",children:_.jsx(hc,{appToken:t})})]})},qx=e=>Object.values(fn).includes(e),Wx=e=>qx(e)?e:(console.warn(`Display mode not valid. Using ${fn.LAUNCHER} as default.`),fn.LAUNCHER),Xx=(e,t)=>{let n,r;return typeof window<"u"&&(r=window.localStorage.getItem(ax)),r&&e?.[r]!==void 0?n=e[r]:(n=e[t],n.isDefault=!0),n},Qx=(e,t)=>{const[n,r]=k.useState(e[t]),i=a=>{Object.keys(e).includes(a?.locale)?r(a):r(e[nt.ENGLISH])};return k.useEffect(()=>{let a=Xx(e,t);a.locale!==t&&r(e[a.locale])},[]),{appCurrentLang:n,handleSetContextCurrentLang:i}},Kx=e=>Object.values(nt).includes(e),Zx=e=>Kx(e)?e:(console.log(`Language ${e} not handled for now. Using ${nt.ENGLISH}.`),nt.ENGLISH);function Jx(e,t=Date.now()){return t-e}function ey(e,t=Date.now()){return Jx(new Date(e).getTime(),t)<=Tx}function ty({settings:e,setCurrentConversation:t,setArchivedConversation:n}){const r=_x({key:fc});if(!r){t({discussionId:null,items:[{userType:"assistant",content:e.agent.text.initialText}]});return}ey(r.updatedAt)?t({discussionId:r.discussionId,items:r.items,updatedAt:r.updatedAt}):(t({discussionId:null,items:[{userType:"assistant",content:e.agent.text.initialText}]}),n({discussionId:r.discussionId,items:r.items,updatedAt:r.updatedAt}))}const ny=({agentId:e,appToken:t,onFetched:n})=>{const[r,i]=k.useState({}),a={companySettings:r,setCompanySettings:i},[s,u]=k.useState({discussionId:null,items:[],updatedAt:null}),[o,c]=k.useState({discussionId:null,items:[],updatedAt:null}),f={currentConversation:s,setCurrentConversation:u,archivedConversation:o,setArchivedConversation:c};return k.useEffect(()=>{const d=Fn.getApiUrl(),h=Fn.getFetchConfig({httpVerb:"GET",contentType:"application/json"});let m=`${d}/company/settings/${t}`;
|
|
158
|
+
`,children:[_.jsxs("div",{className:"relative bg-violet-700 py-2 text-white text-center flex justify-center items-center chatsystem-header",children:[_.jsx("span",{className:"font-medium",children:"Assistant"}),_.jsx(zx,{setIsWidgetOpen:e.setIsWidgetOpen})]}),_.jsx(hc,{appToken:e.appToken})]})),Yx=({isWidgetOpen:e,appToken:t,setIsWidgetOpen:n})=>{const r=k.useRef(null);return _.jsx("div",{children:_.jsx(Oa,{nodeRef:r,in:e,timeout:200,classNames:"menuTransition",unmountOnExit:!0,children:_.jsx($x,{ref:r,props:{appToken:t,setIsWidgetOpen:n}})})})},Tc=()=>({hasFetchedSettings:!1,hasDisplayedCSS:!1}),Gx=()=>{const[e,t]=k.useState(Tc());return{appInternalContext:e,setAppInternalContext:t,setHasFetchedSettings:()=>{t(i=>({...i,hasFetchedSettings:!0}))},setHasDisplayedCss:()=>{t(i=>({...i,hasDisplayedCSS:!0}))}}},xc=k.createContext({appInternalContext:Tc(),setAppInternalContext:()=>{},setHasFetchedSettings:()=>{}}),Vx=({displayMode:e,appToken:t})=>{const[n,r]=k.useState(!1),{appInternalContext:i}=k.useContext(xc);return _.jsxs(_.Fragment,{children:[e===fn.LAUNCHER&&i.hasFetchedSettings&&_.jsxs(_.Fragment,{children:[_.jsx(Uc,{isWidgetOpen:n,setIsWidgetOpen:r}),_.jsx(Yx,{isWidgetOpen:n,appToken:t,setIsWidgetOpen:r})]}),e===fn.CHATBOX&&i.hasFetchedSettings&&_.jsx("div",{className:"chatBox",children:_.jsx(hc,{appToken:t})})]})},qx=e=>Object.values(fn).includes(e),Wx=e=>qx(e)?e:(console.warn(`Display mode not valid. Using ${fn.LAUNCHER} as default.`),fn.LAUNCHER),Xx=(e,t)=>{let n,r;return typeof window<"u"&&(r=window.localStorage.getItem(ax)),r&&e?.[r]!==void 0?n=e[r]:(n=e[t],n.isDefault=!0),n},Qx=(e,t)=>{const[n,r]=k.useState(e[t]),i=a=>{Object.keys(e).includes(a?.locale)?r(a):r(e[nt.ENGLISH])};return k.useEffect(()=>{let a=Xx(e,t);a.locale!==t&&r(e[a.locale])},[]),{appCurrentLang:n,handleSetContextCurrentLang:i}},Kx=e=>Object.values(nt).includes(e),Zx=e=>Kx(e)?e:(console.log(`Language ${e} not handled for now. Using ${nt.ENGLISH}.`),nt.ENGLISH);function Jx(e,t=Date.now()){return t-e}function ey(e,t=Date.now()){return Jx(new Date(e).getTime(),t)<=Tx}function ty({settings:e,setCurrentConversation:t,setArchivedConversation:n}){const r=_x({key:fc});if(!r){t({discussionId:null,items:[{userType:"assistant",content:e.agent.text.initialText}]});return}ey(r.updatedAt)?t({discussionId:r.discussionId,items:r.items,updatedAt:r.updatedAt}):(t({discussionId:null,items:[{userType:"assistant",content:e.agent.text.initialText}]}),n({discussionId:r.discussionId,items:r.items,updatedAt:r.updatedAt}))}const ny=({agentId:e,appToken:t,onFetched:n})=>{const[r,i]=k.useState({}),a={companySettings:r,setCompanySettings:i},[s,u]=k.useState({discussionId:null,items:[],updatedAt:null}),[o,c]=k.useState({discussionId:null,items:[],updatedAt:null}),f={currentConversation:s,setCurrentConversation:u,archivedConversation:o,setArchivedConversation:c};return k.useEffect(()=>{const d=Fn.getApiUrl(),h=Fn.getFetchConfig({httpVerb:"GET",contentType:"application/json"});let m=`${d}/company/settings/${t}`;m+=`/${e}`,fetch(m,{...h,credentials:"omit"}).then(async b=>{const A=await b.json();i(A),ty({settings:A,setCurrentConversation:u,setArchivedConversation:c}),n?.()}).catch(b=>console.log("error in settings fetch",b))},[t,e]),{contextCompanySettings:a,contextInitialConversationState:f}};function ry(e,t={},n,r){const{id:i,nonce:a,target:s,disableConstructable:u}=t,o=s,c=k.useRef(null),f=k.useRef(null);k.useEffect(()=>{if(!s)return;if(!e){n&&(console.log("No custom css found."),r?.());return}if(!u&&"adoptedStyleSheets"in o&&typeof CSSStyleSheet<"u"&&"replaceSync"in CSSStyleSheet.prototype)return c.current||(c.current=new CSSStyleSheet,o.adoptedStyleSheets=[...o.adoptedStyleSheets,c.current]),c.current.replaceSync(e),console.log("Loading custom css via stylesheet."),r?.(),()=>{const h=o.adoptedStyleSheets||[],m=h.indexOf(c.current);if(m>=0){const b=h.slice();b.splice(m,1),o.adoptedStyleSheets=b}c.current=null};if(!f.current){const h=document.createElement("style");h.type="text/css",i&&(h.id=i),a&&(h.nonce=a),(o instanceof Document&&o.head||o).appendChild(h),f.current=h}return f.current.textContent=e,console.log("Loading custom css via style tag."),r?.(),()=>{f.current?.parentNode?.removeChild(f.current),f.current=null}},[e,i,a,s,u])}function iy(e){const{manifest:t,origins:n}=ay(e);n.forEach(Nc),Oc(t),Ic(t)}function ay(e){const t=sy(e),n=new Set,r=new Set,i=new Set,a=new Set;for(const{url:o,mode:c}of t)switch(uy(c,o)){case"svg":r.add(o);break;case"lottie":i.add(o);break;case"spritesheet":a.add(o);break;case"image":n.add(o);break}const s={images:Array.from(n),svgs:Array.from(r),lotties:Array.from(i),sprites:Array.from(a)},u=oy(s);return{manifest:s,origins:u}}function sy(e){if(!e?.agent?.display)return[];const t=e.agent.display,n=[t.launcher,t.assistant,t.search].filter(Boolean),r=[];for(const i of n)i?.assetUrl&&r.push({url:i.assetUrl,mode:i.mode});return r}function uy(e,t){if(e)switch(e){case"svg":return"svg";case"lottie":return"lottie";case"spritesheet":return"spritesheet";case"image":return"image";case"video":return"video"}try{const r=new URL(t,document.baseURI).pathname.toLowerCase();if(r.endsWith(".svg"))return"svg";if(r.endsWith(".lottie")||r.endsWith(".zip")||r.endsWith(".json"))return r.endsWith(".json"),"lottie";if(/\.(png|webp|jpg|jpeg|gif|avi,ef)$/.test(r))return"image";if(/\.(mp4|webm|mov|m4v|ogg)$/.test(r))return"video"}catch(n){console.log("error in normalizeKind:",n)}return"unknown"}function oy(e){const t=new Set,n=r=>{if(r)try{const i=new URL(r,document.baseURI);t.add(`${i.protocol}//${i.host}`)}catch(i){console.log("error in uniqueOriginsFromManifest",i)}};return(e.images??[]).forEach(n),(e.svgs??[]).forEach(n),(e.lotties??[]).forEach(n),(e.sprites??[]).forEach(n),Array.from(t)}const ly=({children:e,appToken:t,agentId:n,appRoot:r})=>{var i=navigator.language;console.log("Brower language",i);const a=Zx(i),{appCurrentLang:s,handleSetContextCurrentLang:u}=Qx(Ur,a),o={appCurrentLang:s,setAppCurrentLang:u},c=Gx(),{contextCompanySettings:f,contextInitialConversationState:d}=ny({agentId:n,appToken:t,onFetched:c.setHasFetchedSettings});return iy(f.companySettings),ry(f.companySettings?.agent?.display?.CSSRules,{id:`${n}`,target:r},c.appInternalContext.hasFetchedSettings,c.setHasDisplayedCss),_.jsx(_.Fragment,{children:_.jsx(fd,{locale:s?.locale,messages:s?.translatedText,children:_.jsx(lc.Provider,{value:o,children:_.jsx(xc.Provider,{value:c,children:_.jsx(dn.Provider,{value:f,children:_.jsx(dc.Provider,{value:d,children:c.appInternalContext.hasDisplayedCSS&&e})})})})})})};var fn=(e=>(e.LAUNCHER="launcher",e.CHATBOX="chatbox",e))(fn||{});function cy({appToken:e,displayMode:t="launcher",agentId:n,appRoot:r}){e||console.warn("appToken not defined in ai-client. Please see the documentation at URL_ERROR_IN_DOC");const i=Wx(t);return console.log(`App boot in ${i} mode.`),_.jsx("div",{className:"chatSystemWidget app-root",id:"chatSystemWidget",children:_.jsx(ly,{appToken:e,agentId:n,appRoot:r,children:_.jsx(Vx,{displayMode:i,appToken:e})})})}const fy=`*, ::before, ::after {
|
|
159
159
|
--tw-border-spacing-x: 0;
|
|
160
160
|
--tw-border-spacing-y: 0;
|
|
161
161
|
--tw-translate-x: 0;
|