obi-sdk 0.13.0 → 0.13.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-14b8cc26.js +6 -0
- package/dist/modular/chunks/index-14b8cc26.js.map +1 -0
- package/dist/modular/chunks/{obi-widget-5c728b05.js → obi-widget-d596380b.js} +6 -1
- package/dist/modular/chunks/{obi-widget-5c728b05.js.map → obi-widget-d596380b.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 -1
- package/dist/obi-sdk.standalone.iife.js.map +1 -1
- package/dist/react.es.js +2 -1
- package/dist/react.es.js.map +1 -1
- package/dist/react.umd.js +2 -1
- package/dist/react.umd.js.map +1 -1
- package/package.json +3 -3
- package/dist/modular/chunks/index-c25ba599.js +0 -6
- package/dist/modular/chunks/index-c25ba599.js.map +0 -1
package/dist/react.umd.js
CHANGED
|
@@ -2541,7 +2541,7 @@ Url: ${$o(A)}`),!0}return!1}function yQ(A,e){return e?.length?zm(A).some(t=>Ro(t
|
|
|
2541
2541
|
.disabled=${this.disabled}
|
|
2542
2542
|
></obi-voice-guidance-content>
|
|
2543
2543
|
</obi-base-onboarding-modal>
|
|
2544
|
-
`}}qA.styles=[Ce],Ui([L({type:Object})],qA.prototype,"session",2),Ui([L({type:Boolean,reflect:!0})],qA.prototype,"open",2),Ui([L()],qA.prototype,"color",2),Ui([L({type:Boolean,reflect:!0})],qA.prototype,"disabled",2),Ui([L({type:Boolean,reflect:!0})],qA.prototype,"loading",2),Ui([L({type:Boolean,attribute:"close-disabled"})],qA.prototype,"closeDisabled",2),customElements.get("obi-voice-guidance-modal")||customElements.define("obi-voice-guidance-modal",qA);var h2=Object.defineProperty,f2=Object.getOwnPropertyDescriptor,pe=(A,e,t,n)=>{for(var i=n>1?void 0:n?f2(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&&h2(e,t,i),i};let ce=class extends S.LitElement{constructor(){super(),this.apiKey="",this.isActive=!0,this.linkOnlyAccess=!1,this.urlBlacklist=[],this.position="bottom-right",this.user=null,this.state=H.READY,this.storedActiveState=void 0,this.showCourseModal=!1,this.showSessionStartModal=!1,this.showShareMicModal=!1,this.micShareEnabled=!1,this.showVoiceGuidanceModal=!1,this.voiceGuidanceEnabled=!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.primaryColor="#9500FF",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=br(async e=>{if(this.activeSession){ee("connection_already_exists",{sessionToken:e},"ObiWidget"),console.log("Connection already exists");return}ee("session_connection_started",{sessionToken:e},"ObiWidget"),Cr({sessionId:e});try{const t=this.createSession(e);if(!t){this.handleSessionCreationFailure(()=>this.removeSessionUrlParams());return}this.setupSessionEventListeners(t,()=>this.removeSessionUrlParams()),t.on("screenCaptureRequested",br(async()=>{ee("screen_capture_requested",{},"ObiWidget");try{const r=(await q1(document.documentElement,{useCORS:!0,allowTaint:!0,foreignObjectRendering:!0})).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",r),ee("screen_capture_completed",{},"ObiWidget")}catch(i){$e(i,{componentName:"ObiWidget",handlerName:"screenCaptureRequested",sessionToken:e}),console.error("[obi] error capturing screen:",i),this.activeSession.emit("screenCaptureComplete","error"),ee("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,Cr({sessionId:e,widgetState:this.state.toString()}),this.removeSessionUrlParams(),ee("session_connection_established",{sessionToken:e,hasRoomToken:!!n.token},"ObiWidget")),this.activeSession=t}catch(t){console.error("Failed to start session:",t),$e(t,{componentName:"ObiWidget",handlerName:"connectObi",sessionToken:e}),this.handleSessionCreationFailure(()=>this.removeSessionUrlParams())}},"connectObi","ObiWidget"),this.handleCloseModals=()=>{this.state=H.READY,this.showCourseModal=!1,this.showSessionStartModal=!1,this.showShareMicModal=!1},this.handleCourseSelectEvent=e=>{const t=e;this.selectedCourse=t.detail,this.showCourseModal=!1,this.showSessionStartModal=!0,this.showShareMicModal=!1},this.handleUrlSessionEvent=br(async e=>{ee("url_session_event",{sessionToken:e},"ObiWidget");try{if(!this.obiClient){const n=new Error("ObiClient not initialized");$e(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),ee("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=H.LOADING,this.showSessionStartModal=!0,ee("matching_session_found",{sessionToken:e,hasOnboardingPlan:!!i.onboarding_plan},"ObiWidget")}else console.log("[obi-sdk] no session found with token:",e),ee("no_matching_session",{sessionToken:e},"ObiWidget")}}catch(t){console.error("Failed to fetch session details:",t),$e(t,{componentName:"ObiWidget",handlerName:"handleUrlSessionEvent",sessionToken:e})}},"handleUrlSessionEvent","ObiWidget"),this.handleSessionStart=br(async e=>{ee("session_start_requested",{sessionToken:e},"ObiWidget"),this.activeSession&&(ee("session_start_blocked",{sessionToken:e},"ObiWidget"),$e(new Error("Session start blocked"),{componentName:"ObiWidget",handlerName:"handleSessionStart",sessionToken:e}),this.activeSession.disconnect(),this.activeSession=null),this.showSessionStartModal=!1,this.showShareMicModal=!0,this.state=H.LOADING,Cr({widgetState:this.state.toString()}),await this.connectObi(e)},"handleSessionStart","ObiWidget"),this.handleSessionModalStart=e=>{const{sessionId:t,attempt:n}=e.detail;if(console.log("[SessionStartModal] Start button clicked",{sessionId:t,hasSession:!!this.selectedCourse,startAttempts:n,timestamp:new Date().toISOString()}),ee("session_start_modal_continue_clicked",{sessionId:t,sessionName:this.selectedCourse?.name},"SessionStartModal"),!this.selectedCourse){const i="Session data is missing.";console.error("[SessionStartModal] Validation failed:",i),$e(i,{componentName:"SessionStartModal",handlerName:"handleSessionModalStart",sessionData:this.selectedCourse});return}if(!this.selectedCourse.id){const i="Session ID is missing.";console.error("[SessionStartModal] Validation failed:",i,{session:this.selectedCourse}),$e(i,{componentName:"SessionStartModal",handlerName:"handleSessionModalStart",sessionData:this.selectedCourse});return}console.log("[SessionStartModal] Starting session attempt",{attempt:n,sessionId:this.selectedCourse.id}),ee("session_start_modal_calling_onStart",{sessionId:this.selectedCourse.id},"SessionStartModal"),this.handleSessionStart(this.selectedCourse.id),console.log("[SessionStartModal] Session start completed successfully",{sessionId:this.selectedCourse.id,attempt:n}),ee("session_start_modal_onStart_called",{sessionId:this.selectedCourse.id},"SessionStartModal")},this.handleSessionModalClose=()=>{console.log("[SessionStartModal] Close button clicked",{sessionId:this.selectedCourse?.id}),this.handleCloseModals(),this.selectedCourse=null,this.removeSessionUrlParams()},this.handleSessionModalError=e=>{const{error:t,sessionId:n}=e.detail;console.error("[SessionStartModal] Error occurred",{error:t instanceof Error?t.message:String(t),sessionId:n}),$e(t,{componentName:"SessionStartModal",handlerName:"handleSessionModalError",sessionId:n})},this.handleShareMicModalContinue=async e=>{const{session:t,micPermissionGranted:n}=e.detail;if(console.log("[ShareMicModal] Continue button clicked",{sessionId:t?.id,micPermissionGranted:n,timestamp:new Date().toISOString()}),ee("share_mic_modal_continue_clicked",{sessionId:t?.id,micPermissionGranted:n},"ShareMicModal"),!this.activeSession){console.error("[obi] no active session during microphone sharing");return}await this.activeSession.shareMic(),this.showShareMicModal=!1,this.showVoiceGuidanceModal=!0},this.handleShareMicModalClose=()=>{console.log("[ShareMicModal] Close button clicked",{sessionId:this.selectedCourse?.id}),this.handleCloseModals()},this.handleVoiceGuidanceModalContinue=async()=>{console.log("[obi] voice guidance modal continue",{sessionId:this.selectedCourse?.id,timestamp:new Date().toISOString()}),ee("voice_guidance_modal_continue_clicked",{sessionId:this.selectedCourse?.id},"ShareMicModal"),await this.activeSession?.promptContinue(),this.showVoiceGuidanceModal=!1},this.handleVoiceGuidanceModalClose=()=>{console.log("[obi] voice guidance modal close",{sessionId:this.selectedCourse?.id}),this.handleCloseModals()},this.checkExistingSession=br(async()=>{ee("checking_existing_session",{},"ObiWidget");try{const e=JSON.parse(Ed.getItem(yd.SESSION_DATA)||"{}"),{sessionToken:t,roomToken:n,roomUrl:i,sessionExpiry:r,obiState:s}=e;if(!t||!n||!i){ee("no_existing_session_data",{},"ObiWidget");return}if(console.log("[obi-sdk] using existing session"),ee("existing_session_data_found",{sessionToken:t,hasExpiry:!!r,obiState:s},"ObiWidget"),r&&new Date(r)<new Date){this.clearSessionStorage(),ee("session_expired",{sessionToken:t},"ObiWidget");return}this.state=H.LOADING,Cr({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,ee("session_reconnected",{sessionToken:t,obiState:s},"ObiWidget")):(this.clearSessionStorage(),ee("session_reconnection_failed",{sessionToken:t},"ObiWidget"))}catch(e){console.error("Error reconnecting to session:",e),$e(e,{componentName:"ObiWidget",handlerName:"checkExistingSession"}),this.handleSessionCreationFailure(()=>this.clearSessionStorage())}},"checkExistingSession","ObiWidget");try{U0("ObiWidget").setContext(),this.obiClient=new Lf({baseUrl:Hc}),this.currentUrl=window.location.href;const t=()=>{try{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()}catch(n){$e(n,{componentName:"ObiWidget",handlerName:"handleUnload"})}};window.addEventListener("beforeunload",t),window.addEventListener("pagehide",t),ee("ObiWidget_constructor_completed",{},"ObiWidget")}catch(e){throw $e(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=H.LOADING,this.showCourseModal=!0,window.obiWidgetConfig.showMenu=!1)}else this.configLoaded||this.fetchDatabaseConfig()}generateColorVariables(e){try{this.primaryColor=e;const t=Mc(e,"#c4b5fd"),n=Mc(e,"#c76cff"),i=_w(e),r=Mc(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($f),window.history.replaceState({},"",e.toString()),localStorage.removeItem("obi-url-params")}createSession(e){try{const t=new pw({sessionId:e,apiBaseUrl:Hc,...this.user&&{user:this.user}});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===H.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!==H.READY&&(this.storedActiveState=i)},1500),this.storedActiveState=n;return}this.researchingTimeoutRef===null&&(this.state=n,n!==H.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=H.ERROR,this.activeSession=null,t&&t()}),e.on("micShareRequested",()=>{this.micShareEnabled=!0}),e.on("promptUser",()=>{this.voiceGuidanceEnabled=!0})}handleSessionCreationFailure(e){this.state=H.ERROR,this.activeSession=null,e&&e()}clearSessionStorage(){Ed.removeItem(yd.SESSION_DATA)}handleUrlChange(){this.requestUpdate(),Jo(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()};Ed.setItem(yd.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}),t[$f]}();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()}async handleConfigUpdate(e){const n=e.detail,i=n.isActive&&!this.isActive,r=this.user;if(this.updateFromConfig(),this.activeSession&&n.user!==void 0){const s=n.user;if(JSON.stringify(r)!==JSON.stringify(s))try{await this.activeSession.updateUser(s)}catch(o){console.error("Failed to update session user data:",o)}}i&&!Jo(this.urlBlacklist)&&!this.activeSession&&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=H.READY}handleItemSelect(e,t){if(e==="experiences"){this.showCourseModal=!0,this.showShareMicModal=!1;return}Vi([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||Es;this.primaryColor=r,this.style.setProperty("--obi-primary",r),this.generateColorVariables(r),this.isActive&&!Jo(this.urlBlacklist)&&!this.activeSession&&this.sessionConnectionCheck()}render(){if(!this.configLoaded||!this.isActive||this.linkOnlyAccess&&this.state===H.READY||Jo(this.urlBlacklist))return S.nothing;const e=Vi(this.state).with(H.LOADING,()=>S.html`<obi-dot-loader></obi-dot-loader>`).with(H.RESEARCHING,()=>S.html`<obi-searching-loader></obi-searching-loader>`).with(nw.union(H.USER_SPEAKING,H.AGENT_SPEAKING),()=>S.html`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`).with(H.THINKING,()=>S.html`<obi-dot-loader></obi-dot-loader>`).with(H.PAUSED,()=>Sd).otherwise(()=>Sd),t=this.state===H.USER_SPEAKING||this.state===H.AGENT_SPEAKING,n=this.state===H.PAUSED,i=this.state===H.RESEARCHING,r=this.state===H.USER_SPEAKING,s=this.state!==H.READY||this.navVisible,o=this.state!==H.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 S.html`
|
|
2544
|
+
`}}qA.styles=[Ce],Ui([L({type:Object})],qA.prototype,"session",2),Ui([L({type:Boolean,reflect:!0})],qA.prototype,"open",2),Ui([L()],qA.prototype,"color",2),Ui([L({type:Boolean,reflect:!0})],qA.prototype,"disabled",2),Ui([L({type:Boolean,reflect:!0})],qA.prototype,"loading",2),Ui([L({type:Boolean,attribute:"close-disabled"})],qA.prototype,"closeDisabled",2),customElements.get("obi-voice-guidance-modal")||customElements.define("obi-voice-guidance-modal",qA);var h2=Object.defineProperty,f2=Object.getOwnPropertyDescriptor,pe=(A,e,t,n)=>{for(var i=n>1?void 0:n?f2(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&&h2(e,t,i),i};let ce=class extends S.LitElement{constructor(){super(),this.apiKey="",this.isActive=!0,this.linkOnlyAccess=!1,this.urlBlacklist=[],this.position="bottom-right",this.user=null,this.state=H.READY,this.storedActiveState=void 0,this.showCourseModal=!1,this.showSessionStartModal=!1,this.showShareMicModal=!1,this.micShareEnabled=!1,this.showVoiceGuidanceModal=!1,this.voiceGuidanceEnabled=!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.primaryColor="#9500FF",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=br(async e=>{if(this.activeSession){ee("connection_already_exists",{sessionToken:e},"ObiWidget"),console.log("Connection already exists");return}ee("session_connection_started",{sessionToken:e},"ObiWidget"),Cr({sessionId:e});try{const t=this.createSession(e);if(!t){this.handleSessionCreationFailure(()=>this.removeSessionUrlParams());return}this.setupSessionEventListeners(t,()=>this.removeSessionUrlParams()),t.on("screenCaptureRequested",br(async()=>{ee("screen_capture_requested",{},"ObiWidget");try{const r=(await q1(document.documentElement,{useCORS:!0,allowTaint:!0,foreignObjectRendering:!0})).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",r),ee("screen_capture_completed",{},"ObiWidget")}catch(i){$e(i,{componentName:"ObiWidget",handlerName:"screenCaptureRequested",sessionToken:e}),console.error("[obi] error capturing screen:",i),this.activeSession.emit("screenCaptureComplete","error"),ee("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,Cr({sessionId:e,widgetState:this.state.toString()}),this.removeSessionUrlParams(),ee("session_connection_established",{sessionToken:e,hasRoomToken:!!n.token},"ObiWidget")),this.activeSession=t}catch(t){console.error("Failed to start session:",t),$e(t,{componentName:"ObiWidget",handlerName:"connectObi",sessionToken:e}),this.handleSessionCreationFailure(()=>this.removeSessionUrlParams())}},"connectObi","ObiWidget"),this.handleCloseModals=()=>{this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=H.READY,this.showCourseModal=!1,this.showSessionStartModal=!1,this.showShareMicModal=!1},this.handleCourseSelectEvent=e=>{const t=e;this.selectedCourse=t.detail,this.showCourseModal=!1,this.showSessionStartModal=!0,this.showShareMicModal=!1},this.handleUrlSessionEvent=br(async e=>{ee("url_session_event",{sessionToken:e},"ObiWidget");try{if(!this.obiClient){const n=new Error("ObiClient not initialized");$e(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),ee("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=H.LOADING,this.showSessionStartModal=!0,ee("matching_session_found",{sessionToken:e,hasOnboardingPlan:!!i.onboarding_plan},"ObiWidget")}else console.log("[obi-sdk] no session found with token:",e),ee("no_matching_session",{sessionToken:e},"ObiWidget")}}catch(t){console.error("Failed to fetch session details:",t),$e(t,{componentName:"ObiWidget",handlerName:"handleUrlSessionEvent",sessionToken:e})}},"handleUrlSessionEvent","ObiWidget"),this.handleSessionStart=br(async e=>{ee("session_start_requested",{sessionToken:e},"ObiWidget"),this.activeSession&&(ee("session_start_blocked",{sessionToken:e},"ObiWidget"),$e(new Error("Session start blocked"),{componentName:"ObiWidget",handlerName:"handleSessionStart",sessionToken:e}),this.activeSession.disconnect(),this.activeSession=null),this.showSessionStartModal=!1,this.showShareMicModal=!0,this.state=H.LOADING,Cr({widgetState:this.state.toString()}),await this.connectObi(e)},"handleSessionStart","ObiWidget"),this.handleSessionModalStart=e=>{const{sessionId:t,attempt:n}=e.detail;if(console.log("[SessionStartModal] Start button clicked",{sessionId:t,hasSession:!!this.selectedCourse,startAttempts:n,timestamp:new Date().toISOString()}),ee("session_start_modal_continue_clicked",{sessionId:t,sessionName:this.selectedCourse?.name},"SessionStartModal"),!this.selectedCourse){const i="Session data is missing.";console.error("[SessionStartModal] Validation failed:",i),$e(i,{componentName:"SessionStartModal",handlerName:"handleSessionModalStart",sessionData:this.selectedCourse});return}if(!this.selectedCourse.id){const i="Session ID is missing.";console.error("[SessionStartModal] Validation failed:",i,{session:this.selectedCourse}),$e(i,{componentName:"SessionStartModal",handlerName:"handleSessionModalStart",sessionData:this.selectedCourse});return}console.log("[SessionStartModal] Starting session attempt",{attempt:n,sessionId:this.selectedCourse.id}),ee("session_start_modal_calling_onStart",{sessionId:this.selectedCourse.id},"SessionStartModal"),this.handleSessionStart(this.selectedCourse.id),console.log("[SessionStartModal] Session start completed successfully",{sessionId:this.selectedCourse.id,attempt:n}),ee("session_start_modal_onStart_called",{sessionId:this.selectedCourse.id},"SessionStartModal")},this.handleSessionModalClose=()=>{console.log("[SessionStartModal] Close button clicked",{sessionId:this.selectedCourse?.id}),this.handleCloseModals(),this.selectedCourse=null,this.removeSessionUrlParams()},this.handleSessionModalError=e=>{const{error:t,sessionId:n}=e.detail;console.error("[SessionStartModal] Error occurred",{error:t instanceof Error?t.message:String(t),sessionId:n}),$e(t,{componentName:"SessionStartModal",handlerName:"handleSessionModalError",sessionId:n})},this.handleShareMicModalContinue=async e=>{const{session:t,micPermissionGranted:n}=e.detail;if(console.log("[ShareMicModal] Continue button clicked",{sessionId:t?.id,micPermissionGranted:n,timestamp:new Date().toISOString()}),ee("share_mic_modal_continue_clicked",{sessionId:t?.id,micPermissionGranted:n},"ShareMicModal"),!this.activeSession){console.error("[obi] no active session during microphone sharing");return}await this.activeSession.shareMic(),this.showShareMicModal=!1,this.showVoiceGuidanceModal=!0},this.handleShareMicModalClose=()=>{console.log("[ShareMicModal] Close button clicked",{sessionId:this.selectedCourse?.id}),this.handleCloseModals()},this.handleVoiceGuidanceModalContinue=async()=>{console.log("[obi] voice guidance modal continue",{sessionId:this.selectedCourse?.id,timestamp:new Date().toISOString()}),ee("voice_guidance_modal_continue_clicked",{sessionId:this.selectedCourse?.id},"ShareMicModal"),await this.activeSession?.promptContinue(),this.showVoiceGuidanceModal=!1},this.handleVoiceGuidanceModalClose=()=>{console.log("[obi] voice guidance modal close",{sessionId:this.selectedCourse?.id}),this.handleCloseModals()},this.checkExistingSession=br(async()=>{ee("checking_existing_session",{},"ObiWidget");try{const e=JSON.parse(Ed.getItem(yd.SESSION_DATA)||"{}"),{sessionToken:t,roomToken:n,roomUrl:i,sessionExpiry:r,obiState:s}=e;if(!t||!n||!i){ee("no_existing_session_data",{},"ObiWidget");return}if(console.log("[obi-sdk] using existing session"),ee("existing_session_data_found",{sessionToken:t,hasExpiry:!!r,obiState:s},"ObiWidget"),r&&new Date(r)<new Date){this.clearSessionStorage(),ee("session_expired",{sessionToken:t},"ObiWidget");return}this.state=H.LOADING,Cr({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,ee("session_reconnected",{sessionToken:t,obiState:s},"ObiWidget")):(this.clearSessionStorage(),ee("session_reconnection_failed",{sessionToken:t},"ObiWidget"))}catch(e){console.error("Error reconnecting to session:",e),$e(e,{componentName:"ObiWidget",handlerName:"checkExistingSession"}),this.handleSessionCreationFailure(()=>this.clearSessionStorage())}},"checkExistingSession","ObiWidget");try{U0("ObiWidget").setContext(),this.obiClient=new Lf({baseUrl:Hc}),this.currentUrl=window.location.href;const t=()=>{try{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()}catch(n){$e(n,{componentName:"ObiWidget",handlerName:"handleUnload"})}};window.addEventListener("beforeunload",t),window.addEventListener("pagehide",t),ee("ObiWidget_constructor_completed",{},"ObiWidget")}catch(e){throw $e(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=H.LOADING,this.showCourseModal=!0,window.obiWidgetConfig.showMenu=!1)}else this.configLoaded||this.fetchDatabaseConfig()}generateColorVariables(e){try{this.primaryColor=e;const t=Mc(e,"#c4b5fd"),n=Mc(e,"#c76cff"),i=_w(e),r=Mc(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($f),window.history.replaceState({},"",e.toString()),localStorage.removeItem("obi-url-params")}createSession(e){try{const t=new pw({sessionId:e,apiBaseUrl:Hc,...this.user&&{user:this.user}});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===H.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!==H.READY&&(this.storedActiveState=i)},1500),this.storedActiveState=n;return}this.researchingTimeoutRef===null&&(this.state=n,n!==H.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=H.ERROR,this.activeSession=null,t&&t()}),e.on("micShareRequested",()=>{this.micShareEnabled=!0}),e.on("promptUser",()=>{this.voiceGuidanceEnabled=!0})}handleSessionCreationFailure(e){this.state=H.ERROR,this.activeSession=null,e&&e()}clearSessionStorage(){Ed.removeItem(yd.SESSION_DATA)}handleUrlChange(){this.requestUpdate(),Jo(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()};Ed.setItem(yd.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}),t[$f]}();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()}async handleConfigUpdate(e){const n=e.detail,i=n.isActive&&!this.isActive,r=this.user;if(this.updateFromConfig(),this.activeSession&&n.user!==void 0){const s=n.user;if(JSON.stringify(r)!==JSON.stringify(s))try{await this.activeSession.updateUser(s)}catch(o){console.error("Failed to update session user data:",o)}}i&&!Jo(this.urlBlacklist)&&!this.activeSession&&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=H.READY}handleItemSelect(e,t){if(e==="experiences"){this.showCourseModal=!0,this.showShareMicModal=!1;return}Vi([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||Es;this.primaryColor=r,this.style.setProperty("--obi-primary",r),this.generateColorVariables(r),this.isActive&&!Jo(this.urlBlacklist)&&!this.activeSession&&this.sessionConnectionCheck()}render(){if(!this.configLoaded||!this.isActive||this.linkOnlyAccess&&this.state===H.READY||Jo(this.urlBlacklist))return S.nothing;const e=Vi(this.state).with(H.LOADING,()=>S.html`<obi-dot-loader></obi-dot-loader>`).with(H.RESEARCHING,()=>S.html`<obi-searching-loader></obi-searching-loader>`).with(nw.union(H.USER_SPEAKING,H.AGENT_SPEAKING),()=>S.html`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`).with(H.THINKING,()=>S.html`<obi-dot-loader></obi-dot-loader>`).with(H.PAUSED,()=>Sd).otherwise(()=>Sd),t=this.state===H.USER_SPEAKING||this.state===H.AGENT_SPEAKING,n=this.state===H.PAUSED,i=this.state===H.RESEARCHING,r=this.state===H.USER_SPEAKING,s=this.state!==H.READY||this.navVisible,o=this.state!==H.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 S.html`
|
|
2545
2545
|
<div
|
|
2546
2546
|
class="${c}"
|
|
2547
2547
|
@mouseenter=${this.handleMouseEnter}
|
|
@@ -2558,6 +2558,7 @@ Url: ${$o(A)}`),!0}return!1}function yQ(A,e){return e?.length?zm(A).some(t=>Ro(t
|
|
|
2558
2558
|
></obi-navigation-bar>
|
|
2559
2559
|
`:S.nothing}
|
|
2560
2560
|
</div>
|
|
2561
|
+
|
|
2561
2562
|
${this.showCourseModal?S.html`<obi-course-modal
|
|
2562
2563
|
.onClose=${this.handleCloseModals.bind(this)}
|
|
2563
2564
|
.apiKey=${this.apiKey}
|