obi-sdk 0.11.0 → 0.11.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/modular/chunks/index-45f4d445.js +6 -0
- package/dist/modular/chunks/index-45f4d445.js.map +1 -0
- package/dist/modular/chunks/{obi-widget-585f773a.js → obi-widget-00df4624.js} +25 -8
- package/dist/modular/chunks/{obi-widget-585f773a.js.map → obi-widget-00df4624.js.map} +1 -1
- package/dist/modular/index.js +1 -1
- package/dist/modular/ui.js +10 -10
- package/dist/obi-sdk.standalone.iife.js +2 -2
- package/dist/obi-sdk.standalone.iife.js.map +1 -1
- package/dist/react.es.js +5 -5
- package/dist/react.es.js.map +1 -1
- package/dist/react.umd.js +2 -2
- package/dist/react.umd.js.map +1 -1
- package/dist/ui/components/obi-widget/obi-widget.d.ts +1 -1
- package/package.json +1 -1
- package/dist/modular/chunks/index-4be516d9.js +0 -6
- package/dist/modular/chunks/index-4be516d9.js.map +0 -1
package/dist/react.umd.js
CHANGED
|
@@ -1056,7 +1056,7 @@ Url: ${io(A)}`),!0}return!1}function $F(A,e){return e?.length?Vp(A).some(t=>Xs(t
|
|
|
1056
1056
|
opacity: 0.5;
|
|
1057
1057
|
cursor: not-allowed;
|
|
1058
1058
|
}
|
|
1059
|
-
`,Xn([ee({type:Object})],DA.prototype,"session",2),Xn([ee({type:Function})],DA.prototype,"onStart",2),Xn([ee({type:Function})],DA.prototype,"onClose",2),Xn([oe()],DA.prototype,"isLoading",2),Xn([oe()],DA.prototype,"error",2),Xn([oe()],DA.prototype,"startAttempts",2),customElements.get("obi-session-start-modal")||customElements.define("obi-session-start-modal",DA);var y_=Object.defineProperty,b_=Object.getOwnPropertyDescriptor,Qe=(A,e,t,n)=>{for(var i=n>1?void 0:n?b_(e,t):e,r=A.length-1,s;r>=0;r--)(s=A[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&y_(e,t,i),i};let Ce=class extends L.LitElement{constructor(){super(),this.apiKey="",this.isActive=!0,this.linkOnlyAccess=!1,this.urlBlacklist=[],this.position="bottom-right",this.user=null,this.state=O.READY,this.storedActiveState=void 0,this.showCourseModal=!1,this.showSessionStartModal=!1,this.selectedCourse=null,this.isHovering=!1,this.navVisible=!1,this.activeSession=null,this.volume={speaker:"ASSISTANT",volume:0,spectrum:[]},this.databaseConfig=null,this.configLoaded=!1,this.configInCode=!1,this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.boundSaveSessionData=null,this.obiClient=null,this.closeNavTimeoutRef=null,this.researchingTimeoutRef=null,this.urlCheckInterval=null,this.currentUrl="",this.connectObi=Vi(async e=>{if(this.activeSession){ie("connection_already_exists",{sessionToken:e},"ObiWidget"),console.log("Connection already exists");return}ie("session_connection_started",{sessionToken:e},"ObiWidget"),Gi({sessionId:e});try{const t=this.createSession(e);if(!t){this.handleSessionCreationFailure(()=>this.removeSessionUrlParams());return}this.setupSessionEventListeners(t,()=>this.removeSessionUrlParams()),t.on("screenCaptureRequested",Vi(async()=>{ie("screen_capture_requested",{},"ObiWidget");try{const r=(await vT(document.documentElement,{useCORS:!0,allowTaint:!0,foreignObjectRendering:!0})).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",r),ie("screen_capture_completed",{},"ObiWidget")}catch(i){Me(i,{componentName:"ObiWidget",handlerName:"screenCaptureRequested",sessionToken:e}),console.error("[obi] error capturing screen:",i),this.activeSession.emit("screenCaptureComplete","error"),ie("screen_capture_failed",{error:i instanceof Error?i.message:String(i)},"ObiWidget")}},"screenCaptureRequested","ObiWidget"));const n=await t.connect();n&&(this.sessionToken=e,this.roomToken=n.token,this.roomUrl=n.url,Gi({sessionId:e,widgetState:this.state.toString()}),this.removeSessionUrlParams(),ie("session_connection_established",{sessionToken:e,hasRoomToken:!!n.token},"ObiWidget")),this.activeSession=t}catch(t){console.error("Failed to start session:",t),Me(t,{componentName:"ObiWidget",handlerName:"connectObi",sessionToken:e}),this.handleSessionCreationFailure(()=>this.removeSessionUrlParams())}},"connectObi","ObiWidget"),this.handleCloseModals=()=>{this.state=O.READY,this.showCourseModal=!1,this.showSessionStartModal=!1},this.handleCourseSelectEvent=e=>{const t=e;this.selectedCourse=t.detail,this.showCourseModal=!1,this.showSessionStartModal=!0},this.handleUrlSessionEvent=Vi(async e=>{ie("url_session_event",{sessionToken:e},"ObiWidget");try{if(!this.obiClient){const n=new Error("ObiClient not initialized");Me(n,{componentName:"ObiWidget",handlerName:"handleUrlSessionEvent",sessionToken:e}),console.error("ObiClient not initialized");return}const t=await this.obiClient.startSession(e,this.apiKey);if(t.data){const{session:n}=t.data;if(console.log("[obi-sdk] session:",n),ie("session_started",{sessionId:n?.id,sessionToken:e},"ObiWidget"),n){const i=n;this.selectedCourse={id:e,name:i.onboarding_plan?.name||"",description:i.onboarding_plan?.description||""},this.state=O.LOADING,this.showSessionStartModal=!0,ie("matching_session_found",{sessionToken:e,hasOnboardingPlan:!!i.onboarding_plan},"ObiWidget")}else console.log("[obi-sdk] no session found with token:",e),ie("no_matching_session",{sessionToken:e},"ObiWidget")}}catch(t){console.error("Failed to fetch session details:",t),Me(t,{componentName:"ObiWidget",handlerName:"handleUrlSessionEvent",sessionToken:e})}},"handleUrlSessionEvent","ObiWidget"),this.handleSessionStart=Vi(async e=>{ie("session_start_requested",{sessionToken:e},"ObiWidget"),this.activeSession&&(ie("session_start_blocked",{sessionToken:e},"ObiWidget"),Me(new Error("Session start blocked"),{componentName:"ObiWidget",handlerName:"handleSessionStart",sessionToken:e}),this.activeSession.disconnect(),this.activeSession=null),this.showSessionStartModal=!1,this.state=O.LOADING,Gi({widgetState:this.state.toString()}),await this.connectObi(e)},"handleSessionStart","ObiWidget"),this.checkExistingSession=Vi(async()=>{ie("checking_existing_session",{},"ObiWidget");try{const e=JSON.parse(Tl.getItem(Ul.SESSION_DATA)||"{}"),{sessionToken:t,roomToken:n,roomUrl:i,sessionExpiry:r,obiState:s}=e;if(!t||!n||!i){ie("no_existing_session_data",{},"ObiWidget");return}if(console.log("[obi-sdk] using existing session"),ie("existing_session_data_found",{sessionToken:t,hasExpiry:!!r,obiState:s},"ObiWidget"),r&&new Date(r)<new Date){this.clearSessionStorage(),ie("session_expired",{sessionToken:t},"ObiWidget");return}this.state=O.LOADING,Gi({sessionId:t,widgetState:this.state.toString()});const o=this.createSession(t);if(!o){this.handleSessionCreationFailure(()=>this.clearSessionStorage());return}this.setupSessionEventListeners(o,()=>this.clearSessionStorage()),await o.reconnect(i,n,s)?(this.activeSession=o,this.sessionToken=t,this.roomToken=n,this.roomUrl=i,this.state=s,this.storedActiveState=s,ie("session_reconnected",{sessionToken:t,obiState:s},"ObiWidget")):(this.clearSessionStorage(),ie("session_reconnection_failed",{sessionToken:t},"ObiWidget"))}catch(e){console.error("Error reconnecting to session:",e),Me(e,{componentName:"ObiWidget",handlerName:"checkExistingSession"}),this.handleSessionCreationFailure(()=>this.clearSessionStorage())}},"checkExistingSession","ObiWidget");try{vm("ObiWidget").setContext(),this.obiClient=new Qh({baseUrl:Ka}),this.currentUrl=window.location.href;const t=()=>{try{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()}catch(n){Me(n,{componentName:"ObiWidget",handlerName:"handleUnload"})}};window.addEventListener("beforeunload",t),window.addEventListener("pagehide",t),ie("ObiWidget_constructor_completed",{},"ObiWidget")}catch(e){throw Me(e,{componentName:"ObiWidget",lifecycle:"constructor"}),e}}updateFromConfig(){if(window.obiWidgetConfig){this.apiKey=window.obiWidgetConfig.apiKey||this.apiKey;const e=window.obiWidgetConfig.position!==void 0,t=window.obiWidgetConfig.primaryColor!==void 0,n=window.obiWidgetConfig.linkOnlyAccess!==void 0,i=window.obiWidgetConfig.urlBlacklist!==void 0;this.configInCode=e&&t&&n&&i,this.configInCode?(this.configLoaded=!0,this.applyFinalConfiguration()):this.configLoaded||this.fetchDatabaseConfig(),window.obiWidgetConfig.showMenu===!0&&(this.state=O.LOADING,this.showCourseModal=!0,window.obiWidgetConfig.showMenu=!1)}else this.configLoaded||this.fetchDatabaseConfig()}generateColorVariables(e){try{const t=Ga(e,"#c4b5fd"),n=Ga(e,"#c76cff"),i=tw(e),r=Ga(e,"#A06DF9");this.style.setProperty("--obi-secondary",t),this.style.setProperty("--obi-course-selected",n),this.style.setProperty("--obi-course-selected-bg",i),this.style.setProperty("--obi-paused-pulse",r)}catch(t){console.warn("Failed to generate color variables:",t),this.style.setProperty("--obi-secondary","#c4b5fd"),this.style.setProperty("--obi-course-selected","#c76cff"),this.style.setProperty("--obi-course-selected-bg","#fbf3ff"),this.style.setProperty("--obi-paused-pulse","#A06DF9")}}removeSessionUrlParams(){const e=new URL(window.location.href);e.searchParams.delete(Ph),window.history.replaceState({},"",e.toString()),localStorage.removeItem("obi-url-params")}createSession(e){try{const t=new OC({sessionId:e,apiBaseUrl:Ka});return t||(console.error("Failed to create session"),null)}catch(t){return console.error("Error creating session:",t),null}}setupSessionEventListeners(e,t){e.on("stateChanged",n=>{if(n===O.RESEARCHING){this.researchingTimeoutRef&&window.clearTimeout(this.researchingTimeoutRef),this.state=n,this.researchingTimeoutRef=window.setTimeout(()=>{this.researchingTimeoutRef=null;const i=e.getCurrentState();this.state=i,i!==O.READY&&(this.storedActiveState=i)},1500),this.storedActiveState=n;return}this.researchingTimeoutRef===null&&(this.state=n,n!==O.READY&&(this.storedActiveState=n))}),e.on("volume",({speaker:n,spectrum:i,volume:r})=>{this.volume={speaker:n,spectrum:i,volume:r}}),e.on("error",n=>{console.error("Session error:",n),this.state=O.ERROR,this.activeSession=null,t&&t()})}handleSessionCreationFailure(e){this.state=O.ERROR,this.activeSession=null,e&&e()}clearSessionStorage(){Tl.removeItem(Ul.SESSION_DATA)}handleUrlChange(){this.requestUpdate(),co(this.urlBlacklist)&&this.activeSession&&this.terminateSession()}saveSessionData(){if(this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl){const e=new Date;e.setMinutes(e.getMinutes()+5);const t={sessionToken:this.sessionToken,roomToken:this.roomToken,roomUrl:this.roomUrl,obiState:this.storedActiveState??this.state,sessionExpiry:e.toISOString()};Tl.setItem(Ul.SESSION_DATA,JSON.stringify(t))}}async sessionConnectionCheck(){const e=function(){let t={};return t=JSON.parse(localStorage.getItem("obi-url-params")||"{}"),Object.keys(t).length===0&&new URLSearchParams(window.location.search).forEach((i,r)=>{t[r]=i}),localStorage.removeItem("obi-url-params"),t[Ph]}();if(!e){await this.checkExistingSession();return}console.log("[obi-sdk] using magic link"),this.apiKey?await this.handleUrlSessionEvent(e):(console.log("[obi-sdk] API key not ready, retrying..."),setTimeout(()=>{this.apiKey&&this.handleUrlSessionEvent(e)},100))}connectedCallback(){super.connectedCallback(),this.updateFromConfig(),this.addEventListener("obi-config-updated",this.handleConfigUpdate.bind(this)),this.setAttribute("position",this.position),this.boundSaveSessionData=this.saveSessionData.bind(this),window.addEventListener("beforeunload",this.boundSaveSessionData),window.addEventListener("pagehide",this.boundSaveSessionData),this.isActive&&(this.urlCheckInterval=window.setInterval(()=>{this.currentUrl!==window.location.href&&(this.currentUrl=window.location.href,this.handleUrlChange())},1e3)),this.addEventListener("course-select",this.handleCourseSelectEvent)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("obi-config-updated",this.handleConfigUpdate.bind(this)),this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.researchingTimeoutRef!==null&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.boundSaveSessionData&&(window.removeEventListener("beforeunload",this.boundSaveSessionData),window.removeEventListener("pagehide",this.boundSaveSessionData)),this.urlCheckInterval!==null&&(clearInterval(this.urlCheckInterval),this.urlCheckInterval=null),this.removeSessionUrlParams()}handleConfigUpdate(e){const i=e.detail.isActive&&!this.isActive;this.updateFromConfig(),this.position&&this.setAttribute("position",this.position),i&&!co(this.urlBlacklist)&&this.sessionConnectionCheck(),this.requestUpdate()}handleMouseEnter(){this.isHovering=!0,this.navVisible=!0}handleMouseLeave(){this.isHovering=!1,this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.closeNavTimeoutRef=window.setTimeout(()=>{this.isHovering||(this.navVisible=!1),this.closeNavTimeoutRef=null},300)}terminateSession(){this.clearSessionStorage(),this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.researchingTimeoutRef!==null&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=O.READY}handleItemSelect(e,t){if(e==="experiences"){this.showCourseModal=!0;return}hi([e,t]).with(["pause",!0],()=>{this.activeSession?.pauseRecording()}).with(["pause",!1],()=>{this.activeSession?.resumeRecording()}).with(["activate",!1],()=>{this.terminateSession()}).otherwise(()=>{})}async fetchDatabaseConfig(){if(!this.apiKey){this.configLoaded=!0,this.applyFinalConfiguration();return}try{const e=`obi-widget-config-${this.apiKey}`,t=localStorage.getItem(e),n=localStorage.getItem(`${e}-timestamp`);if(t&&n){const a=Date.now()-parseInt(n,10),c=10*60*1e3;if(a<c){const l=JSON.parse(t);this.databaseConfig=l,this.configLoaded=!0,this.applyFinalConfiguration();return}}const i=new AbortController,r=setTimeout(()=>i.abort(),3e3),s=await this.obiClient.getOnboardeeWidgetConfig(this.apiKey,i.signal);if(clearTimeout(r),s.error){if(s.response?.status===404){localStorage.removeItem(e),localStorage.removeItem(`${e}-timestamp`),this.databaseConfig=null,this.configLoaded=!0,this.applyFinalConfiguration();return}throw new Error(`HTTP ${s.response?.status||"Unknown error"}`)}const o=s.data;localStorage.setItem(e,JSON.stringify(o)),localStorage.setItem(`${e}-timestamp`,Date.now().toString()),this.databaseConfig=o,this.configLoaded=!0,this.applyFinalConfiguration()}catch(e){e instanceof Error&&e.name==="AbortError"?console.warn("Widget config fetch timed out, using defaults"):console.warn("Failed to fetch widget config from database:",e),this.databaseConfig=null,this.configLoaded=!0,this.applyFinalConfiguration()}}applyFinalConfiguration(){const e=window.obiWidgetConfig,t=this.databaseConfig;this.user=e?.user||this.user,this.position=e?.position||t?.position||this.position,this.setAttribute("position",this.position),e?.isActive!==void 0&&(this.isActive=e.isActive),e?.linkOnlyAccess!==void 0?this.linkOnlyAccess=e.linkOnlyAccess:t?.linkOnlyAccess!==void 0&&(this.linkOnlyAccess=t.linkOnlyAccess);const n=e?.urlBlacklist||[],i=t?.urlBlacklist||[];if(n.length>0||i.length>0){const s=[...n,...i];this.urlBlacklist=[...new Set(s)]}const r=e?.primaryColor||t?.primaryColor||Mr;this.style.setProperty("--obi-primary",r),this.generateColorVariables(r),this.isActive&&!co(this.urlBlacklist)&&this.sessionConnectionCheck()}render(){if(!this.configLoaded||!this.isActive||this.linkOnlyAccess&&this.state===O.READY||co(this.urlBlacklist))return L.nothing;const e=hi(this.state).with(O.LOADING,()=>L.html`<obi-dot-loader></obi-dot-loader>`).with(O.RESEARCHING,()=>L.html`<obi-searching-loader></obi-searching-loader>`).with(UC.union(O.USER_SPEAKING,O.AGENT_SPEAKING),()=>L.html`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`).with(O.THINKING,()=>L.html`<obi-dot-loader></obi-dot-loader>`).with(O.PAUSED,()=>uo).otherwise(()=>uo),t=this.state===O.USER_SPEAKING||this.state===O.AGENT_SPEAKING,n=this.state===O.PAUSED,i=this.state===O.RESEARCHING,r=this.state===O.USER_SPEAKING,s=this.state!==O.READY||this.navVisible,o=this.state!==O.READY||this.navVisible,a=this.position.includes("top")?"down":"up",c=["widget-container",s?"rotated":"",t?"pulse":"",n?"paused-pulse":"",i?"researching":"",r?"user-speaking":""].filter(Boolean).join(" ");return L.html`
|
|
1059
|
+
`,Xn([ee({type:Object})],DA.prototype,"session",2),Xn([ee({type:Function})],DA.prototype,"onStart",2),Xn([ee({type:Function})],DA.prototype,"onClose",2),Xn([oe()],DA.prototype,"isLoading",2),Xn([oe()],DA.prototype,"error",2),Xn([oe()],DA.prototype,"startAttempts",2),customElements.get("obi-session-start-modal")||customElements.define("obi-session-start-modal",DA);var y_=Object.defineProperty,b_=Object.getOwnPropertyDescriptor,Qe=(A,e,t,n)=>{for(var i=n>1?void 0:n?b_(e,t):e,r=A.length-1,s;r>=0;r--)(s=A[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&y_(e,t,i),i};let Ce=class extends L.LitElement{constructor(){super(),this.apiKey="",this.isActive=!0,this.linkOnlyAccess=!1,this.urlBlacklist=[],this.position="bottom-right",this.user=null,this.state=O.READY,this.storedActiveState=void 0,this.showCourseModal=!1,this.showSessionStartModal=!1,this.selectedCourse=null,this.isHovering=!1,this.navVisible=!1,this.activeSession=null,this.volume={speaker:"ASSISTANT",volume:0,spectrum:[]},this.databaseConfig=null,this.configLoaded=!1,this.configAllInCode=!1,this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.boundSaveSessionData=null,this.obiClient=null,this.closeNavTimeoutRef=null,this.researchingTimeoutRef=null,this.urlCheckInterval=null,this.currentUrl="",this.connectObi=Vi(async e=>{if(this.activeSession){ie("connection_already_exists",{sessionToken:e},"ObiWidget"),console.log("Connection already exists");return}ie("session_connection_started",{sessionToken:e},"ObiWidget"),Gi({sessionId:e});try{const t=this.createSession(e);if(!t){this.handleSessionCreationFailure(()=>this.removeSessionUrlParams());return}this.setupSessionEventListeners(t,()=>this.removeSessionUrlParams()),t.on("screenCaptureRequested",Vi(async()=>{ie("screen_capture_requested",{},"ObiWidget");try{const r=(await vT(document.documentElement,{useCORS:!0,allowTaint:!0,foreignObjectRendering:!0})).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",r),ie("screen_capture_completed",{},"ObiWidget")}catch(i){Me(i,{componentName:"ObiWidget",handlerName:"screenCaptureRequested",sessionToken:e}),console.error("[obi] error capturing screen:",i),this.activeSession.emit("screenCaptureComplete","error"),ie("screen_capture_failed",{error:i instanceof Error?i.message:String(i)},"ObiWidget")}},"screenCaptureRequested","ObiWidget"));const n=await t.connect();n&&(this.sessionToken=e,this.roomToken=n.token,this.roomUrl=n.url,Gi({sessionId:e,widgetState:this.state.toString()}),this.removeSessionUrlParams(),ie("session_connection_established",{sessionToken:e,hasRoomToken:!!n.token},"ObiWidget")),this.activeSession=t}catch(t){console.error("Failed to start session:",t),Me(t,{componentName:"ObiWidget",handlerName:"connectObi",sessionToken:e}),this.handleSessionCreationFailure(()=>this.removeSessionUrlParams())}},"connectObi","ObiWidget"),this.handleCloseModals=()=>{this.state=O.READY,this.showCourseModal=!1,this.showSessionStartModal=!1},this.handleCourseSelectEvent=e=>{const t=e;this.selectedCourse=t.detail,this.showCourseModal=!1,this.showSessionStartModal=!0},this.handleUrlSessionEvent=Vi(async e=>{ie("url_session_event",{sessionToken:e},"ObiWidget");try{if(!this.obiClient){const n=new Error("ObiClient not initialized");Me(n,{componentName:"ObiWidget",handlerName:"handleUrlSessionEvent",sessionToken:e}),console.error("ObiClient not initialized");return}const t=await this.obiClient.startSession(e,this.apiKey);if(t.data){const{session:n}=t.data;if(console.log("[obi-sdk] session:",n),ie("session_started",{sessionId:n?.id,sessionToken:e},"ObiWidget"),n){const i=n;this.selectedCourse={id:e,name:i.onboarding_plan?.name||"",description:i.onboarding_plan?.description||""},this.state=O.LOADING,this.showSessionStartModal=!0,ie("matching_session_found",{sessionToken:e,hasOnboardingPlan:!!i.onboarding_plan},"ObiWidget")}else console.log("[obi-sdk] no session found with token:",e),ie("no_matching_session",{sessionToken:e},"ObiWidget")}}catch(t){console.error("Failed to fetch session details:",t),Me(t,{componentName:"ObiWidget",handlerName:"handleUrlSessionEvent",sessionToken:e})}},"handleUrlSessionEvent","ObiWidget"),this.handleSessionStart=Vi(async e=>{ie("session_start_requested",{sessionToken:e},"ObiWidget"),this.activeSession&&(ie("session_start_blocked",{sessionToken:e},"ObiWidget"),Me(new Error("Session start blocked"),{componentName:"ObiWidget",handlerName:"handleSessionStart",sessionToken:e}),this.activeSession.disconnect(),this.activeSession=null),this.showSessionStartModal=!1,this.state=O.LOADING,Gi({widgetState:this.state.toString()}),await this.connectObi(e)},"handleSessionStart","ObiWidget"),this.checkExistingSession=Vi(async()=>{ie("checking_existing_session",{},"ObiWidget");try{const e=JSON.parse(Tl.getItem(Ul.SESSION_DATA)||"{}"),{sessionToken:t,roomToken:n,roomUrl:i,sessionExpiry:r,obiState:s}=e;if(!t||!n||!i){ie("no_existing_session_data",{},"ObiWidget");return}if(console.log("[obi-sdk] using existing session"),ie("existing_session_data_found",{sessionToken:t,hasExpiry:!!r,obiState:s},"ObiWidget"),r&&new Date(r)<new Date){this.clearSessionStorage(),ie("session_expired",{sessionToken:t},"ObiWidget");return}this.state=O.LOADING,Gi({sessionId:t,widgetState:this.state.toString()});const o=this.createSession(t);if(!o){this.handleSessionCreationFailure(()=>this.clearSessionStorage());return}this.setupSessionEventListeners(o,()=>this.clearSessionStorage()),await o.reconnect(i,n,s)?(this.activeSession=o,this.sessionToken=t,this.roomToken=n,this.roomUrl=i,this.state=s,this.storedActiveState=s,ie("session_reconnected",{sessionToken:t,obiState:s},"ObiWidget")):(this.clearSessionStorage(),ie("session_reconnection_failed",{sessionToken:t},"ObiWidget"))}catch(e){console.error("Error reconnecting to session:",e),Me(e,{componentName:"ObiWidget",handlerName:"checkExistingSession"}),this.handleSessionCreationFailure(()=>this.clearSessionStorage())}},"checkExistingSession","ObiWidget");try{vm("ObiWidget").setContext(),this.obiClient=new Qh({baseUrl:Ka}),this.currentUrl=window.location.href;const t=()=>{try{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()}catch(n){Me(n,{componentName:"ObiWidget",handlerName:"handleUnload"})}};window.addEventListener("beforeunload",t),window.addEventListener("pagehide",t),ie("ObiWidget_constructor_completed",{},"ObiWidget")}catch(e){throw Me(e,{componentName:"ObiWidget",lifecycle:"constructor"}),e}}updateFromConfig(){if(window.obiWidgetConfig){this.apiKey=window.obiWidgetConfig.apiKey||this.apiKey,window.obiWidgetConfig.position!==void 0&&(this.position=window.obiWidgetConfig.position,this.setAttribute("position",this.position)),window.obiWidgetConfig.primaryColor!==void 0&&(this.style.setProperty("--obi-primary",window.obiWidgetConfig.primaryColor),this.generateColorVariables(window.obiWidgetConfig.primaryColor)),window.obiWidgetConfig.user!==void 0&&(this.user=window.obiWidgetConfig.user),window.obiWidgetConfig.isActive!==void 0&&(this.isActive=window.obiWidgetConfig.isActive),window.obiWidgetConfig.linkOnlyAccess!==void 0&&(this.linkOnlyAccess=window.obiWidgetConfig.linkOnlyAccess),window.obiWidgetConfig.urlBlacklist!==void 0&&(this.urlBlacklist=window.obiWidgetConfig.urlBlacklist);const e=window.obiWidgetConfig.position!==void 0,t=window.obiWidgetConfig.primaryColor!==void 0,n=window.obiWidgetConfig.linkOnlyAccess!==void 0,i=window.obiWidgetConfig.urlBlacklist!==void 0;this.configAllInCode=e&&t&&n&&i,this.configAllInCode?(this.configLoaded=!0,this.applyFinalConfiguration()):this.configLoaded||this.fetchDatabaseConfig(),window.obiWidgetConfig.showMenu===!0&&(this.state=O.LOADING,this.showCourseModal=!0,window.obiWidgetConfig.showMenu=!1)}else this.configLoaded||this.fetchDatabaseConfig()}generateColorVariables(e){try{const t=Ga(e,"#c4b5fd"),n=Ga(e,"#c76cff"),i=tw(e),r=Ga(e,"#A06DF9");this.style.setProperty("--obi-secondary",t),this.style.setProperty("--obi-course-selected",n),this.style.setProperty("--obi-course-selected-bg",i),this.style.setProperty("--obi-paused-pulse",r)}catch(t){console.warn("Failed to generate color variables:",t),this.style.setProperty("--obi-secondary","#c4b5fd"),this.style.setProperty("--obi-course-selected","#c76cff"),this.style.setProperty("--obi-course-selected-bg","#fbf3ff"),this.style.setProperty("--obi-paused-pulse","#A06DF9")}}removeSessionUrlParams(){const e=new URL(window.location.href);e.searchParams.delete(Ph),window.history.replaceState({},"",e.toString()),localStorage.removeItem("obi-url-params")}createSession(e){try{const t=new OC({sessionId:e,apiBaseUrl:Ka});return t||(console.error("Failed to create session"),null)}catch(t){return console.error("Error creating session:",t),null}}setupSessionEventListeners(e,t){e.on("stateChanged",n=>{if(n===O.RESEARCHING){this.researchingTimeoutRef&&window.clearTimeout(this.researchingTimeoutRef),this.state=n,this.researchingTimeoutRef=window.setTimeout(()=>{this.researchingTimeoutRef=null;const i=e.getCurrentState();this.state=i,i!==O.READY&&(this.storedActiveState=i)},1500),this.storedActiveState=n;return}this.researchingTimeoutRef===null&&(this.state=n,n!==O.READY&&(this.storedActiveState=n))}),e.on("volume",({speaker:n,spectrum:i,volume:r})=>{this.volume={speaker:n,spectrum:i,volume:r}}),e.on("error",n=>{console.error("Session error:",n),this.state=O.ERROR,this.activeSession=null,t&&t()})}handleSessionCreationFailure(e){this.state=O.ERROR,this.activeSession=null,e&&e()}clearSessionStorage(){Tl.removeItem(Ul.SESSION_DATA)}handleUrlChange(){this.requestUpdate(),co(this.urlBlacklist)&&this.activeSession&&this.terminateSession()}saveSessionData(){if(this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl){const e=new Date;e.setMinutes(e.getMinutes()+5);const t={sessionToken:this.sessionToken,roomToken:this.roomToken,roomUrl:this.roomUrl,obiState:this.storedActiveState??this.state,sessionExpiry:e.toISOString()};Tl.setItem(Ul.SESSION_DATA,JSON.stringify(t))}}async sessionConnectionCheck(){const e=function(){let t={};return t=JSON.parse(localStorage.getItem("obi-url-params")||"{}"),Object.keys(t).length===0&&new URLSearchParams(window.location.search).forEach((i,r)=>{t[r]=i}),localStorage.removeItem("obi-url-params"),t[Ph]}();if(!e){await this.checkExistingSession();return}console.log("[obi-sdk] using magic link"),this.apiKey?await this.handleUrlSessionEvent(e):(console.log("[obi-sdk] API key not ready, retrying..."),setTimeout(()=>{this.apiKey&&this.handleUrlSessionEvent(e)},100))}connectedCallback(){super.connectedCallback(),this.updateFromConfig(),this.addEventListener("obi-config-updated",this.handleConfigUpdate.bind(this)),this.setAttribute("position",this.position),this.boundSaveSessionData=this.saveSessionData.bind(this),window.addEventListener("beforeunload",this.boundSaveSessionData),window.addEventListener("pagehide",this.boundSaveSessionData),this.isActive&&(this.urlCheckInterval=window.setInterval(()=>{this.currentUrl!==window.location.href&&(this.currentUrl=window.location.href,this.handleUrlChange())},1e3)),this.addEventListener("course-select",this.handleCourseSelectEvent)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("obi-config-updated",this.handleConfigUpdate.bind(this)),this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.researchingTimeoutRef!==null&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.boundSaveSessionData&&(window.removeEventListener("beforeunload",this.boundSaveSessionData),window.removeEventListener("pagehide",this.boundSaveSessionData)),this.urlCheckInterval!==null&&(clearInterval(this.urlCheckInterval),this.urlCheckInterval=null),this.removeSessionUrlParams()}handleConfigUpdate(e){const i=e.detail.isActive&&!this.isActive;this.updateFromConfig(),i&&!co(this.urlBlacklist)&&this.sessionConnectionCheck(),this.requestUpdate()}handleMouseEnter(){this.isHovering=!0,this.navVisible=!0}handleMouseLeave(){this.isHovering=!1,this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.closeNavTimeoutRef=window.setTimeout(()=>{this.isHovering||(this.navVisible=!1),this.closeNavTimeoutRef=null},300)}terminateSession(){this.clearSessionStorage(),this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.researchingTimeoutRef!==null&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=O.READY}handleItemSelect(e,t){if(e==="experiences"){this.showCourseModal=!0;return}hi([e,t]).with(["pause",!0],()=>{this.activeSession?.pauseRecording()}).with(["pause",!1],()=>{this.activeSession?.resumeRecording()}).with(["activate",!1],()=>{this.terminateSession()}).otherwise(()=>{})}async fetchDatabaseConfig(){if(!this.apiKey){this.configLoaded=!0,this.applyFinalConfiguration();return}try{const e=`obi-widget-config-${this.apiKey}`,t=localStorage.getItem(e),n=localStorage.getItem(`${e}-timestamp`);if(t&&n){const a=Date.now()-parseInt(n,10),c=10*60*1e3;if(a<c){const l=JSON.parse(t);this.databaseConfig=l,this.configLoaded=!0,this.applyFinalConfiguration();return}}const i=new AbortController,r=setTimeout(()=>i.abort(),3e3),s=await this.obiClient.getOnboardeeWidgetConfig(this.apiKey,i.signal);if(clearTimeout(r),s.error){if(s.response?.status===404){localStorage.removeItem(e),localStorage.removeItem(`${e}-timestamp`),this.databaseConfig=null,this.configLoaded=!0,this.applyFinalConfiguration();return}throw new Error(`HTTP ${s.response?.status||"Unknown error"}`)}const o=s.data;localStorage.setItem(e,JSON.stringify(o)),localStorage.setItem(`${e}-timestamp`,Date.now().toString()),this.databaseConfig=o,this.configLoaded=!0,this.applyFinalConfiguration()}catch(e){e instanceof Error&&e.name==="AbortError"?console.warn("Widget config fetch timed out, using defaults"):console.warn("Failed to fetch widget config from database:",e),this.databaseConfig=null,this.configLoaded=!0,this.applyFinalConfiguration()}}applyFinalConfiguration(){const e=window.obiWidgetConfig,t=this.databaseConfig;this.user=e?.user||this.user,this.position=e?.position||t?.position||this.position,this.setAttribute("position",this.position),e?.isActive!==void 0&&(this.isActive=e.isActive),e?.linkOnlyAccess!==void 0?this.linkOnlyAccess=e.linkOnlyAccess:t?.linkOnlyAccess!==void 0&&(this.linkOnlyAccess=t.linkOnlyAccess);const n=e?.urlBlacklist||[],i=t?.urlBlacklist||[];if(n.length>0||i.length>0){const s=[...n,...i];this.urlBlacklist=[...new Set(s)]}const r=e?.primaryColor||t?.primaryColor||Mr;this.style.setProperty("--obi-primary",r),this.generateColorVariables(r),this.isActive&&!co(this.urlBlacklist)&&this.sessionConnectionCheck()}render(){if(!this.configLoaded||!this.isActive||this.linkOnlyAccess&&this.state===O.READY||co(this.urlBlacklist))return L.nothing;const e=hi(this.state).with(O.LOADING,()=>L.html`<obi-dot-loader></obi-dot-loader>`).with(O.RESEARCHING,()=>L.html`<obi-searching-loader></obi-searching-loader>`).with(UC.union(O.USER_SPEAKING,O.AGENT_SPEAKING),()=>L.html`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`).with(O.THINKING,()=>L.html`<obi-dot-loader></obi-dot-loader>`).with(O.PAUSED,()=>uo).otherwise(()=>uo),t=this.state===O.USER_SPEAKING||this.state===O.AGENT_SPEAKING,n=this.state===O.PAUSED,i=this.state===O.RESEARCHING,r=this.state===O.USER_SPEAKING,s=this.state!==O.READY||this.navVisible,o=this.state!==O.READY||this.navVisible,a=this.position.includes("top")?"down":"up",c=["widget-container",s?"rotated":"",t?"pulse":"",n?"paused-pulse":"",i?"researching":"",r?"user-speaking":""].filter(Boolean).join(" ");return L.html`
|
|
1060
1060
|
<div
|
|
1061
1061
|
class="${c}"
|
|
1062
1062
|
@mouseenter=${this.handleMouseEnter}
|
|
@@ -1232,5 +1232,5 @@ Url: ${io(A)}`),!0}return!1}function $F(A,e){return e?.length?Vp(A).some(t=>Xs(t
|
|
|
1232
1232
|
box-shadow: 0px 0px 18px 6px
|
|
1233
1233
|
color-mix(in srgb, var(--obi-paused-pulse, #a06df9) 75%, transparent);
|
|
1234
1234
|
}
|
|
1235
|
-
`,Qe([oe()],Ce.prototype,"apiKey",2),Qe([oe()],Ce.prototype,"isActive",2),Qe([oe()],Ce.prototype,"linkOnlyAccess",2),Qe([oe()],Ce.prototype,"urlBlacklist",2),Qe([oe()],Ce.prototype,"position",2),Qe([oe()],Ce.prototype,"user",2),Qe([oe()],Ce.prototype,"state",2),Qe([oe()],Ce.prototype,"storedActiveState",2),Qe([oe()],Ce.prototype,"showCourseModal",2),Qe([oe()],Ce.prototype,"showSessionStartModal",2),Qe([oe()],Ce.prototype,"selectedCourse",2),Qe([oe()],Ce.prototype,"isHovering",2),Qe([oe()],Ce.prototype,"navVisible",2),Qe([oe()],Ce.prototype,"activeSession",2),Qe([oe()],Ce.prototype,"volume",2),Qe([oe()],Ce.prototype,"databaseConfig",2),Qe([oe()],Ce.prototype,"configLoaded",2),Qe([oe()],Ce.prototype,"
|
|
1235
|
+
`,Qe([oe()],Ce.prototype,"apiKey",2),Qe([oe()],Ce.prototype,"isActive",2),Qe([oe()],Ce.prototype,"linkOnlyAccess",2),Qe([oe()],Ce.prototype,"urlBlacklist",2),Qe([oe()],Ce.prototype,"position",2),Qe([oe()],Ce.prototype,"user",2),Qe([oe()],Ce.prototype,"state",2),Qe([oe()],Ce.prototype,"storedActiveState",2),Qe([oe()],Ce.prototype,"showCourseModal",2),Qe([oe()],Ce.prototype,"showSessionStartModal",2),Qe([oe()],Ce.prototype,"selectedCourse",2),Qe([oe()],Ce.prototype,"isHovering",2),Qe([oe()],Ce.prototype,"navVisible",2),Qe([oe()],Ce.prototype,"activeSession",2),Qe([oe()],Ce.prototype,"volume",2),Qe([oe()],Ce.prototype,"databaseConfig",2),Qe([oe()],Ce.prototype,"configLoaded",2),Qe([oe()],Ce.prototype,"configAllInCode",2),customElements.get("obi-widget")||customElements.define("obi-widget",Ce);const E_=zn({tagName:"obi-course-modal",elementClass:Ft,react:Kt}),S_=zn({tagName:"obi-audio-equalizer",elementClass:zi,react:Kt}),U_=zn({tagName:"obi-dot-loader",elementClass:Bo,react:Kt}),T_=zn({tagName:"obi-searching-loader",elementClass:Il,react:Kt}),Q_=zn({tagName:"obi-widget",elementClass:Ce,react:Kt});ot.AudioEqualizer=S_,ot.CourseModal=E_,ot.DotLoader=U_,ot.ObiWidget=Q_,ot.SearchingLoader=T_,Object.defineProperty(ot,Symbol.toStringTag,{value:"Module"})});
|
|
1236
1236
|
//# sourceMappingURL=react.umd.js.map
|