obi-sdk 0.4.1 → 0.4.2
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/{obi-widget-58dc98b0.js → obi-widget-2ba751b3.js} +49 -37
- package/dist/modular/chunks/obi-widget-2ba751b3.js.map +1 -0
- package/dist/modular/index.js +6 -6
- package/dist/modular/index.js.map +1 -1
- package/dist/modular/ui.js +10 -10
- package/dist/obi-sdk.es.js +53 -41
- package/dist/obi-sdk.es.js.map +1 -1
- package/dist/obi-sdk.standalone.iife.js +26 -26
- package/dist/obi-sdk.standalone.iife.js.map +1 -1
- package/dist/obi-sdk.umd.js +26 -26
- package/dist/obi-sdk.umd.js.map +1 -1
- package/dist/ui/components/session-start-modal/index.d.ts +1 -0
- package/dist/ui/components/{session-start-modal.d.ts → session-start-modal/session-start-modal.d.ts} +1 -1
- package/dist/ui/components/session-start-modal/session-start-modal.stories.d.ts +37 -0
- package/package.json +11 -4
- package/dist/modular/chunks/obi-widget-58dc98b0.js.map +0 -1
|
@@ -414,12 +414,13 @@
|
|
|
414
414
|
<p class="subtitle">${this.session.description}</p>
|
|
415
415
|
</div>
|
|
416
416
|
|
|
417
|
-
<button class="button button-primary" @click=${this.handleStart}>Continue
|
|
417
|
+
<button class="button button-primary" @click=${this.handleStart}>Continue</button>
|
|
418
418
|
</div>
|
|
419
419
|
`}}YQ.styles=Xf`
|
|
420
420
|
:host {
|
|
421
421
|
display: block;
|
|
422
422
|
font-family: "Inter", sans-serif;
|
|
423
|
+
box-sizing: border-box;
|
|
423
424
|
}
|
|
424
425
|
|
|
425
426
|
.backdrop {
|
|
@@ -433,18 +434,18 @@
|
|
|
433
434
|
}
|
|
434
435
|
|
|
435
436
|
.container {
|
|
437
|
+
box-sizing: border-box;
|
|
436
438
|
position: fixed;
|
|
437
439
|
top: 50%;
|
|
438
440
|
left: 50%;
|
|
439
441
|
transform: translate(-50%, -50%);
|
|
440
442
|
z-index: 50;
|
|
441
|
-
gap: 32px;
|
|
442
443
|
|
|
443
444
|
/* Layout from user specifications */
|
|
444
445
|
display: flex;
|
|
445
446
|
width: 640px;
|
|
446
447
|
min-height: 380px;
|
|
447
|
-
padding:
|
|
448
|
+
padding: 32px;
|
|
448
449
|
flex-direction: column;
|
|
449
450
|
justify-content: space-between;
|
|
450
451
|
align-items: center;
|
|
@@ -463,20 +464,17 @@
|
|
|
463
464
|
flex-direction: column;
|
|
464
465
|
align-items: center;
|
|
465
466
|
text-align: center;
|
|
466
|
-
gap: 16px;
|
|
467
467
|
}
|
|
468
468
|
|
|
469
469
|
.logo {
|
|
470
470
|
display: flex;
|
|
471
471
|
width: 96px;
|
|
472
472
|
height: 96px;
|
|
473
|
-
padding: 8px;
|
|
474
473
|
justify-content: center;
|
|
475
474
|
align-items: center;
|
|
476
|
-
gap: 8px;
|
|
477
475
|
aspect-ratio: 1/1;
|
|
478
|
-
border-radius:
|
|
479
|
-
background: var(--
|
|
476
|
+
border-radius: 8px;
|
|
477
|
+
background: var(--obi-primary, #a10fff);
|
|
480
478
|
box-shadow:
|
|
481
479
|
0px 0px 8px 0px rgba(168, 85, 247, 0.12),
|
|
482
480
|
0px 0px 8px 0px rgba(192, 132, 252, 0.24),
|
|
@@ -494,32 +492,36 @@
|
|
|
494
492
|
}
|
|
495
493
|
|
|
496
494
|
h1 {
|
|
497
|
-
font-family: "
|
|
495
|
+
font-family: "Satoshi", sans-serif;
|
|
498
496
|
font-size: 32px;
|
|
499
497
|
font-weight: 700;
|
|
500
498
|
color: #111827;
|
|
501
499
|
margin: 0;
|
|
500
|
+
margin-top: 32px;
|
|
501
|
+
margin-bottom: 16px;
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
.subtitle {
|
|
505
|
+
font-family: "Satoshi", sans-serif;
|
|
506
|
+
font-weight: 300;
|
|
505
507
|
font-size: 16px;
|
|
506
|
-
color: #
|
|
507
|
-
line-height: 1.
|
|
508
|
+
color: #18181b;
|
|
509
|
+
line-height: 1.4;
|
|
508
510
|
margin: 0;
|
|
509
511
|
}
|
|
510
512
|
|
|
511
513
|
.button {
|
|
514
|
+
font-family: "Satoshi", sans-serif;
|
|
515
|
+
font-weight: 400;
|
|
516
|
+
font-size: 16px;
|
|
512
517
|
padding: 12px 24px;
|
|
513
518
|
border-radius: 8px;
|
|
514
519
|
border: none;
|
|
515
|
-
font-size: 16px;
|
|
516
|
-
font-weight: 500;
|
|
517
520
|
cursor: pointer;
|
|
518
521
|
transition: all 0.2s ease;
|
|
519
522
|
display: flex;
|
|
520
523
|
align-items: center;
|
|
521
524
|
justify-content: center;
|
|
522
|
-
gap: 8px;
|
|
523
525
|
}
|
|
524
526
|
|
|
525
527
|
.button-primary {
|
|
@@ -543,23 +545,21 @@
|
|
|
543
545
|
|
|
544
546
|
.close-button {
|
|
545
547
|
position: absolute;
|
|
546
|
-
top:
|
|
548
|
+
top: 12px;
|
|
547
549
|
right: 16px;
|
|
548
550
|
background: none;
|
|
549
551
|
border: none;
|
|
550
552
|
cursor: pointer;
|
|
551
553
|
font-size: 24px;
|
|
552
554
|
color: #6b7280;
|
|
553
|
-
padding:
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
color: #374151;
|
|
560
|
-
background: #f3f4f6;
|
|
555
|
+
padding: 0;
|
|
556
|
+
margin: 0;
|
|
557
|
+
line-height: 1;
|
|
558
|
+
display: inline-flex;
|
|
559
|
+
align-items: center;
|
|
560
|
+
justify-content: center;
|
|
561
561
|
}
|
|
562
|
-
`,XQ([$g({type:Object})],YQ.prototype,"session",2),XQ([$g({type:Function})],YQ.prototype,"onStart",2),XQ([$g({type:Function})],YQ.prototype,"onClose",2),customElements.get("obi-session-start-modal")||customElements.define("obi-session-start-modal",YQ);var ZQ=Object.defineProperty,WQ=Object.getOwnPropertyDescriptor,qQ=(A,t,e,i)=>{for(var n,s=i>1?void 0:i?WQ(t,e):t,r=A.length-1;r>=0;r--)(n=A[r])&&(s=(i?n(t,e,s):n(s))||s);return i&&s&&ZQ(t,e,s),s};const $Q="io.obi.widget-parameters";class zQ extends Yg{constructor(){super(),this.apiKey="",this.isActive=!0,this.linkOnlyAccess=!1,this.position="bottom-right",this.user=null,this.state=Na.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.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.boundSaveSessionData=null,this.obiClient=null,this.closeNavTimeoutRef=null,this.researchingTimeoutRef=null,this.handleCourseSelectEvent=A=>{const t=A;this.selectedCourse=t.detail,this.showCourseModal=!1,this.showSessionStartModal=!0},this.handleUrlSessionEvent=async A=>{try{if(!this.obiClient)return;const t=await this.obiClient.listSessions(this.apiKey);if(t.data){const e=t.data.sessions,i=e?.find((t=>t.uuid===A));if(i){const t=i;this.selectedCourse={id:A,name:t.onboarding_plan?.name||"",description:t.onboarding_plan?.description||""},this.state=Na.LOADING,this.showSessionStartModal=!0}}}catch(t){}},this.obiClient=new h({baseUrl:t});const A=()=>{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()};window.addEventListener("beforeunload",A),window.addEventListener("pagehide",A)}updateFromConfig(){window.obiWidgetConfig&&(this.apiKey=window.obiWidgetConfig.apiKey||this.apiKey,this.position=window.obiWidgetConfig.position||this.position,this.user=window.obiWidgetConfig.user||this.user,void 0!==window.obiWidgetConfig.isActive&&(this.isActive=window.obiWidgetConfig.isActive),void 0!==window.obiWidgetConfig.linkOnlyAccess&&(this.linkOnlyAccess=window.obiWidgetConfig.linkOnlyAccess),this.style.setProperty("--obi-primary",window.obiWidgetConfig?.primaryColor||"#9500ff"),this.style.setProperty("--obi-secondary",window.obiWidgetConfig?.secondaryColor||"#c4b5fd"))}removeSessionUrlParams(){const A=new URL(window.location.href);A.searchParams.delete(Va),window.history.replaceState({},"",A.toString());try{localStorage.removeItem($Q)}catch(t){}}createSession(A){try{return new ja({sessionId:A,apiBaseUrl:t})||null}catch(e){return null}}setupSessionEventListeners(A,t){A.on("stateChanged",(t=>{if(t===Na.RESEARCHING)return this.researchingTimeoutRef&&window.clearTimeout(this.researchingTimeoutRef),this.state=t,this.researchingTimeoutRef=window.setTimeout((()=>{this.researchingTimeoutRef=null;const t=A.getCurrentState();this.state=t,t!==Na.READY&&(this.storedActiveState=t)}),1500),void(this.storedActiveState=t);null===this.researchingTimeoutRef&&(this.state=t,t!==Na.READY&&(this.storedActiveState=t))})),A.on("volume",(({speaker:A,spectrum:t,volume:e})=>{this.volume={speaker:A,spectrum:t,volume:e}})),A.on("error",(A=>{this.state=Na.ERROR,this.activeSession=null,t&&t()}))}handleSessionCreationFailure(A){this.state=Na.ERROR,this.activeSession=null,A&&A()}async connectObi(A){if(!this.activeSession)try{const t=this.createSession(A);if(!t)return void this.handleSessionCreationFailure((()=>this.removeSessionUrlParams()));this.setupSessionEventListeners(t,(()=>this.removeSessionUrlParams())),t.on("screenCaptureRequested",(async()=>{try{const e=(await(A=document.documentElement,t={useCORS:!0,allowTaint:!0,foreignObjectRendering:!0},void 0===t&&(t={}),(function(A,t){return Xa(void 0,void 0,void 0,(function(){var e,i,n,s,r,o,a,c,h,u,l,d,B,w,f,g,Q,v,p,m,U,C,F,y,b,E,H,I,k,T,S,K,O,D,M,L,R,x;return Ya(this,(function(N){switch(N.label){case 0:if(!A||"object"!=typeof A)return[2,Promise.reject("Invalid element provided as first argument")];if(!(e=A.ownerDocument))throw new Error("Element is not attached to a Document");if(!(i=e.defaultView))throw new Error("Document is not attached to a Window");return n={allowTaint:null!==(C=t.allowTaint)&&void 0!==C&&C,imageTimeout:null!==(F=t.imageTimeout)&&void 0!==F?F:15e3,proxy:t.proxy,useCORS:null!==(y=t.useCORS)&&void 0!==y&&y,customIsSameOrigin:t.customIsSameOrigin},s=Ja({logging:null===(b=t.logging)||void 0===b||b,cache:t.cache},n),r={windowWidth:null!==(E=t.windowWidth)&&void 0!==E?E:i.innerWidth,windowHeight:null!==(H=t.windowHeight)&&void 0!==H?H:i.innerHeight,scrollX:null!==(I=t.scrollX)&&void 0!==I?I:i.pageXOffset,scrollY:null!==(k=t.scrollY)&&void 0!==k?k:i.pageYOffset},o=new Za(r.scrollX,r.scrollY,r.windowWidth,r.windowHeight),a=new Gf(s,o),c=null!==(T=t.foreignObjectRendering)&&void 0!==T&&T,h={allowTaint:null!==(S=t.allowTaint)&&void 0!==S&&S,onclone:t.onclone,ignoreElements:t.ignoreElements,inlineImages:c,copyStyles:c},a.logger.debug("Starting document clone with size ".concat(o.width,"x").concat(o.height," scrolled to ").concat(-o.left,",").concat(-o.top)),u=new bw(a,A,h),(l=u.clonedReferenceElement)?[4,u.toIFrame(e,o)]:[2,Promise.reject("Unable to find element in cloned iframe")];case 1:return d=N.sent(),B=Aw(l)||"HTML"===l.tagName?(function(A){var t=A.body,e=A.documentElement;if(!t||!e)throw new Error("Unable to get document size");var i=Math.max(Math.max(t.scrollWidth,e.scrollWidth),Math.max(t.offsetWidth,e.offsetWidth),Math.max(t.clientWidth,e.clientWidth)),n=Math.max(Math.max(t.scrollHeight,e.scrollHeight),Math.max(t.offsetHeight,e.offsetHeight),Math.max(t.clientHeight,e.clientHeight));return new Za(0,0,i,n)})(l.ownerDocument):Wa(a,l),w=B.width,f=B.height,g=B.left,Q=B.top,v=(function(A,t,e){var i=t.ownerDocument,n=i.documentElement?Vu(A,getComputedStyle(i.documentElement).backgroundColor):Pu.TRANSPARENT,s=i.body?Vu(A,getComputedStyle(i.body).backgroundColor):Pu.TRANSPARENT,r="string"==typeof e?Vu(A,e):null===e?Pu.TRANSPARENT:4294967295;return t===i.documentElement?ou(n)?ou(s)?r:s:n:r})(a,l,t.backgroundColor),p={canvas:t.canvas,backgroundColor:v,scale:null!==(O=null!==(K=t.scale)&&void 0!==K?K:i.devicePixelRatio)&&void 0!==O?O:1,x:(null!==(D=t.x)&&void 0!==D?D:0)+g,y:(null!==(M=t.y)&&void 0!==M?M:0)+Q,width:null!==(L=t.width)&&void 0!==L?L:Math.ceil(w),height:null!==(R=t.height)&&void 0!==R?R:Math.ceil(f)},c?(a.logger.debug("Document cloned, using foreign object rendering"),[4,new Rf(a,p).render(l)]):[3,3];case 2:return m=N.sent(),[3,5];case 3:return a.logger.debug("Document cloned, element located at ".concat(g,",").concat(Q," with size ").concat(w,"x").concat(f," using computed rendering")),a.logger.debug("Starting DOM parsing"),U=VB(a,l),v===U.styles.backgroundColor&&(U.styles.backgroundColor=Pu.TRANSPARENT),a.logger.debug("Starting renderer for element at ".concat(p.x,",").concat(p.y," with size ").concat(p.width,"x").concat(p.height)),[4,new Sf(a,p).render(U)];case 4:m=N.sent(),N.label=5;case 5:return(null===(x=t.removeContainer)||void 0===x||x)&&(bw.destroy(d)||a.logger.error("Cannot detach cloned iframe as it is not in the DOM anymore")),a.logger.debug("Finished rendering"),[2,m]}}))}))})(A,t))).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",e)}catch(e){this.activeSession.emit("screenCaptureComplete","error")}var A,t}));const e=await t.connect();e&&(this.sessionToken=A,this.roomToken=e.token,this.roomUrl=e.url,this.removeSessionUrlParams()),this.activeSession=t}catch(t){this.handleSessionCreationFailure((()=>this.removeSessionUrlParams()))}}async handleSessionStart(A){this.activeSession||(this.showSessionStartModal=!1,this.state=Na.LOADING,await this.connectObi(A))}async checkExistingSession(){try{const A=JSON.parse(tQ.getItem(AQ)||"{}"),{sessionToken:t,roomToken:e,roomUrl:i,sessionExpiry:n,obiState:s}=A;if(!t||!e||!i)return;if(n&&new Date(n)<new Date)return void this.clearSessionStorage();this.state=Na.LOADING;const r=this.createSession(t);if(!r)return void this.handleSessionCreationFailure((()=>this.clearSessionStorage()));this.setupSessionEventListeners(r,(()=>this.clearSessionStorage())),await r.reconnect(i,e,s)?(this.activeSession=r,this.sessionToken=t,this.roomToken=e,this.roomUrl=i,this.state=s,this.storedActiveState=s):this.clearSessionStorage()}catch(A){this.handleSessionCreationFailure((()=>this.clearSessionStorage()))}}clearSessionStorage(){tQ.removeItem(AQ)}saveSessionData(){if(this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl){const A=new Date;A.setMinutes(A.getMinutes()+5);const t={sessionToken:this.sessionToken,roomToken:this.roomToken,roomUrl:this.roomUrl,obiState:this.storedActiveState??this.state,sessionExpiry:A.toISOString()};tQ.setItem(AQ,JSON.stringify(t))}}async sessionConnectionCheck(){if(await this.checkExistingSession(),!this.activeSession){let t={};try{const A=localStorage.getItem($Q);A&&(t=JSON.parse(A))}catch(A){}0===Object.keys(t).length&&new URLSearchParams(window.location.search).forEach(((A,e)=>{t[e]=A}));const e=t[Va];e&&this.apiKey&&await this.handleUrlSessionEvent(e)}}connectedCallback(){super.connectedCallback(),this.updateFromConfig(),this.setAttribute("position",this.position),this.boundSaveSessionData=this.saveSessionData.bind(this),window.addEventListener("beforeunload",this.boundSaveSessionData),window.addEventListener("pagehide",this.boundSaveSessionData),this.sessionConnectionCheck()}disconnectedCallback(){null!==this.closeNavTimeoutRef&&window.clearTimeout(this.closeNavTimeoutRef),null!==this.researchingTimeoutRef&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.boundSaveSessionData&&(window.removeEventListener("beforeunload",this.boundSaveSessionData),window.removeEventListener("pagehide",this.boundSaveSessionData)),this.removeSessionUrlParams(),super.disconnectedCallback()}handleMouseEnter(){this.isHovering=!0,this.navVisible=!0}handleMouseLeave(){this.isHovering=!1,null!==this.closeNavTimeoutRef&&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,null!==this.researchingTimeoutRef&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=Na.READY}handleItemSelect(A,t){"experiences"!==A?La([A,t]).with(["pause",!0],(()=>{this.activeSession?.pauseRecording()})).with(["pause",!1],(()=>{this.activeSession?.resumeRecording()})).with(["activate",!1],(()=>{this.terminateSession()})).otherwise((()=>{})):this.showCourseModal=!0}render(){if(!this.isActive)return Kg;if(this.linkOnlyAccess&&this.state===Na.READY)return Kg;const A=La(this.state).with(Na.LOADING,(()=>kg`<obi-dot-loader></obi-dot-loader>`)).with(Na.RESEARCHING,(()=>kg`<obi-searching-loader></obi-searching-loader>`)).with(Oa.union(Na.USER_SPEAKING,Na.AGENT_SPEAKING),(()=>kg`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`)).with(Na.THINKING,(()=>kg`<obi-dot-loader></obi-dot-loader>`)).with(Na.PAUSED,(()=>lQ)).otherwise((()=>lQ)),t=this.state===Na.USER_SPEAKING||this.state===Na.AGENT_SPEAKING,e=this.state===Na.RESEARCHING,i=this.state===Na.USER_SPEAKING,n=["widget-container",this.state!==Na.READY||this.navVisible?"rotated":"",t?"pulse":"",e?"researching":"",i?"user-speaking":""].filter(Boolean).join(" ");return kg`
|
|
562
|
+
`,XQ([$g({type:Object})],YQ.prototype,"session",2),XQ([$g({type:Function})],YQ.prototype,"onStart",2),XQ([$g({type:Function})],YQ.prototype,"onClose",2),customElements.get("obi-session-start-modal")||customElements.define("obi-session-start-modal",YQ);var ZQ=Object.defineProperty,WQ=Object.getOwnPropertyDescriptor,qQ=(A,t,e,i)=>{for(var n,s=i>1?void 0:i?WQ(t,e):t,r=A.length-1;r>=0;r--)(n=A[r])&&(s=(i?n(t,e,s):n(s))||s);return i&&s&&ZQ(t,e,s),s};class $Q extends Yg{constructor(){super(),this.apiKey="",this.isActive=!0,this.linkOnlyAccess=!1,this.position="bottom-right",this.user=null,this.state=Na.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.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.boundSaveSessionData=null,this.obiClient=null,this.closeNavTimeoutRef=null,this.researchingTimeoutRef=null,this.handleCourseSelectEvent=A=>{const t=A;this.selectedCourse=t.detail,this.showCourseModal=!1,this.showSessionStartModal=!0},this.handleUrlSessionEvent=async A=>{try{if(!this.obiClient)return;const t=await this.obiClient.listSessions(this.apiKey);if(t.data){const e=t.data.sessions,i=e?.find((t=>t.uuid===A));if(i){const t=i;this.selectedCourse={id:A,name:t.onboarding_plan?.name||"",description:t.onboarding_plan?.description||""},this.state=Na.LOADING,this.showSessionStartModal=!0}}}catch(t){}},this.obiClient=new h({baseUrl:t});const A=()=>{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()};window.addEventListener("beforeunload",A),window.addEventListener("pagehide",A)}updateFromConfig(){window.obiWidgetConfig&&(this.apiKey=window.obiWidgetConfig.apiKey||this.apiKey,this.position=window.obiWidgetConfig.position||this.position,this.user=window.obiWidgetConfig.user||this.user,void 0!==window.obiWidgetConfig.isActive&&(this.isActive=window.obiWidgetConfig.isActive),void 0!==window.obiWidgetConfig.linkOnlyAccess&&(this.linkOnlyAccess=window.obiWidgetConfig.linkOnlyAccess),this.style.setProperty("--obi-primary",window.obiWidgetConfig?.primaryColor||"#9500ff"),this.style.setProperty("--obi-secondary",window.obiWidgetConfig?.secondaryColor||"#c4b5fd"))}removeSessionUrlParams(){const A=new URL(window.location.href);A.searchParams.delete(Va),window.history.replaceState({},"",A.toString());try{window.__obiUrlParams&&(window.__obiUrlParams=null)}catch(t){}}createSession(A){try{return new ja({sessionId:A,apiBaseUrl:t})||null}catch(e){return null}}setupSessionEventListeners(A,t){A.on("stateChanged",(t=>{if(t===Na.RESEARCHING)return this.researchingTimeoutRef&&window.clearTimeout(this.researchingTimeoutRef),this.state=t,this.researchingTimeoutRef=window.setTimeout((()=>{this.researchingTimeoutRef=null;const t=A.getCurrentState();this.state=t,t!==Na.READY&&(this.storedActiveState=t)}),1500),void(this.storedActiveState=t);null===this.researchingTimeoutRef&&(this.state=t,t!==Na.READY&&(this.storedActiveState=t))})),A.on("volume",(({speaker:A,spectrum:t,volume:e})=>{this.volume={speaker:A,spectrum:t,volume:e}})),A.on("error",(A=>{this.state=Na.ERROR,this.activeSession=null,t&&t()}))}handleSessionCreationFailure(A){this.state=Na.ERROR,this.activeSession=null,A&&A()}async connectObi(A){if(!this.activeSession)try{const t=this.createSession(A);if(!t)return void this.handleSessionCreationFailure((()=>this.removeSessionUrlParams()));this.setupSessionEventListeners(t,(()=>this.removeSessionUrlParams())),t.on("screenCaptureRequested",(async()=>{try{const e=(await(A=document.documentElement,t={useCORS:!0,allowTaint:!0,foreignObjectRendering:!0},void 0===t&&(t={}),(function(A,t){return Xa(void 0,void 0,void 0,(function(){var e,i,n,s,r,o,a,c,h,u,l,d,B,w,f,g,Q,v,p,m,U,C,F,y,b,E,H,I,k,T,S,K,O,D,M,L,R,x;return Ya(this,(function(N){switch(N.label){case 0:if(!A||"object"!=typeof A)return[2,Promise.reject("Invalid element provided as first argument")];if(!(e=A.ownerDocument))throw new Error("Element is not attached to a Document");if(!(i=e.defaultView))throw new Error("Document is not attached to a Window");return n={allowTaint:null!==(C=t.allowTaint)&&void 0!==C&&C,imageTimeout:null!==(F=t.imageTimeout)&&void 0!==F?F:15e3,proxy:t.proxy,useCORS:null!==(y=t.useCORS)&&void 0!==y&&y,customIsSameOrigin:t.customIsSameOrigin},s=Ja({logging:null===(b=t.logging)||void 0===b||b,cache:t.cache},n),r={windowWidth:null!==(E=t.windowWidth)&&void 0!==E?E:i.innerWidth,windowHeight:null!==(H=t.windowHeight)&&void 0!==H?H:i.innerHeight,scrollX:null!==(I=t.scrollX)&&void 0!==I?I:i.pageXOffset,scrollY:null!==(k=t.scrollY)&&void 0!==k?k:i.pageYOffset},o=new Za(r.scrollX,r.scrollY,r.windowWidth,r.windowHeight),a=new Gf(s,o),c=null!==(T=t.foreignObjectRendering)&&void 0!==T&&T,h={allowTaint:null!==(S=t.allowTaint)&&void 0!==S&&S,onclone:t.onclone,ignoreElements:t.ignoreElements,inlineImages:c,copyStyles:c},a.logger.debug("Starting document clone with size ".concat(o.width,"x").concat(o.height," scrolled to ").concat(-o.left,",").concat(-o.top)),u=new bw(a,A,h),(l=u.clonedReferenceElement)?[4,u.toIFrame(e,o)]:[2,Promise.reject("Unable to find element in cloned iframe")];case 1:return d=N.sent(),B=Aw(l)||"HTML"===l.tagName?(function(A){var t=A.body,e=A.documentElement;if(!t||!e)throw new Error("Unable to get document size");var i=Math.max(Math.max(t.scrollWidth,e.scrollWidth),Math.max(t.offsetWidth,e.offsetWidth),Math.max(t.clientWidth,e.clientWidth)),n=Math.max(Math.max(t.scrollHeight,e.scrollHeight),Math.max(t.offsetHeight,e.offsetHeight),Math.max(t.clientHeight,e.clientHeight));return new Za(0,0,i,n)})(l.ownerDocument):Wa(a,l),w=B.width,f=B.height,g=B.left,Q=B.top,v=(function(A,t,e){var i=t.ownerDocument,n=i.documentElement?Vu(A,getComputedStyle(i.documentElement).backgroundColor):Pu.TRANSPARENT,s=i.body?Vu(A,getComputedStyle(i.body).backgroundColor):Pu.TRANSPARENT,r="string"==typeof e?Vu(A,e):null===e?Pu.TRANSPARENT:4294967295;return t===i.documentElement?ou(n)?ou(s)?r:s:n:r})(a,l,t.backgroundColor),p={canvas:t.canvas,backgroundColor:v,scale:null!==(O=null!==(K=t.scale)&&void 0!==K?K:i.devicePixelRatio)&&void 0!==O?O:1,x:(null!==(D=t.x)&&void 0!==D?D:0)+g,y:(null!==(M=t.y)&&void 0!==M?M:0)+Q,width:null!==(L=t.width)&&void 0!==L?L:Math.ceil(w),height:null!==(R=t.height)&&void 0!==R?R:Math.ceil(f)},c?(a.logger.debug("Document cloned, using foreign object rendering"),[4,new Rf(a,p).render(l)]):[3,3];case 2:return m=N.sent(),[3,5];case 3:return a.logger.debug("Document cloned, element located at ".concat(g,",").concat(Q," with size ").concat(w,"x").concat(f," using computed rendering")),a.logger.debug("Starting DOM parsing"),U=VB(a,l),v===U.styles.backgroundColor&&(U.styles.backgroundColor=Pu.TRANSPARENT),a.logger.debug("Starting renderer for element at ".concat(p.x,",").concat(p.y," with size ").concat(p.width,"x").concat(p.height)),[4,new Sf(a,p).render(U)];case 4:m=N.sent(),N.label=5;case 5:return(null===(x=t.removeContainer)||void 0===x||x)&&(bw.destroy(d)||a.logger.error("Cannot detach cloned iframe as it is not in the DOM anymore")),a.logger.debug("Finished rendering"),[2,m]}}))}))})(A,t))).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",e)}catch(e){this.activeSession.emit("screenCaptureComplete","error")}var A,t}));const e=await t.connect();e&&(this.sessionToken=A,this.roomToken=e.token,this.roomUrl=e.url,this.removeSessionUrlParams()),this.activeSession=t}catch(t){this.handleSessionCreationFailure((()=>this.removeSessionUrlParams()))}}async handleSessionStart(A){this.activeSession||(this.showSessionStartModal=!1,this.state=Na.LOADING,await this.connectObi(A))}async checkExistingSession(){try{const A=JSON.parse(tQ.getItem(AQ)||"{}"),{sessionToken:t,roomToken:e,roomUrl:i,sessionExpiry:n,obiState:s}=A;if(!t||!e||!i)return;if(n&&new Date(n)<new Date)return void this.clearSessionStorage();this.state=Na.LOADING;const r=this.createSession(t);if(!r)return void this.handleSessionCreationFailure((()=>this.clearSessionStorage()));this.setupSessionEventListeners(r,(()=>this.clearSessionStorage())),await r.reconnect(i,e,s)?(this.activeSession=r,this.sessionToken=t,this.roomToken=e,this.roomUrl=i,this.state=s,this.storedActiveState=s):this.clearSessionStorage()}catch(A){this.handleSessionCreationFailure((()=>this.clearSessionStorage()))}}clearSessionStorage(){tQ.removeItem(AQ)}saveSessionData(){if(this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl){const A=new Date;A.setMinutes(A.getMinutes()+5);const t={sessionToken:this.sessionToken,roomToken:this.roomToken,roomUrl:this.roomUrl,obiState:this.storedActiveState??this.state,sessionExpiry:A.toISOString()};tQ.setItem(AQ,JSON.stringify(t))}}async sessionConnectionCheck(){if(await this.checkExistingSession(),!this.activeSession){let A={};window.__obiUrlParams&&(A=window.__obiUrlParams),0===Object.keys(A).length&&new URLSearchParams(window.location.search).forEach(((t,e)=>{A[e]=t}));const t=A[Va];t&&this.apiKey?await this.handleUrlSessionEvent(t):t&&!this.apiKey&&setTimeout((()=>{this.apiKey&&this.handleUrlSessionEvent(t)}),100)}}connectedCallback(){super.connectedCallback(),this.updateFromConfig(),this.setAttribute("position",this.position),this.boundSaveSessionData=this.saveSessionData.bind(this),window.addEventListener("beforeunload",this.boundSaveSessionData),window.addEventListener("pagehide",this.boundSaveSessionData),"complete"===document.readyState?Promise.resolve().then((()=>this.sessionConnectionCheck())):window.addEventListener("load",(()=>{Promise.resolve().then((()=>this.sessionConnectionCheck()))}),{once:!0})}disconnectedCallback(){null!==this.closeNavTimeoutRef&&window.clearTimeout(this.closeNavTimeoutRef),null!==this.researchingTimeoutRef&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.boundSaveSessionData&&(window.removeEventListener("beforeunload",this.boundSaveSessionData),window.removeEventListener("pagehide",this.boundSaveSessionData)),this.removeSessionUrlParams(),super.disconnectedCallback()}handleMouseEnter(){this.isHovering=!0,this.navVisible=!0}handleMouseLeave(){this.isHovering=!1,null!==this.closeNavTimeoutRef&&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,null!==this.researchingTimeoutRef&&(window.clearTimeout(this.researchingTimeoutRef),this.researchingTimeoutRef=null),this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=Na.READY}handleItemSelect(A,t){"experiences"!==A?La([A,t]).with(["pause",!0],(()=>{this.activeSession?.pauseRecording()})).with(["pause",!1],(()=>{this.activeSession?.resumeRecording()})).with(["activate",!1],(()=>{this.terminateSession()})).otherwise((()=>{})):this.showCourseModal=!0}render(){if(!this.isActive)return Kg;if(this.linkOnlyAccess&&this.state===Na.READY)return Kg;const A=La(this.state).with(Na.LOADING,(()=>kg`<obi-dot-loader></obi-dot-loader>`)).with(Na.RESEARCHING,(()=>kg`<obi-searching-loader></obi-searching-loader>`)).with(Oa.union(Na.USER_SPEAKING,Na.AGENT_SPEAKING),(()=>kg`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`)).with(Na.THINKING,(()=>kg`<obi-dot-loader></obi-dot-loader>`)).with(Na.PAUSED,(()=>lQ)).otherwise((()=>lQ)),t=this.state===Na.USER_SPEAKING||this.state===Na.AGENT_SPEAKING,e=this.state===Na.RESEARCHING,i=this.state===Na.USER_SPEAKING,n=["widget-container",this.state!==Na.READY||this.navVisible?"rotated":"",t?"pulse":"",e?"researching":"",i?"user-speaking":""].filter(Boolean).join(" ");return kg`
|
|
563
563
|
<div
|
|
564
564
|
class="${n}"
|
|
565
565
|
@mouseenter=${this.handleMouseEnter}
|
|
@@ -586,7 +586,7 @@
|
|
|
586
586
|
.onStart=${this.handleSessionStart.bind(this)}
|
|
587
587
|
.onClose=${()=>{this.showSessionStartModal=!1,this.selectedCourse=null,this.state=Na.READY,this.removeSessionUrlParams()}}
|
|
588
588
|
></obi-session-start-modal>`:Kg}
|
|
589
|
-
`}}function
|
|
589
|
+
`}}function zQ(A){return new Promise((t=>setTimeout(t,A)))}function Av(A){const t=200*Math.pow(2,A);return Math.min(t,2e3)}async function tv(A,t,e=3){let i=null;for(let s=0;s<e;s++)try{return await A()}catch(n){if(i=n,s<e-1){const A=Av(s);await zQ(A)}}throw new Error(`${t} failed after ${e} attempts: ${i?.message}`)}function ev(){const A=window;"function"!=typeof A.ObiSDK&&"object"!=typeof A.ObiSDK&&(A.ObiSDK=function(t,e){"update"===t&&e&&(A.obiWidgetConfig={...A.obiWidgetConfig,...e})},A.ObiSDK.q=[])}function iv(){const A=window;A.ObiSDK&&Array.isArray(A.ObiSDK.q)&&(A.ObiSDK.q.forEach((t=>{const[e,i]=t;"update"===e&&i&&(A.obiWidgetConfig={...A.obiWidgetConfig,...i})})),A.ObiSDK.q=[])}async function nv(A){return tv((async()=>{if(!document.head)throw new Error("document.head not available");const t=document.createElement("link");return document.head.querySelectorAll("link[data-obi-font]").forEach((A=>A.remove())),t.setAttribute("data-obi-font","true"),t.href=A,t.rel="stylesheet",new Promise(((A,e)=>{const i=setTimeout((()=>{e(new Error("Font loading timeout"))}),5e3);t.onload=()=>{clearTimeout(i),A()},t.onerror=()=>{clearTimeout(i),e(new Error("Font loading failed"))},document.head.appendChild(t)}))}),"Font loading")}async function sv(){try{ev(),await(async function(){await nv("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap"),await nv("https://fonts.cdnfonts.com/css/satoshi")})(),await(async function(){return tv((async()=>{if(document.querySelector("obi-widget"))return;if(!document.body)throw new Error("document.body not available");const A=document.createElement("obi-widget");document.body.appendChild(A)}),"Widget mounting")})(),iv()}catch(A){try{ev(),iv()}catch(t){}}}$Q.styles=Xf`
|
|
590
590
|
:host {
|
|
591
591
|
display: block;
|
|
592
592
|
position: fixed;
|
|
@@ -708,4 +708,4 @@
|
|
|
708
708
|
.pulse {
|
|
709
709
|
animation: pulse-shadow 2s ease-in-out infinite;
|
|
710
710
|
}
|
|
711
|
-
`,qQ([zg()]
|
|
711
|
+
`,qQ([zg()],$Q.prototype,"apiKey",2),qQ([zg()],$Q.prototype,"isActive",2),qQ([zg()],$Q.prototype,"linkOnlyAccess",2),qQ([zg()],$Q.prototype,"position",2),qQ([zg()],$Q.prototype,"user",2),qQ([zg()],$Q.prototype,"state",2),qQ([zg()],$Q.prototype,"storedActiveState",2),qQ([zg()],$Q.prototype,"showCourseModal",2),qQ([zg()],$Q.prototype,"showSessionStartModal",2),qQ([zg()],$Q.prototype,"selectedCourse",2),qQ([zg()],$Q.prototype,"isHovering",2),qQ([zg()],$Q.prototype,"navVisible",2),qQ([zg()],$Q.prototype,"activeSession",2),qQ([zg()],$Q.prototype,"volume",2),customElements.get("obi-widget")||customElements.define("obi-widget",$Q),customElements.get("obi-widget")||customElements.define("obi-widget",$Q),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{sv()})):sv(),A.ObiWidget=$Q,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})})({});//# sourceMappingURL=obi-sdk.standalone.iife.js.map
|