1"use strict";(self.webpackChunklanding_v3=self.webpackChunklanding_v3||[]).push([[7989],{27599(e,t,i){i.d(t,{h:()=>o});var s,n=i(9950);const a=["title","titleId"];function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var s in i)({}).hasOwnProperty.call(i,s)&&(e[s]=i[s])}return e},r.apply(null,arguments)}function l(e,t){let i=e.title,l=e.titleId,o=function(e,t){if(null==e)return{};var i,s,n=function(e,t){if(null==e)return{};var i={};for(var s in e)if({}.hasOwnProperty.call(e,s)){if(-1!==t.indexOf(s))continue;i[s]=e[s]}return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(s=0;s<a.length;s++)i=a[s],-1===t.indexOf(i)&&{}.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}(e,a);return n.createElement("svg",r({viewBox:"0 0 6.5 11.15",fill:"none",xmlns:"http://www.w3.org/2000/svg",ref:t,"aria-labelledby":l},o),i?n.createElement("title",{id:l},i):null,s||(s=n.createElement("path",{d:"M6.5 5.57498C6.5 5.69914 6.47517 5.8171 6.4255 5.92884C6.37997 6.03645 6.30548 6.13992 6.20201 6.23925L1.42789 10.914C1.26648 11.0713 1.06988 11.15 0.838109 11.15C0.689112 11.15 0.550462 11.1127 0.422159 11.0382C0.293855 10.9637 0.190385 10.8644 0.111748 10.7402C0.0372493 10.616 0 10.4753 0 10.318C0 10.0904 0.086915 9.88761 0.260745 9.70965L4.51337 5.57498L0.260745 1.44031C0.086915 1.26648 0 1.06367 0 0.831901C0 0.678765 0.0372493 0.540115 0.111748 0.41595C0.190385 0.287647 0.293855 0.186246 0.422159 0.111748C0.550462 0.0372493 0.689112 0 0.838109 0C1.06988 0 1.26648 0.0786374 1.42789 0.235912L6.20201 4.9107C6.30134 5.01003 6.37584 5.1135 6.4255 5.22111C6.47517 5.32872 6.5 5.44667 6.5 5.57498Z",fill:"#ffffff",fillOpacity:.2})))}const o=n.forwardRef(l);i.p},42086(e,t,i){i.d(t,{v:()=>s});const s=new class{constructor(){this.cache=new Map,this.CACHE_EXPIRY=864e5}generateKey(e){let t=e.botId,i=e.text,s=e.voiceStrapiId;return"".concat(t,"_").concat(s,"_").concat(i)}isExpired(e){return Date.now()-e.timestamp>this.CACHE_EXPIRY}cleanup(){this.cache.forEach((e,t)=>{this.isExpired(e)&&(URL.revokeObjectURL(e.audioUrl),this.cache.delete(t))})}get(e){let t=e.botId,i=e.text,s=e.voiceStrapiId;this.cleanup();const n=this.generateKey({botId:t,text:i,voiceStrapiId:s}),a=this.cache.get(n);return a&&!this.isExpired(a)?a:(a&&(URL.revokeObjectURL(a.audioUrl),this.cache.delete(n)),null)}set(e,t){let i=e.botId,s=e.text,n=e.voiceStrapiId;this.cleanup();const a=this.generateKey({botId:i,text:s,voiceStrapiId:n}),r=this.cache.get(a);r&&URL.revokeObjectURL(r.audioUrl);const l={audioBlob:t,audioUrl:URL.createObjectURL(t),timestamp:Date.now()};return this.cache.set(a,l),l}clear(){this.cache.forEach(e=>{URL.revokeObjectURL(e.audioUrl)}),this.cache.clear()}getSize(){return this.cache.size}}},75865(e,t,i){i.d(t,{p:()=>d,u:()=>c});var s=i(42086),n=i(78003);const a=e=>{const t=e.reduce((e,t)=>e+t.length,0),i=new Uint8Array(t);let s=0;for(const n of e)i.set(n,s),s+=n.length;return i},r=e=>!n.nr&&!n.un&&(()=>{try{return"undefined"!==typeof MediaSource&&"function"===typeof MediaSource.isTypeSupported&&MediaSource.isTypeSupported("audio/mpeg")}catch(e){return!1}})()&&!!e.body&&"function"===typeof e.body.getReader,l=(e,t)=>new Promise(i=>{const s=()=>{e.appendBuffer(t);const s=()=>{e.removeEventListener("updateend",s),i()};e.addEventListener("updateend",s)};if(!e.updating)return void s();const n=()=>{e.removeEventListener("updateend",n),s()};e.addEventListener("updateend",n)}),o=async e=>{const t=await e.arrayBuffer();return t.byteLength?new Blob([t],{type:"audio/mpeg"}):null},c=async(e,t,i)=>{const n=s.v.get(t);if(n)return n.audioBlob;const a=await e(i);if(!a.ok)return null;const r=await o(a);return r?(s.v.set(t,r),r):null},d=async e=>{let t=e.audio,i=e.fetchSpeech,n=e.cacheKey,c=e.play,d=e.signal,u=e.onCommitted,h=e.onPlaybackStarted;const p=async(e,i)=>{t.pause(),t.src=null!==i&&void 0!==i?i:URL.createObjectURL(e),t.load(),await(null===u||void 0===u?void 0:u()),await c(t),null===h||void 0===h||h()},m=async e=>{const t=await o(e);if(!t)throw new Error("Empty audio response");s.v.set(n,t),await p(t)},g=s.v.get(n);if(g)return void await p(g.audioBlob,g.audioUrl);const v=await i(d);if(!v.ok)throw new Error("Failed to generate audio");if(!r(v))return void await m(v);t.pause();const y=new MediaSource;t.src=URL.createObjectURL(y);const S=[];let b=!1,f=!1;try{await new Promise((e,i)=>{y.addEventListener("sourceopen",async()=>{try{var s;const n=y.addSourceBuffer("audio/mpeg"),a=null===(s=v.body)||void 0===s?void 0:s.getReader();if(!a)return void i(new Error("No reader available"));for(;;){const e=await a.read(),i=e.done,s=e.value;if(i)break;S.push(s),await l(n,s),f||(await c(t),f=!0,null===h||void 0===h||h())}y.endOfStream(),b=!0,e()}catch(n){i(n)}}),y.addEventListener("error",e=>{i(new Error("MediaSource error: ".concat(e)))})})}catch(_){if(f||null!==d&&void 0!==d&&d.aborted)throw _;const e=await i(d);if(!e.ok)throw _;return void await m(e)}await(null===u||void 0===u?void 0:u()),b&&S.length>0&&s.v.set(n,new Blob([a(S)],{type:"audio/mpeg"}))}},89438(e,t,i){i.d(t,{w:()=>y});var s=i(48738),n=i.n(s),a=i(27599),r=i(49718),l=i(48956);const o="CustomStreamBanner_banner__4kN1+",c="CustomStreamBanner_icon__mOpzw",d="CustomStreamBanner_texts__OVZJI",u="CustomStreamBanner_title__G9Q8h",h="CustomStreamBanner_subtitle__e1rHq",p="CustomStreamBanner_chevron__17ktm",m="CustomStreamBanner_close__sQmlZ",g="CustomStreamBanner_closeIcon__26cCN";var v=i(44414);const y=e=>{let t=e.onOpen,i=e.onClose,s=e.className;return(0,v.jsxs)("div",{className:n()(o,"chat-promo-banner",s),role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),t()},onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),t())},"data-testid":"custom-stream-banner",children:[(0,v.jsx)("img",{className:c,src:l,alt:""}),(0,v.jsxs)("span",{className:d,children:[(0,v.jsx)("span",{className:u,children:"Generate a live stream"}),(0,v.jsx)("span",{className:h,children:"with your custom bot"})]}),(0,v.jsx)(a.h,{className:p}),(0,v.jsx)("button",{type:"button",className:m,onClick:e=>{e.stopPropagation(),i()},"aria-label":"Hide banner",children:(0,v.jsx)(r.h,{className:g})})]})}}
1,77989(e,t,i){i.d(t,{VideoStreamingPage:()=>lt});var s=i(9950),n=i(28429),a=i(79600),r=i(11531),l=i(8130),o=i(19472),c=i(65861),d=i(4471);const u=(0,c.g)({key:"live_stream_tip_suggestions",variants:["control","enabled"],forceVariant:void 0}),h=()=>(0,d.NL)();var p=i(17858);const m="live_stream_monetization_type",g=["default","per_message"],v=(0,c.g)({key:m,variants:g,forceVariant:void 0}),y="experiment-override:".concat(m),S=()=>{const e=(()=>{if(!(0,p.p2)())return null;try{var e;const t=localStorage.getItem(y);return null!==(e=g.find(e=>e===t))&&void 0!==e?e:null}catch(t){return null}})(),t=(0,o.z)(v,"default",null!==e);return null!==e?{monetizationType:e,isResolved:!0}:{monetizationType:t.variant,isResolved:!t.isLoading}};var b=i(51096),f=i(89379),_=i(5544);class T{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"emma",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:()=>performance.now(),s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:!document.hidden;this.streamVisitId=e,this.streamId=t,this.now=i,this.openedAt=void 0,this.activeStartedAt=null,this.activeMs=0,this.started=!1,this.visible=void 0,this.ended=!1,this.messages=0,this.committedPlaybacks=0,this.tips=0,this.states=0,this.reconnects=0,this.terminalReason=null,this.openedAt=this.now(),this.visible=s}startTapped(e,t){this.ended||l._w.videoStreamStartTapped((0,f.A)((0,f.A)({},this.baseParams()),{},{billing_mode:e,action:t}))}playbackStarted(){this.ended||(this.started||(this.started=!0,l._w.videoStreamStarted(this.baseParams())),this.startActiveTime())}messageSent(e){this.ended||(this.messages+=1,l._w.videoStreamMessageSent((0,f.A)((0,f.A)({},this.baseParams()),{},{source:e})))}continueButtonTapped(){this.ended||l._w.videoStreamContinueButtonTapped(this.baseParams())}soundToggled(e){this.ended||l._w.videoStreamSoundToggled((0,f.A)((0,f.A)({},this.baseParams()),{},{sound_enabled:e}))}suggestionTapped(){this.ended||l._w.videoStreamSuggestionTapped(this.baseParams())}playbackCommitted(e,t,i,s){this.ended||(this.committedPlaybacks+=1,l._w.videoStreamPlaybackCommitted((0,f.A)((0,f.A)({},this.baseParams()),{},{tip_name:e,choice_name:t,state:i,clip_count:s})))}sendTipButtonTapped(e,t){this.ended||l._w.videoStreamSendTipButtonTapped((0,f.A)((0,f.A)({},this.baseParams()),{},{state:e,was_animated:t}))}tipTapped(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];this.ended||l._w.videoStreamTipTapped((0,f.A)((0,f.A)({},this.baseParams()),{},{tip_name:e,energy:t,state:i,is_replay:s}))}tipActivated(e,t,i){this.ended||(this.tips+=1,l._w.videoStreamTipActivated((0,f.A)((0,f.A)({},this.baseParams()),{},{tip_name:e,energy:t,state:i})))}customTipTapped(e){this.ended||l._w.videoStreamCustomTipTapped((0,f.A)((0,f.A)({},this.baseParams()),{},{state:e}))}customTipSubmitted(e,t,i,s){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"typed",a=arguments.length>5&&void 0!==arguments[5]&&arguments[5];this.ended||l._w.videoStreamCustomTipSubmitted((0,f.A)((0,f.A)({},this.baseParams()),{},{prompt:e,prompt_length:e.length,energy:t,state:i,access_level:s,source:n,suggestion_tip:a}))}customTipChipsShown(e,t,i,s,n){this.ended||l._w.videoStreamCustomTipChipsShown((0,f.A)((0,f.A)({},this.baseParams()),{},{row_id:e,state:t,chips:i,chip_count:i.length,energy:s,language:n}))}customTipChipTapped(e,t,i,s,n,a,r){if(this.ended)return;const o=(0,f.A)((0,f.A)({},this.baseParams()),{},{row_id:e,state:t,chip:i,other_chip:s,position:n,chip_length:i.length,energy:a,language:r});l._w.videoStreamCustomTipChipTapped(o),l._w.videoStreamSuggestionTipTapped(o)}suggestionTipSubmitted(e,t,i,s,n,a){this.ended||l._w.videoStreamSuggestionTipSubmitted((0,f.A)((0,f.A)({},this.baseParams()),{},{row_id:e,state:t,chip:i,energy:s,language:n,access_level:a}))}customStreamBannerShown(){this.ended||l._w.customStreamBannerShown((0,f.A)({source:"live_stream"},this.baseParams()))}customStreamBannerTapped(e,t,i){this.ended||l._w.customStreamBannerTapped((0,f.A)((0,f.A)({source:"live_stream"},this.baseParams()),{},{price:e,energy:t,is_anonymous:i}))}customStreamBannerClosed(){this.ended||l._w.customStreamBannerClosed((0,f.A)({source:"live_stream"},this.baseParams()))}customStreamComingSoonShown(e){this.ended||l._w.customStreamComingSoonShown({source:"live_stream",price:e})}customStreamComingSoonClosed(e){this.ended||l._w.customStreamComingSoonClosed({source:"live_stream",price:e})}customStreamOfferShown(e){this.ended||l._w.customStreamOfferShown({source:"live_stream",price:e})}customStreamOfferClosed(e){this.ended||l._w.customStreamOfferClosed({source:"live_stream",price:e})}customStreamStartTapped(e,t){this.ended||l._w.customStreamStartTapped({source:"live_stream",price:e,energy:t})}customTipClosed(e,t){this.ended||l._w.videoStreamCustomTipClosed((0,f.A)((0,f.A)({},this.baseParams()),{},{state:e,had_text:t}))}stateActivated(e){this.ended||(this.states+=1,l._w.videoStreamStateActivated((0,f.A)((0,f.A)({},this.baseParams()),{},{state_name:e})))}billingGateShown(e,t,i){this.ended||l._w.videoStreamBillingGateShown((0,f.A)((0,f.A)({},this.baseParams()),{},{billing_state:e,price_energy:t,period_seconds:i}))}reconnectCompleted(){this.ended||(this.reconnects+=1)}error(e,t){this.ended||l._w.videoStreamError((0,f.A)((0,f.A)({},this.baseParams()),{},{stage:e,code:C(t)}))}errorShown(e,t){this.ended||l._w.videoStreamErrorShown((0,f.A)((0,f.A)({},this.baseParams()),{},{kind:C(e),message:t}))}setVisible(e){this.ended||this.visible===e||(this.visible=e,e?this.startActiveTime():this.stopActiveTime())}setTerminalReason(e){this.terminalReason=e}clearTerminalReason(){this.terminalReason=null}end(e){var t;this.ended||(this.stopActiveTime(),this.ended=!0,l._w.videoStreamSessionEnded((0,f.A)((0,f.A)({},this.baseParams()),{},{total_seconds:I(this.now()-this.openedAt),active_seconds:I(this.activeMs),messages:this.messages,committed_playbacks:this.committedPlaybacks,tips:this.tips,states:this.states,reconnects:this.reconnects,end_reason:null!==(t=this.terminalReason)&&void 0!==t?t:e})))}baseParams(){return{stream_visit_id:this.streamVisitId,stream:this.streamId}}startActiveTime(){this.started&&this.visible&&null===this.activeStartedAt&&(this.activeStartedAt=this.now())}stopActiveTime(){null!==this.activeStartedAt&&(this.activeMs+=Math.max(0,this.now()-this.activeStartedAt),this.activeStartedAt=null)}}function I(e){return Math.round(Math.max(0,e)/100)/10}function C(e){return e.trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"_").slice(0,64)||"unknown"}const P=(e,t)=>globalThis.setTimeout.call(globalThis,e,t),k=e=>globalThis.clearTimeout.call(globalThis,e);class w{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:P,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;this.schedule=e,this.cancel=t,this.reconnect=null,this.connectTimeout=null,this.sessionReadyTimeout=null,this.operationTimeout=null}scheduleReconnect(e,t){return null===this.reconnect&&(this.reconnect=this.schedule(()=>{this.reconnect=null,t()},e),!0)}startConnectTimeout(e,t){this.clearConnectTimeout(),this.connectTimeout=this.schedule(()=>{this.connectTimeout=null,t()},e)}startSessionReadyTimeout(e,t){this.clearSessionReadyTimeout(),this.sessionReadyTimeout=this.schedule(()=>{this.sessionReadyTimeout=null,t()},e)}startOperationTimeout(e,t){this.clearOperationTimeout(),this.operationTimeout=this.schedule(()=>{this.operationTimeout=null,t()},e)}clearReconnect(){null!==this.reconnect&&(this.cancel(this.reconnect),this.reconnect=null)}clearConnectTimeout(){null!==this.connectTimeout&&(this.cancel(this.connectTimeout),this.connectTimeout=null)}clearSessionReadyTimeout(){null!==this.sessionReadyTimeout&&(this.cancel(this.sessionReadyTimeout),this.sessionReadyTimeout=null)}clearOperationTimeout(){null!==this.operationTimeout&&(this.cancel(this.operationTimeout),this.operationTimeout=null)}clearConnectionTimeouts(){this.clearConnectTimeout(),this.clearSessionReadyTimeout()}clearAll(){this.clearReconnect(),this.clearConnectionTimeouts(),this.clearOperationTimeout()}}const x={1:"media loading was aborted",2:"a network error interrupted media loading",3:"the browser could not decode a media clip",4:"the media format is not supported"},A=12e3,R=1e4;class M{constructor(e,t){if(this.videos=void 0,this.callbacks=void 0,this.endedHandlers=void 0,this.errorHandlers=void 0,this.readyHandlers=void 0,this.timeUpdateHandlers=void 0,this.waitingHandlers=void 0,this.playingHandlers=void 0,this.slotItems=[null,null],this.slotUrls=[null,null],this.activeIndex=0,this.current=null,this.next=null,this.idleLo
1op=[],this.idleBoundary=null,this.position=null,this.plan=null,this.activeTimeCue=null,this.started=!1,this.stopped=!0,this.failureReported=!1,this.generation=0,this.cancelPlayableWait=null,this.startPromise=null,this.initialLoadTimeout=null,this.stallTimeout=null,this.handoffPending=!1,this.mediaOperationCancels=new Set,this.userMuted=!1,this.videos=e,this.callbacks=t,this.endedHandlers=[()=>this.handleEnded(0),()=>this.handleEnded(1)],this.errorHandlers=[()=>this.handleMediaError(0),()=>this.handleMediaError(1)],this.readyHandlers=[()=>this.handleCanPlay(0),()=>this.handleCanPlay(1)],this.timeUpdateHandlers=[()=>this.handleTimeUpdate(0),()=>this.handleTimeUpdate(1)],this.waitingHandlers=[()=>this.handleWaiting(0),()=>this.handleWaiting(1)],this.playingHandlers=[()=>this.handlePlaying(0),()=>this.handlePlaying(1)],!Number.isFinite(this.callbacks.activeTimeLeadSeconds)||this.callbacks.activeTimeLeadSeconds<0)throw new Error("Active-time lead must be a non-negative number.");this.videos.forEach((e,t)=>{e.preload="auto",e.playsInline=!0,e.controls=!1,e.addEventListener("ended",this.endedHandlers[t]),e.addEventListener("error",this.errorHandlers[t]),e.addEventListener("canplay",this.readyHandlers[t]),e.addEventListener("timeupdate",this.timeUpdateHandlers[t]),e.addEventListener("waiting",this.waitingHandlers[t]),e.addEventListener("stalled",this.waitingHandlers[t]),e.addEventListener("playing",this.playingHandlers[t])}),this.syncVisibility()}get pendingPlanId(){var e,t;return null!==(e=null===(t=this.plan)||void 0===t?void 0:t.id)&&void 0!==e?e:null}get canStart(){const e=this.videos[this.activeIndex];return!this.stopped&&null!==this.current&&e.readyState>=HTMLMediaElement.HAVE_FUTURE_DATA}get isPlaying(){const e=this.videos[this.activeIndex];return this.started&&!this.stopped&&!e.paused&&!e.ended}secondsUntilPendingChoiceStarts(){var e,t,i,s;if(null===this.plan||"idle"!==(null===(e=this.current)||void 0===e?void 0:e.source))return 0;const n=function(e){const t=V(e),i=L(e.currentTime),s=L(e.playbackRate);if(null===t||null===i||null===s||s<=0)return null;return Math.max(0,t-i/s)}(this.videos[this.activeIndex]);if(null===n)return null;const a=this.plan.playback.clips.length-1;if("plan"===(null===(t=this.next)||void 0===t?void 0:t.source)&&this.next.planId===this.plan.id&&this.next.index===a)return n;const r=0===this.activeIndex?1:0;if(!("plan"===(null===(i=this.next)||void 0===i?void 0:i.source)&&this.next.planId===this.plan.id&&this.next.index===a-1||"idle"===(null===(s=this.next)||void 0===s?void 0:s.source)&&0===a&&O(j(this.next.clip),this.plan.playback.start)))return null;const l=V(this.videos[r]);return null===l?null:n+l}loadSession(e){this.reset();const t={stateId:e.stateId,anchorId:e.anchorId};this.stopped=!1,this.failureReported=!1,this.idleLoop=e.idleLoop,this.idleBoundary=t,this.position=t,this.activeIndex=0,this.current=B(e.idleLoop,0),this.setSlot(0,this.current),this.startInitialLoadTimeout(0,this.generation),this.prepareNext(),this.syncVisibility(),this.reportCanStart()}async restoreSession(e){const t=B(e.idleLoop,0),i={stateId:e.stateId,anchorId:e.anchorId};this.suspend();const s=this.generation,n=0===this.activeIndex?1:0;if(this.setSlot(n,t),await this.waitUntilPlayable(n,s,A),s!==this.generation)throw new Error("Restored playback was replaced while loading.");this.failureReported=!1,this.idleLoop=e.idleLoop,this.idleBoundary=i,this.position=i,this.plan=null,this.current=t,this.next=null,this.activeIndex=n,this.stopped=!1,this.started=!1,this.reportCanStart()}start(){if(null!==this.startPromise)return this.startPromise;if(!this.canStart||null===this.current)return Promise.reject(new Error("The first video is not ready yet."));this.started=!0;const e=this.generation;null!==this.next&&this.primeStandbyVideo(e);const t=this.startForGeneration(e);return this.startPromise=t,t.then(()=>{this.startPromise===t&&(this.startPromise=null)},()=>{this.startPromise===t&&(this.startPromise=null)}),t}async startForGeneration(e){try{if(await this.withMediaTimeout(this.videos[this.activeIndex].play(),R,"Playback did not start in time."),await this.waitUntilFramePresented(this.activeIndex,e,R),e!==this.generation||this.stopped)throw new E;if(this.syncVisibility(),null===this.next&&(this.prepareNext(),this.stopped))throw new Error("The restored idle loop could not be prepared.")}catch(t){throw e===this.generation&&(this.started=!1,function(e){return"object"===typeof e&&null!==e&&"name"in e&&"NotAllowedError"===e.name}(t)||t instanceof E||this.fail("Playback could not start: ".concat($(t)))),t}}stagePlan(e,t){if(this.stopped||null===this.current)throw new Error("Cannot stage a plan before idle playback is ready.");
1if(null!==this.plan)throw new Error("A playback plan is already pending.");if(null===this.idleBoundary||!O(t.start,this.idleBoundary))throw new Error("The playback plan does not start at the current idle boundary.");this.plan={id:e,playback:t,phase:"waiting"},this.prepareNext()}async startPendingPlanNow(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(this.stopped||!this.started||"idle"!==(null===(e=this.current)||void 0===e?void 0:e.source)||null===this.plan)throw new Error("Cannot skip idle without a pending playback plan.");const i=this.plan,s=i.playback.clips.length-1,n={source:"plan",clip:i.playback.clips[s],index:s,planId:i.id},a=this.generation,r=0===this.activeIndex?1:0;if(this.videos[this.activeIndex].pause(),i.phase="playing",D(n,this.next)||(this.next=n,this.setSlot(r,n)),this.stopped)throw new Error("The pending playback plan could not be loaded.");try{var l,o,c,d,u;if(await Promise.all([this.waitUntilPlayable(r,a,A),(h=t,h>0?new Promise(e=>setTimeout(e,h)):Promise.resolve())]),a!==this.generation||this.stopped||(null===(l=this.plan)||void 0===l?void 0:l.id)!==i.id||!D(n,this.next))throw new Error("The pending playback plan changed while loading.");if(this.position=N(n.clip),this.activeIndex=r,this.current=n,this.next=null,null===(o=(c=this.callbacks).onClipStart)||void 0===o||o.call(c,n.clip.kind),await this.withMediaTimeout(this.videos[this.activeIndex].play(),R,"The pending playback plan did not start in time."),await this.waitUntilFramePresented(this.activeIndex,a,R),a!==this.generation||this.stopped||(null===(d=this.plan)||void 0===d?void 0:d.id)!==i.id)throw new E;if(this.syncVisibility(),this.prepareNext(),this.stopped)throw new Error("The next playback clip could not be prepared.");a===this.generation&&(null===(u=this.plan)||void 0===u?void 0:u.id)===i.id&&this.startActiveTimeCue(i)}catch(p){throw a!==this.generation||this.stopped||this.fail("Could not start the pending plan immediately: ".concat($(p))),p}var h}setMuted(e){this.userMuted=e,this.applyMuting()}async resume(){const e=this.videos[this.activeIndex];if(!this.started||this.stopped||null===this.current||e.ended)return!1;if(!e.paused)return!0;const t=this.generation;try{await this.withMediaTimeout(e.play(),R,"Playback did not resume in time.")}catch(i){return!1}return t===this.generation&&!this.stopped}applyMuting(){this.videos.forEach((e,t)=>{var i;const s=null===(i=this.slotItems[t])||void 0===i?void 0:i.clip.kind;e.muted=this.userMuted||"idle"===s||void 0===s})}suspend(){var e,t,i;this.generation+=1,this.cancelMediaOperations(),null===(e=this.cancelPlayableWait)||void 0===e||e.call(this),this.cancelPlayableWait=null,this.startPromise=null,this.handoffPending=!1,this.clearMediaTimeouts(),this.cancelActiveTimeCue(),this.videos.forEach(e=>e.pause()),this.started=!1,this.stopped=!0,this.current=null,this.next=null,this.idleLoop=[],this.idleBoundary=null,this.position=null,this.plan=null,null===(t=(i=this.callbacks).onCanStartChange)||void 0===t||t.call(i,!1)}reset(){var e,t,i;this.generation+=1,this.cancelMediaOperations(),null===(e=this.cancelPlayableWait)||void 0===e||e.call(this),this.cancelPlayableWait=null,this.startPromise=null,this.handoffPending=!1,this.clearMediaTimeouts(),this.cancelActiveTimeCue(),this.started=!1,this.stopped=!0,this.failureReported=!1,this.current=null,this.next=null,this.idleLoop=[],this.idleBoundary=null,this.position=null,this.plan=null,null===(t=(i=this.callbacks).onCanStartChange)||void 0===t||t.call(i,!1),this.videos.forEach((e,t)=>{e.pause(),this.slotItems[t]=null,this.slotUrls[t]=null,e.removeAttribute("src"),e.load()}),this.activeIndex=0,this.syncVisibility()}destroy(){this.reset(),this.videos.forEach((e,t)=>{e.removeEventListener("ended",this.endedHandlers[t]),e.removeEventListener("error",this.errorHandlers[t]),e.removeEventListener("canplay",this.readyHandlers[t]),e.removeEventListener("timeupdate",this.timeUpdateHandlers[t]),e.removeEventListener("waiting",this.waitingHandlers[t]),e.removeEventListener("stalled",this.waitingHandlers[t]),e.removeEventListener("playing",this.playingHandlers[t])})}handleEnded(e){var t,i;if(this.stopped||e!==this.activeIndex||null===this.current)return;this.clearStallTimeout();const s=this.current,n=j(s.clip);if(null===this.next||!F(this.next.clip,n))return void this.fail("The next media clip was not ready at a valid boundary.");const a=0===this.activeIndex?1:0;if(this.videos[a].readyState<HTMLMediaElement.HAVE_FUTURE_DATA)return void this.waitForPlayableHandoff(e,a,s);this.position=n;const r="plan"===s.source&&null!==this.plan&&s.planId===this.plan.id&&s.index===this.plan.playback.clips.length-1;if(r&&null!==this.plan){if(this.cancelActiveTimeCue(),!O(n,this.plan.playback.end))return void this.fail("The playback plan ended at an unexpected position.");
1this.plan.phase="finishing",this.idleLoop=this.plan.playback.nextIdleLoop,this.idleBoundary=this.plan.playback.end}this.activeIndex=0===this.activeIndex?1:0,this.current=this.next,this.next=null,null===(t=(i=this.callbacks).onClipStart)||void 0===t||t.call(i,this.current.clip.kind);const l=this.generation,o=r&&null!==this.plan?this.plan.id:null,c="plan"===this.current.source&&null!==this.plan&&this.current.planId===this.plan.id&&this.current.index===this.plan.playback.clips.length-1?this.plan.id:null;this.withMediaTimeout(this.videos[this.activeIndex].play(),R,"The next media clip did not start in time.").then(()=>this.waitUntilFramePresented(this.activeIndex,l,R)).then(()=>{if(l!==this.generation||this.stopped)return;if(this.syncVisibility(),this.prepareNext(),this.stopped)return;const e=this.plan;l===this.generation&&null!==e&&(null!==c&&e.id===c&&this.startActiveTimeCue(e),null!==o&&e.id===o&&"finishing"===e.phase&&(this.plan=null,this.callbacks.onPlanCompleted(o)))}).catch(e=>{l===this.generation&&this.fail("The next media clip could not play: ".concat($(e)))})}waitForPlayableHandoff(e,t,i){if(this.handoffPending)return;this.handoffPending=!0;const s=this.generation;this.waitUntilPlayable(t,s,A).then(()=>{s!==this.generation||this.stopped||this.activeIndex!==e||this.current!==i||(this.handoffPending=!1,this.handleEnded(e))},e=>{s!==this.generation||this.stopped||(this.handoffPending=!1,this.fail("The next media clip was not ready: ".concat($(e))))})}primeStandbyVideo(e){const t=0===this.activeIndex?1:0,i=this.videos[t],s=this.slotUrls[t],n=i.volume;i.volume=0,i.play().then(()=>{e===this.generation&&t!==this.activeIndex&&s===this.slotUrls[t]&&(i.pause(),i.currentTime=0),i.volume=n}).catch(()=>{i.volume=n})}prepareNext(){if(null===this.current||this.stopped)return;let e;try{e=this.chooseFollowingItem(this.current)}catch(i){return void this.fail("Could not prepare the next clip: ".concat($(i)))}if(D(e,this.next))return;const t=0===this.activeIndex?1:0;this.next=e,this.setSlot(t,e)}chooseFollowingItem(e){var t;const i=j(e.clip);if("plan"===e.source){const t=this.plan;if(null===t||t.id!==e.planId)throw new Error("the active playback plan is no longer available");const s=e.index+1;if(s<t.playback.clips.length){const e=t.playback.clips[s];return U(e,i,"next plan clip"),{source:"plan",clip:e,index:s,planId:t.id}}const n=B(t.playback.nextIdleLoop,0);return U(n.clip,i,"next idle clip"),n}const s="waiting"===(null===(t=this.plan)||void 0===t?void 0:t.phase)?this.plan:null;if(null!==s){const t=s.playback.clips.findIndex((t,i)=>{return i<s.playback.clips.length-1&&(n=e.clip,a=t,"idle"===n.kind&&"idle"===a.kind&&O(N(n),N(a))&&O(j(n),j(a)));var n,a});if(t>=0){const e=t+1,n=s.playback.clips[e];return U(n,i,"next plan clip"),s.phase="playing",{source:"plan",clip:n,index:e,planId:s.id}}if(O(i,s.playback.start)){const e=s.playback.clips[0];return U(e,i,"first plan clip"),s.phase="playing",{source:"plan",clip:e,index:0,planId:s.id}}}const n=(e.index+1)%e.loop.length,a=B(e.loop,n);return U(a.clip,i,"next idle clip"),a}setSlot(e,t){var i;(null===(i=this.activeTimeCue)||void 0===i?void 0:i.videoIndex)===e&&this.cancelActiveTimeCue();const s=this.videos[e];s.pause(),this.slotItems[e]=t,this.slotUrls[e]=t.clip.url,s.src=t.clip.url,s.load(),this.applyMuting()}waitUntilPlayable(e,t,i){const s=this.videos[e];return s.readyState>=HTMLMediaElement.HAVE_FUTURE_DATA?Promise.resolve():new Promise((e,n)=>{var a;let r=null;const l=t=>{s.removeEventListener("canplay",o),s.removeEventListener("error",c),null!==r&&(globalThis.clearTimeout(r),r=null),this.cancelPlayableWait===d&&(this.cancelPlayableWait=null),void 0===t?e():n(t)},o=()=>{t===this.generation?l():l(new Error("Playback was reset while loading."))},c=()=>{l(new Error("The pending playback clip failed to load."))},d=()=>{l(new E)};null===(a=this.cancelPlayableWait)||void 0===a||a.call(this),this.cancelPlayableWait=d,s.addEventListener("canplay",o),s.addEventListener("error",c),r=globalThis.setTimeout(()=>l(new Error("The media clip did not become playable in time.")),i)})}waitUntilFramePresented(e,t,i){const s=this.videos[e];return"function"!==typeof s.requestVideoFrameCallback?Promise.resolve():new Promise((n,a)=>{let r=!1,l=null;const o=e=>{r||(r=!0,globalThis.clearTimeout(d),this.mediaOperationCancels.delete(c),void 0!==e&&null!==l&&"function"===typeof s.cancelVideoFrameCallback&&s.cancelVideoFrameCallback(l),void 0===e?n():a(e))},c=()=>o(new E),d=globalThis.setTimeout(()=>
1o(new Error("The next video frame did not appear in time.")),i);this.mediaOperationCancels.add(c),l=s.requestVideoFrameCallback(()=>{t!==this.generation||this.stopped||e!==this.activeIndex?o(new E):o()})})}handleCanPlay(e){e===this.activeIndex&&this.clearInitialLoadTimeout(),this.reportCanStart()}handleTimeUpdate(e){e===this.activeIndex&&this.clearStallTimeout(),this.checkActiveTimeCue(e)}handleWaiting(e){if(this.stopped||!this.started||e!==this.activeIndex||null!==this.stallTimeout)return;const t=this.generation;this.stallTimeout=globalThis.setTimeout(()=>{this.stallTimeout=null,t!==this.generation||this.stopped||e!==this.activeIndex||this.fail("Playback stalled while loading media.")},1e4)}handlePlaying(e){e===this.activeIndex&&(this.clearInitialLoadTimeout(),this.clearStallTimeout())}startInitialLoadTimeout(e,t){this.clearInitialLoadTimeout(),this.initialLoadTimeout=globalThis.setTimeout(()=>{this.initialLoadTimeout=null,t!==this.generation||this.stopped||e!==this.activeIndex||this.canStart||this.fail("The first media clip did not become playable in time.")},A)}clearInitialLoadTimeout(){null!==this.initialLoadTimeout&&(globalThis.clearTimeout(this.initialLoadTimeout),this.initialLoadTimeout=null)}clearStallTimeout(){null!==this.stallTimeout&&(globalThis.clearTimeout(this.stallTimeout),this.stallTimeout=null)}clearMediaTimeouts(){this.clearInitialLoadTimeout(),this.clearStallTimeout()}withMediaTimeout(e,t,i){return new Promise((s,n)=>{let a=!1;const r=e=>{a||(a=!0,globalThis.clearTimeout(o),this.mediaOperationCancels.delete(l),"value"in e?s(e.value):n(e.error))},l=()=>r({error:new E}),o=globalThis.setTimeout(()=>r({error:new Error(i)}),t);this.mediaOperationCancels.add(l),e.then(e=>r({value:e}),e=>r({error:e}))})}cancelMediaOperations(){const e=[...this.mediaOperationCancels];this.mediaOperationCancels.clear(),e.forEach(e=>e())}handleMediaError(e){var t,i;if(this.stopped||null===this.slotItems[e])return;const s=this.videos[e],n=this.slotUrls[e],a=s.currentSrc||s.src;if(null!==n&&a&&a!==n)return;const r=null===(t=s.error)||void 0===t?void 0:t.code,l=void 0===r?"a media clip failed to load":null!==(i=x[r])&&void 0!==i?i:"a media clip failed with error code ".concat(r);this.fail("Playback failed because ".concat(l,"."))}reportCanStart(){var e,t;null===(e=(t=this.callbacks).onCanStartChange)||void 0===e||e.call(t,this.canStart)}startActiveTimeCue(e){var t;this.cancelActiveTimeCue();const i=Math.max(0,(null!==(t=e.playback.activeTimeStartSeconds)&&void 0!==t?t:0)-this.callbacks.activeTimeLeadSeconds),s={planId:e.id,videoIndex:this.activeIndex,targetSeconds:i,frameCallbackId:null};this.activeTimeCue=s,this.checkActiveTimeCue(s.videoIndex),this.activeTimeCue===s&&this.scheduleActiveTimeCueFrame(s)}checkActiveTimeCue(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.videos[e].currentTime;const i=this.activeTimeCue,s=this.plan,n=this.current;null!==i&&i.videoIndex===e&&(null!==s&&s.id===i.planId&&"plan"===(null===n||void 0===n?void 0:n.source)&&n.planId===i.planId&&n.index===s.playback.clips.length-1&&this.activeIndex===e?!Number.isFinite(t)||t<i.targetSeconds||(this.cancelActiveTimeCue(),this.callbacks.onActiveTimeReached(i.planId,i.targetSeconds)):this.cancelActiveTimeCue())}scheduleActiveTimeCueFrame(e){const t=this.videos[e.videoIndex];"function"===typeof t.requestVideoFrameCallback&&(e.frameCallbackId=t.requestVideoFrameCallback((t,i)=>{this.activeTimeCue===e&&(e.frameCallbackId=null,this.checkActiveTimeCue(e.videoIndex,i.mediaTime),this.activeTimeCue===e&&this.scheduleActiveTimeCueFrame(e))}))}cancelActiveTimeCue(){const e=this.activeTimeCue;if(null===e)return;if(this.activeTimeCue=null,null===e.frameCallbackId)return;const t=this.videos[e.videoIndex];"function"===typeof t.cancelVideoFrameCallback&&t.cancelVideoFrameCallback(e.frameCallbackId)}fail(e){var t,i,s,n,a;this.failureReported||this.stopped||(this.failureReported=!0,this.stopped=!0,this.started=!1,this.generation+=1,this.cancelMediaOperations(),null===(t=this.cancelPlayableWait)||void 0===t||t.call(this),this.cancelPlayableWait=null,this.startPromise=null,this.handoffPending=!1,this.clearMediaTimeouts(),this.cancelActiveTimeCue(),this.videos.forEach(e
1=>e.pause()),null===(i=(s=this.callbacks).onCanStartChange)||void 0===i||i.call(s,!1),this.callbacks.onFailure({planId:null!==(n=null===(a=this.plan)||void 0===a?void 0:a.id)&&void 0!==n?n:null,reason:e.slice(0,500)}))}syncVisibility(){this.videos.forEach((e,t)=>{const i=t===this.activeIndex;e.dataset.active=String(i)})}}class E extends Error{constructor(){super("Playback was reset while loading."),this.name="PlaybackCancelledError"}}function B(e,t){const i=e[t];if(void 0===i)throw new Error("Idle playback received an empty or invalid loop.");return{source:"idle",clip:i,index:t,loop:e}}function j(e){return{stateId:e.toStateId,anchorId:e.toAnchorId}}function N(e){return{stateId:e.fromStateId,anchorId:e.fromAnchorId}}function L(e){return Number.isFinite(e)?e:null}function V(e){const t=L(e.duration),i=L(e.playbackRate);return null===t||t<0||null===i||i<=0?null:t/i}function F(e,t){return e.fromStateId===t.stateId&&e.fromAnchorId===t.anchorId}function O(e,t){return e.stateId===t.stateId&&e.anchorId===t.anchorId}function U(e,t,i){if(!F(e,t))throw new Error("".concat(i," does not continue from the current position"))}function D(e,t){return null!==t&&e.source===t.source&&e.index===t.index&&e.clip.url===t.clip.url&&("plan"===e.source&&"plan"===t.source?e.planId===t.planId:"idle"===e.source&&"idle"===t.source&&e.loop===t.loop)}function $(e){return e instanceof Error?e.message:"unknown playback error"}const q="video-stream-v2",H=128,W=Object.prototype;class G extends Error{constructor(e,t){super("".concat(e,": ").concat(t)),this.path=void 0,this.name="ProtocolError",this.path=e}}function K(e,t){const i=e.trim();if(!i)throw new G(t,"must be a non-empty HTTP(S) URL");let s;try{s=new URL(i)}catch(n){throw new G(t,"must be a valid absolute URL")}if("http:"!==s.protocol&&"https:"!==s.protocol)throw new G(t,"must use the http: or https: protocol");if(s.username||s.password)throw new G(t,"must not contain credentials");if(s.search||s.hash)throw new G(t,"must not contain a query or fragment");return s}function Y(e){return e.toString().replace(/\/+$/,"")}function Q(e){const t=function(e){if("string"!==typeof e)return e;try{return JSON.parse(e)}catch(t){throw new G("$","must be valid JSON")}}(e),i=ce(t,"$"),s=ue(i.type,"$.type",{nonBlank:!0});switch(s){case"session_ready":return function(e){de(e,["type","sessionId","stateId","anchorId","idleLoop","revision","discoveredActionIdsByState","stateBadges","animateTipButton"],"$",["customTipsEnabled","customTipPrice","messagePrice","speakers"]);const t={type:"session_ready",sessionId:ue(e.sessionId,"$.sessionId",{nonBlank:!0}),stateId:ue(e.stateId,"$.stateId",{nonBlank:!0}),anchorId:ue(e.anchorId,"$.anchorId",{nonBlank:!0}),idleLoop:te(e.idleLoop,"$.idleLoop"),revision:pe(e.revision,"$.revision"),discoveredActionIdsByState:{},stateBadges:ie(e.stateBadges,"$.stateBadges"),animateTipButton:he(e.animateTipButton,"$.animateTipButton"),customTipsEnabled:void 0!==e.customTipsEnabled&&he(e.customTipsEnabled,"$.customTipsEnabled"),customTipPrice:void 0===e.customTipPrice||null===e.customTipPrice?null:pe(e.customTipPrice,"$.customTipPrice"),messagePrice:void 0===e.messagePrice||null===e.messagePrice?null:pe(e.messagePrice,"$.messagePrice"),speakers:void 0===e.speakers||null===e.speakers?[]:z(e.speakers,"$.speakers")};if(t.discoveredActionIdsByState=function(e,t,i){const s=ce(e,i);return de(s,t.map(e=>e.stateId),i),Object.fromEntries(t.map(e=>{const t="".concat(i,".").concat(e.stateId),n=se(s[e.stateId],t);if(n.length>e.actionTotal)throw new G(t,"cannot exceed the state's action total");return[e.stateId,n]}))}(e.discoveredActionIdsByState,t.stateBadges,"$.discoveredActionIdsByState"),!t.stateBadges.some(e=>e.stateId===t.stateId))throw new G("$.stateBadges","must include the current stateId");return ne(t.idleLoop,{stateId:t.stateId,anchorId:t.anchorId},"$.idleLoop"),t}(i);case"opening_message":return function(e){return de(e,["type","replyText"],"$",["replies"]),{type:"opening_message",replyText:ue(e.replyText,"$.replyText",{nonBlank:!0}),replies:void 0===e.replies||null===e.replies?null:J(e.replies,"$.replies")}}(i);case"chat_history":return function(e){if(de(e,["type","messages"],"$"),
1!Array.isArray(e.messages)||0===e.messages.length)throw new G("$.messages","must be a non-empty array");const t=e.messages.map((e,t)=>{if("object"!==typeof e||null===e||Array.isArray(e))throw new G("$.messages[".concat(t,"]"),"must be an object");const i=e;if(de(i,["sender","text"],"$.messages[".concat(t,"]"),["speakerId"]),"user"!==i.sender&&"assistant"!==i.sender)throw new G("$.messages[".concat(t,"].sender"),'must be "user" or "assistant"');return{sender:i.sender,text:ue(i.text,"$.messages[".concat(t,"].text"),{nonBlank:!0}),speakerId:void 0===i.speakerId||null===i.speakerId?null:ue(i.speakerId,"$.messages[".concat(t,"].speakerId"),{nonBlank:!0})}});return{type:"chat_history",messages:t}}(i);case"suggestions":return function(e){if(de(e,["type","suggestions"],"$"),!Array.isArray(e.suggestions)||0===e.suggestions.length)throw new G("$.suggestions","must be a non-empty array");if(e.suggestions.length>2)throw new G("$.suggestions","must contain at most ".concat(2," items"));const t=new Set,i=e.suggestions.map((e,i)=>{const s="$.suggestions[".concat(i,"]"),n=ue(e,s,{nonBlank:!0,maxLength:80});if(n.trim().split(/[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]+/).length>10)throw new G(s,"must contain at most ".concat(10," words"));const a=n.toLocaleLowerCase();if(t.has(a))throw new G(s,'duplicates suggestion "'.concat(n,'"'));return t.add(a),n});return{type:"suggestions",suggestions:i}}(i);case"turn_result":return function(e){return de(e,["type","messageId","planId","replyText","playback"],"$"),{type:"turn_result",messageId:ue(e.messageId,"$.messageId",{nonBlank:!0,maxLength:H}),planId:ue(e.planId,"$.planId",{nonBlank:!0,maxLength:H}),replyText:ue(e.replyText,"$.replyText",{nonBlank:!0}),playback:X(e.playback,"$.playback")}}(i);case"tip_result":return function(e){return de(e,["type","planId","choiceId","playback"],"$",["energyBalance"]),{type:"tip_result",planId:ue(e.planId,"$.planId",{nonBlank:!0,maxLength:H}),choiceId:ue(e.choiceId,"$.choiceId",{nonBlank:!0}),playback:X(e.playback,"$.playback"),energyBalance:null===e.energyBalance||void 0===e.energyBalance?null:pe(e.energyBalance,"$.energyBalance")}}(i);case"custom_tip_result":return function(e){return de(e,["type","clipId"],"$",["energyBalance"]),{type:"custom_tip_result",clipId:ue(e.clipId,"$.clipId",{nonBlank:!0}),energyBalance:null===e.energyBalance||void 0===e.energyBalance?null:pe(e.energyBalance,"$.energyBalance")}}(i);case"chat_reply":return function(e){return de(e,["type","replyText","animateTipButton"],"$",["messageId","energyBalance","replies"]),{type:"chat_reply",messageId:null===e.messageId||void 0===e.messageId?null:ue(e.messageId,"$.messageId",{nonBlank:!0,maxLength:H}),replyText:ue(e.replyText,"$.replyText",{nonBlank:!0}),animateTipButton:he(e.animateTipButton,"$.animateTipButton"),energyBalance:null===e.energyBalance||void 0===e.energyBalance?null:pe(e.energyBalance,"$.energyBalance"),replies:void 0===e.replies||null===e.replies?null:J(e.replies,"$.replies")}}(i);case"progress":return function(e){return de(e,["type","messagesInState","xpPerMessage","complete"],"$",["requiredMessages"]),{type:"progress",messagesInState:pe(e.messagesInState,"$.messagesInState"),requiredMessages:null===e.requiredMessages||void 0===e.requiredMessages?null:pe(e.requiredMessages,"$.requiredMessages"),xpPerMessage:pe(e.xpPerMessage,"$.xpPerMessage"),complete:he(e.complete,"$.complete")}}(i);case"tips":return function(e){if(de(e,["type","actions","nextState"],"$",["customActions","customActionsUnavailable"]),!Array.isArray(e.actions))throw new G("$.actions","must be an array");const t=e.actions.map((e,t)=>{const i="$.actions[".concat(t,"]"),s=ce(e,i);return de(s,["choiceId","label","tipPrice","watched","requiresSubscription"],i),{choiceId:ue(s.choiceId,"".concat(i,".choiceId"),{nonBlank:!0}),label:ue(s.label,"".concat(i,".label"),{nonBlank:!0}),tipPrice:pe(s.tipPrice,"".concat(i,".tipPrice")),watched:he(s.watched,"".concat(i,".watched")),requiresSubscription:he(s.requiresSubscription,"".concat(i,".requiresSubscription"))}});let i=null;if(null!==e.nextState&&void 0!==e.nextState){const t=ce(e.nextState,"$.nextState");
1de(t,["choiceId","label","tipPrice","requiresSubscription"],"$.nextState"),i={choiceId:ue(t.choiceId,"$.nextState.choiceId",{nonBlank:!0}),label:ue(t.label,"$.nextState.label",{nonBlank:!0}),tipPrice:pe(t.tipPrice,"$.nextState.tipPrice"),requiresSubscription:he(t.requiresSubscription,"$.nextState.requiresSubscription")}}let s=null;if(void 0!==e.customActions&&null!==e.customActions){if(!Array.isArray(e.customActions))throw new G("$.customActions","must be an array");const t=new Set;s=e.customActions.map((e,i)=>{const s="$.customActions[".concat(i,"]"),n=ce(e,s);de(n,["clipId","label","status"],s);const a=ue(n.clipId,"".concat(s,".clipId"),{nonBlank:!0});if(t.has(a))throw new G("".concat(s,".clipId"),'duplicates clip ID "'.concat(a,'"'));return t.add(a),{clipId:a,label:ue(n.label,"".concat(s,".label"),{nonBlank:!0}),status:ye(n.status,"".concat(s,".status"),["created","queued","pending","completed","error"])}})}return{type:"tips",nextState:i,actions:t,customActions:s,customActionsUnavailable:void 0!==e.customActionsUnavailable&&he(e.customActionsUnavailable,"$.customActionsUnavailable")}}(i);case"custom_tip_suggestions":return function(e){if(de(e,["type","rowId","suggestions","priceEnergy"],"$",["language"]),!Array.isArray(e.suggestions)||0===e.suggestions.length)throw new G("$.suggestions","must be a non-empty array");if(e.suggestions.length>2)throw new G("$.suggestions","must contain at most ".concat(2," items"));const t=new Set,i=e.suggestions.map((e,i)=>{const s="$.suggestions[".concat(i,"]"),n=ce(e,s);de(n,["suggestionId","chip"],s);const a=ue(n.suggestionId,"".concat(s,".suggestionId"),{nonBlank:!0,maxLength:H});if(t.has(a))throw new G(s,'duplicates suggestion id "'.concat(a,'"'));return t.add(a),{suggestionId:a,chip:ue(n.chip,"".concat(s,".chip"),{nonBlank:!0,maxLength:64})}});return{type:"custom_tip_suggestions",rowId:ue(e.rowId,"$.rowId",{nonBlank:!0,maxLength:H}),suggestions:i,priceEnergy:pe(e.priceEnergy,"$.priceEnergy"),language:void 0===e.language?"":ue(e.language,"$.language",{maxLength:32})}}(i);case"proactive_result":return function(e){return de(e,["type","planId","playback"],"$"),{type:"proactive_result",planId:ue(e.planId,"$.planId",{nonBlank:!0,maxLength:H}),playback:X(e.playback,"$.playback")}}(i);case"playback_committed":return function(e){de(e,["type","planId","revision","stateId","anchorId","discoveredActionIds"],"$");const t=pe(e.revision,"$.revision");if(0===t)throw new G("$.revision","must be at least 1");return{type:"playback_committed",planId:ue(e.planId,"$.planId",{nonBlank:!0,maxLength:H}),revision:t,stateId:ue(e.stateId,"$.stateId",{nonBlank:!0}),anchorId:ue(e.anchorId,"$.anchorId",{nonBlank:!0}),discoveredActionIds:se(e.discoveredActionIds,"$.discoveredActionIds")}}(i);case"billing_status":return function(e){return de(e,["type","state","priceEnergy","periodSeconds","balance"],"$"),{type:"billing_status",state:ye(e.state,"$.state",["free","payment_required","paid","insufficient_energy","unavailable"]),priceEnergy:me(e.priceEnergy,"$.priceEnergy"),periodSeconds:ge(e.periodSeconds,"$.periodSeconds"),balance:null===e.balance?null:pe(e.balance,"$.balance")}}(i);case"progress_reset":return de(i,["type"],"$"),{type:s};case"error":return function(e){return de(e,["type","code","message","retryable"],"$"),{type:"error",code:ue(e.code,"$.code",{nonBlank:!0}),message:ue(e.message,"$.message",{nonBlank:!0}),retryable:he(e.retryable,"$.retryable")}}(i);default:throw new G("$.type",'unknown server message "'.concat(s,'"'))}}function Z(e){return JSON.stringify(function(e){const t=ce(e,"$"),i=ue(t.type,"$.type",{nonBlank:!0});switch(i){case"stream_started":case"reset_progress":case"user_activity":case"billing_continue":case"tip_prompt_acknowledged":return de(t,["type"],"$"),{type:i};case"user_message":return de(t,["type","messageId","text"],"$"),{type:i,messageId:ue(t.messageId,"$.messageId",{nonBlank:!0,maxLength:H}),text:ue(t.text,"$.text",{nonBlank:!0,maxLength:2e3})};case"continue":return de(t,["type","messageId"],"$"),{type:i,messageId:ue(t.messageId,"$.messageId",{nonBlank:!0,maxLength:H})};case"buy_tip":return de(t,["type","choiceId"],"$"),{type:i,choiceId:ue(t.choiceId,"$.choiceId",{nonBlank:!0,maxLength:H})};case"custom_tip_request":return void 0!==t.suggestionId?(de(t,["type","suggestionId"],"$"),{type:i,suggestionId:ue(t.suggestionId,"$.suggestionId",{nonBlank:!0,maxLength:H})}):(de(t,["type","prompt"],"$"),{type:i,prompt:ue(t.prompt,"$.prompt",{nonBlank:!0,maxLength:300})});case"custom_tip_delete":return de(t,["type","clipId"],"$"),{type:i,clipId:ue(t.clipId,"$.clipI
1d",{nonBlank:!0,maxLength:H})};case"playback_completed":return de(t,["type","planId"],"$"),{type:i,planId:ue(t.planId,"$.planId",{nonBlank:!0,maxLength:H})};case"playback_failed":return de(t,["type","planId","reason"],"$"),{type:i,planId:ue(t.planId,"$.planId",{nonBlank:!0,maxLength:H}),reason:ue(t.reason,"$.reason",{nonBlank:!0,maxLength:500})};default:throw new G("$.type",'unknown client message "'.concat(i,'"'))}}(e))}function z(e,t){if(!Array.isArray(e))throw new G(t,"must be an array");return e.map((e,i)=>{if("object"!==typeof e||null===e||Array.isArray(e))throw new G("".concat(t,"[").concat(i,"]"),"must be an object");const s=e;return de(s,["id","name"],"".concat(t,"[").concat(i,"]")),{id:ue(s.id,"".concat(t,"[").concat(i,"].id"),{nonBlank:!0}),name:ue(s.name,"".concat(t,"[").concat(i,"].name"),{nonBlank:!0})}})}function J(e,t){if(!Array.isArray(e)||0===e.length)throw new G(t,"must be a non-empty array");return e.map((e,i)=>{if("object"!==typeof e||null===e||Array.isArray(e))throw new G("".concat(t,"[").concat(i,"]"),"must be an object");const s=e;return de(s,["speakerId","text"],"".concat(t,"[").concat(i,"]")),{speakerId:ue(s.speakerId,"".concat(t,"[").concat(i,"].speakerId"),{nonBlank:!0}),text:ue(s.text,"".concat(t,"[").concat(i,"].text"),{nonBlank:!0})}})}function X(e,t){const i=ce(e,t);de(i,["choiceId","choiceType","isRefusal","activeTimeStartSeconds","start","clips","end","nextIdleLoop"],t);const s=ye(i.choiceType,"".concat(t,".choiceType"),["action","transition","custom"]),n={choiceId:ue(i.choiceId,"".concat(t,".choiceId"),{nonBlank:!0}),choiceType:s,isRefusal:he(i.isRefusal,"".concat(t,".isRefusal")),activeTimeStartSeconds:null===i.activeTimeStartSeconds?null:ve(i.activeTimeStartSeconds,"".concat(t,".activeTimeStartSeconds")),start:ee(i.start,"".concat(t,".start")),clips:te(i.clips,"".concat(t,".clips")),end:ee(i.end,"".concat(t,".end")),nextIdleLoop:te(i.nextIdleLoop,"".concat(t,".nextIdleLoop"))};return function(e,t){let i=e.start;const s=e.clips.length-1;if(e.clips.forEach((n,a)=>{const r="".concat(t,".clips[").concat(a,"]");re(n,i,r),a<s&&ae(n,e.start.stateId,r),i=le(n)}),!oe(i,e.end))throw new G("".concat(t,".end"),"must match the endpoint of the final plan clip");const n=e.clips[s];if(n.kind!==e.choiceType)throw new G("".concat(t,".clips[").concat(s,"].kind"),'must be "'.concat(e.choiceType,'" to match choiceType'));if(n.itemId!==e.choiceId)throw new G("".concat(t,".clips[").concat(s,"].itemId"),"must match choiceId");if("action"===e.choiceType&&e.end.stateId!==e.start.stateId)throw new G("".concat(t,".end.stateId"),"an action plan must remain in its start state");if("custom"===e.choiceType&&!oe(e.end,e.start))throw new G("".concat(t,".end"),"a custom plan must return to its start position");if("transition"===e.choiceType&&e.isRefusal)throw new G("".concat(t,".isRefusal"),"must be false for a transition");ne(e.nextIdleLoop,e.end,"".concat(t,".nextIdleLoop"))}(n,t),n}function ee(e,t){const i=ce(e,t);return de(i,["stateId","anchorId"],t),{stateId:ue(i.stateId,"".concat(t,".stateId"),{nonBlank:!0}),anchorId:ue(i.anchorId,"".concat(t,".anchorId"),{nonBlank:!0})}}function te(e,t){if(!Array.isArray(e))throw new G(t,"must be an array");if(0===e.length)throw new G(t,"must contain at least one clip");return e.map((e,i)=>function(e,t){const i=ce(e,t);de(i,["kind","itemId","url","fromStateId","fromAnchorId","toStateId","toAnchorId"],t);const s=ye(i.kind,"".concat(t,".kind"),["idle","action","transition","custom"]);return{kind:s,itemId:ue(i.itemId,"".concat(t,".itemId"),{nonBlank:!0}),url:Se(i.url,"".concat(t,".url"),{relaxed:"custom"===s}),fromStateId:ue(i.fromStateId,"".concat(t,".fromStateId"),{nonBlank:!0}),fromAnchorId:ue(i.fromAnchorId,"".concat(t,".fromAnchorId"),{nonBlank:!0}),toStateId:ue(i.toStateId,"".concat(t,".toStateId"),{nonBlank:!0}),toAnchorId:ue(i.toAnchorId,"".concat(t,".toAnchorId"),{nonBlank:!0})}}(e,"".concat(t,"[").concat(i,"]")))}function ie(e,t){if(!Array.isArray(e)||0===e.length)throw new G(t,"must be a non-empty array");const i=new Set,s=new Set;return e.map((e,n)=>{const a="".concat(t,"[").concat(n,"]"),r=ce(e,a);de(r,["stateId","label","actionTotal"],a);const l=ue(r.stateId,"".concat(a,".stateId"),{nonBlank:!0}),o=ue(r.label,"".concat(a,".label"),{nonBlank:!0}),c=o.toLocaleLowerCase();if(!/^(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2F
1FF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+$/.test(o))throw new G("".concat(a,".label"),"must be exactly one word");if(i.has(l))throw new G("".concat(a,".stateId"),'duplicates stateId "'.concat(l,'"'));if(s.has(c))throw new G("".concat(a,".label"),'duplicates label "'.concat(o,'"'));return i.add(l),s.add(c),{stateId:l,label:o,actionTotal:pe(r.actionTotal,"".concat(a,".actionTotal"))}})}function se(e,t){if(!Array.isArray(e))throw new G(t,"must be an array");const i=new Set;return e.map((e,s)=>{const n=ue(e,"".concat(t,"[").concat(s,"]"),{nonBlank:!0});if(i.has(n))throw new G("".concat(t,"[").concat(s,"]"),'duplicates action ID "'.concat(n,'"'));return i.add(n),n})}function ne(e,t,i){let s=t;if(e.forEach((e,n)=>{const a="".concat(i,"[").concat(n,"]");re(e,s,a),ae(e,t.stateId,a),s=le(e)}),!oe(s,t))throw new G(i,"must return to its declared starting state and anchor")}function ae(e,t,i){if("idle"!==e.kind)throw new G("".concat(i,".kind"),'must be "idle"');if(e.fromStateId!==t||e.toStateId!==t)throw new G(i,"an idle clip must remain in the loop's state")}function re(e,t,i){if(e.fromStateId!==t.stateId||e.fromAnchorId!==t.anchorId)throw new G(i,'must start at state "'.concat(t.stateId,'", anchor "').concat(t.anchorId,'"'))}function le(e){return{stateId:e.toStateId,anchorId:e.toAnchorId}}function oe(e,t){return e.stateId===t.stateId&&e.anchorId===t.anchorId}function ce(e,t){if("object"!==typeof e||null===e||Array.isArray(e))throw new G(t,"must be an object");return e}function de(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];for(const n of t)if(!W.hasOwnProperty.call(e,n))throw new G("".concat(i,".").concat(n),"is required");for(const n of Object.keys(e))if(!t.includes(n)&&!s.includes(n))throw new G("".concat(i,".").concat(n),"is not allowed")}function ue(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"!==typeof e)throw new G(t,"must be a string");if(i.nonBlank&&0===e.trim().length)throw new G(t,"must not be blank");if(void 0!==i.maxLength&&Array.from(e).length>i.maxLength)throw new G(t,"must be at most ".concat(i.maxLength," characters"));return e}function he(e,t){if("boolean"!==typeof e)throw new G(t,"must be a boolean");return e}function pe(e,t){if(!Number.isInteger(e)||e<0)throw new G(t,"must be a non-negative integer");return e}function me(e,t){if(!Number.isInteger(e)||e<=0)throw new G(t,"must be a positive integer");return e}function ge(e,t){if("number"!==typeof e||!Number.isFinite(e)||e<=0)throw new G(t,"must be a positive finite number");return e}function ve(e,t){if("number"!==typeof e||!Number.isFinite(e)||e<0)throw new G(t,"must be a non-negative finite number");return e}function ye(e,t,i){if("string"!==typeof e||!i.some(t=>t===e))throw new G(t,"must be one of ".concat(i.map(e=>'"'.concat(e,'"')).join(", ")));return e}function Se(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const s=ue(e,t,{nonBlank:!0});if(s!==s.trim()||/[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]/.test(s))throw new G(t,"must not contain whitespace");let n;try{n=new URL(s)}catch(a){throw new G(t,"must be a valid absolute URL")}if("https:"!==n.protocol)throw new G(t,"must use the https: protocol");if(n.username||n.password)throw new G(t,"must not contain credentials");if(i.relaxed)return n.toString();if(n.search||n.hash)throw new G(t,"must not contain a query or fragment");if(!n.pathname.toLocaleLowerCase().endsWith(".mp4"))throw new G(t,"path must end with .mp4");return n.toString()}var be=i(60689);class fe extends Error{constructor(e){super("Invalid playback commit: ".concat(e)),this.code=e,this.name="PlaybackCommitError"}}const _e="history-",Te={billingState:null,billingPriceEnergy:null,billingPeriodSeconds:null,isBillingContinuing:!1,showFreeTimeEnded:!1},Ie={phase:"connecting",hasStreamStarted:!1,needsResumeGesture:!1,canStart:!1,muted:!1,chatMessages:[],suggestions:[],customTipSuggestions:[],customTipSuggestionsRowId:null,customTipSuggestionsLanguage:"",pendingCustomTipChip:null,notice:null,recoverableMessage:null,fatalError:null,fatalAction:null,fatalKind:null,badgeView:null,
1stateTrack:[],isIdleInterrupting:!1,isCustomInterrupting:!1,isReconnecting:!1,isOffline:!1,isMessageSending:!1,isMessageQueued:!1,isAwaitingCommit:!1,isReplyRevealPending:!1,billingState:null,billingPriceEnergy:null,billingPeriodSeconds:null,isBillingContinuing:!1,showFreeTimeEnded:!1,tips:null,progress:null,isAwaitingReply:!1,animateTipButton:!1,isClipPlaying:!1,isTipPending:!1,customTipsEnabled:!1,customTipPrice:null,messagePrice:null,speakers:[],customTipSubmitStatus:"idle",isCustomCutting:!1};class Ce{constructor(e){var t,i,s,n;this.options=e,this.state=Ie,this.listeners=new Set,this.timers=new w,this.playback=void 0,this.createSocket=void 0,this.now=void 0,this.random=void 0,this.socket=null,this.socketGeneration=0,this.operationGeneration=0,this.disposed=!1,this.started=!1,this.startPlaybackInFlight=!1,this.hasSessionOnSocket=!1,this.hasStartedCurrentSocket=!1,this.restoringSession=!1,this.durableSession=null,this.pendingMessageId=null,this.queuedMessage=null,this.pendingPlan=null,this.awaitingCommitPlanId=null,this.stateBadges=new Map,this.discoveredActions=new Map,this.delayedReply=null,this.delayedIdleInterrupt=null,this.tipResponseTimeout=null,this.tipRevealTimeout=null,this.customTipTimeout=null,this.pendingChipTip=null,this.spentChipRow=null,this.pendingChipTipTimeout=null,this.customCutTimeout=null,this.lastClipKind=null,this.reconnectAttempts=0,this.reconnectStartedAt=null,this.lastUserActivitySentAt=0,this.hasReceivedReply=!1,this.hasPaidBillingConsent=!1,this.streamName=void 0,this.heldChatReply=null,this.handleOnline=()=>{this.disposed||"fatal"===this.state.phase||null!==this.socket||(null===this.reconnectStartedAt&&(this.reconnectStartedAt=this.now()),this.patchState({phase:"connecting",isReconnecting:this.started,isOffline:!1}),this.scheduleReconnect(!0))},this.handleOffline=()=>{if(this.timers.clearReconnect(),"fatal"===this.state.phase)return;null===this.reconnectStartedAt&&(this.reconnectStartedAt=this.now());const e=this.discardUncommittedWork();this.invalidatePlaybackOperations(),this.abandonCurrentSocket(4001,"browser offline"),this.playback.suspend(),this.patchState((0,f.A)((0,f.A)({phase:"connecting",canStart:!1,isReconnecting:this.started,isOffline:!0,needsResumeGesture:!1},Te),xe(e,this.state.recoverableMessage)))},this.handleVisibilityChange=()=>{const e=!document.hidden;this.options.analytics.setVisible(e),e&&this.recoverAfterBackground()},this.handlePageShow=()=>{this.options.analytics.setVisible(!document.hidden),this.recoverAfterBackground()},this.streamName=(0,be.ZN)(null!==(t=e.streamId)&&void 0!==t?t:be.Ln),this.createSocket=null!==(i=e.createSocket)&&void 0!==i?i:(e,t)=>new WebSocket(e,t),this.now=null!==(s=e.now)&&void 0!==s?s:()=>performance.now(),this.random=null!==(n=e.random)&&void 0!==n?n:Math.random,this.playback=new M(e.videos,{activeTimeLeadSeconds:.5,onCanStartChange:e=>this.handleCanStartChange(e),onActiveTimeReached:e=>this.revealDelayedReply(e),onPlanCompleted:e=>this.handlePlanCompleted(e),onFailure:e=>this.handlePlaybackFailure(e),onClipStart:e=>{var t;"custom"!==e&&"custom"!==this.lastClipKind||this.pulseCustomCut(),this.lastClipKind=e,"idle"!==e&&this.patchState({isClipPlaying:!0});const i=this.pendingChipTip;"idle"!==e&&null!==i&&null!==i.planId&&(null===(t=this.pendingPlan)||void 0===t?void 0:t.planId)===i.planId&&this.clearPendingChipTip()}})}get snapshot(){return this.state}subscribe(e){return this.listeners.add(e),e(this.state),()=>this.listeners.delete(e)}start(){this.disposed||(window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline),window.addEventListener("pageshow",this.handlePageShow),document.addEventListener("visibilitychange",this.handleVisibilityChange),this.connect())}dispose(){this.disposed||(this.disposed=!0,this.timers.clearAll(),this.clearDelayedWork(),this.clearTipResponseTimeout(),this.clearTipRevealTimeout(),this.clearCustomTipTimeout(),this.clearPendingChipTip(),null!==this.customCutTimeout&&(clearTimeout(this.customCutTimeout),this.customCutTimeout=null),window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline),window.removeEventListener("pageshow",this.handlePageShow),document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.invalidatePlaybackOperations(),this.abandonCurrentSocket(1e3,"route exit"),this.playback.destroy(),this.listeners.clear())}async startPlayback(){return this.startPlaybackInternal(!0)}async startPlaybackInternal(e){if(this.disposed||"ready"!==this.state.phase||!this.state.canStart||this.restoringSession||this.startPlaybackInFlight)return;e&&ke(this.state.billingState)&&(this.hasPaidBillingConsent=!0);const t=this.operationGeneration;this.startPlaybackInFlight=!0;try{if(this.playback.setMuted(this.state.muted),await this.playback.start(),this.disposed||t!==this.operationGeneration||"ready"!==this.state.phase)return;if(!this.send({type:"stream_started"}))return void this.forceRecovery("stream_started_send_failed");this.hasStartedCurrentSocket=!0;const e=null!==this.reconnectStartedAt;this.started=!0,this.options.analytics.playbackStarted(),null!==this.durableSession&&this.options.analytics.stateActivated(this.durableSession.stateId),this.patchState({phase:"idle",hasStreamStarted:!0,needsResumeGesture:!1,isReconnecting:!1,isOffline:!1,notice:e?this.state.notice:null}),e?this.completeRecovery():this.reconnectAttempts=0}catch(i){if(this.disposed||t!==this.operationGeneration||"ready"!==this.state.phase)return;if(Re(i))return void this.patchState({needsResumeGesture:!0,isReconnecting:!1,isOffline:!1});this.enterFatal("retry","playback","playback_start_failed")}finally{t===this.operationGeneration&&(this.startPlaybackInFlight=!1)}}sendMessage(e){const t=e.trim();if(this.disposed||0===t.length||this.state.isReconnecting||Pe(this.state.billingState))return!1;const i=crypto.randomUUID(),s=this.pendingPlan;if("performing"===this.state.phase&&null!==s&&null===this.pendingMessageId&&null===this.queuedMessage){this.queuedMessage={id:i,text:t,wasAlreadySe
1nt:!1},this.patchState({isMessageQueued:!0,notice:null,suggestions:[]});const e=this.playback.secondsUntilPendingChoiceStarts();return null!==e&&e>4&&this.scheduleIdleInterrupt(s.planId),!0}return"idle"===this.state.phase&&!this.state.isMessageSending&&null===this.pendingMessageId&&null===this.pendingPlan&&null===this.queuedMessage&&(this.send({type:"user_message",messageId:i,text:t})?(this.pendingMessageId=i,this.appendChatMessage({id:i,sender:"user",text:t,durable:!1,planId:null}),this.options.analytics.messageSent("message"),this.patchState({phase:"thinking",isMessageSending:!0,isAwaitingReply:!0,notice:null,suggestions:[]}),this.startTurnResultTimeout(i),!0):(this.forceRecovery("message_send_failed"),!1))}continueChat(){if(this.disposed||this.state.isReconnecting||Pe(this.state.billingState)||"idle"!==this.state.phase||this.state.isMessageSending||null!==this.pendingMessageId||null!==this.pendingPlan||null!==this.queuedMessage)return!1;const e=crypto.randomUUID();return this.send({type:"continue",messageId:e})?(this.pendingMessageId=e,this.options.analytics.messageSent("continue"),this.patchState({phase:"thinking",isMessageSending:!0,isAwaitingReply:!0,notice:null,suggestions:[]}),this.startTurnResultTimeout(e),!0):(this.forceRecovery("message_send_failed"),!1)}buyTip(e){return this.disposed||this.state.isMessageSending||null!==this.pendingMessageId||null!==this.pendingPlan||null!==this.queuedMessage?(console.debug("[video-stream] buyTip rejected",{disposed:this.disposed,phase:this.state.phase,isMessageSending:this.state.isMessageSending,pendingMessageId:this.pendingMessageId,hasPendingPlan:null!==this.pendingPlan,hasQueuedMessage:null!==this.queuedMessage}),!1):(this.heldChatReply=null,this.send({type:"buy_tip",choiceId:e})?(this.startTipResponseTimeout(),this.patchState({isAwaitingReply:!1,isTipPending:!0,notice:null}),!0):(this.forceRecovery("tip_send_failed"),!1))}acknowledgeTipPrompt(){return!!this.send({type:"tip_prompt_acknowledged"})&&(this.patchState({animateTipButton:!1}),!0)}requestCustomTip(e){var t;const i=e.trim();if(0===i.length)return!1;const s=this.sendCustomTipRequest({type:"custom_tip_request",prompt:i});return s&&null===(null===(t=this.pendingChipTip)||void 0===t?void 0:t.clipId)&&this.clearPendingChipTip(),s}requestSuggestedCustomTip(e){const t=this.state.customTipSuggestions.find(t=>t.suggestionId===e);if(void 0===t)return!1;const i={suggestions:this.state.customTipSuggestions,rowId:this.state.customTipSuggestionsRowId};return this.patchState({customTipSuggestions:[],customTipSuggestionsRowId:null}),!!this.sendCustomTipRequest({type:"custom_tip_request",suggestionId:e})&&(this.spentChipRow=i,this.startPendingChipTip(t.chip),!0)}sendCustomTipRequest(e){return!(this.disposed||!this.state.customTipsEnabled||"pending"===this.state.customTipSubmitStatus)&&(this.send(e)?(this.startCustomTipTimeout(),this.patchState({customTipSubmitStatus:"pending",notice:null}),!0):(this.forceRecovery("custom_tip_send_failed"),!1))}resetCustomTipSubmit(){this.clearCustomTipTimeout(),"idle"!==this.state.customTipSubmitStatus&&this.patchState({customTipSubmitStatus:"idle"})}resetProgress(){return!this.disposed&&this.send({type:"reset_progress"})}deleteCustomTip(e){return!(this.disposed||!this.state.customTipsEnabled)&&this.send({type:"custom_tip_delete",clipId:e})}handleTipResult(e){var t,i,s,n,a,r,l,o,c,d,u,h,p,m,g;if(null===this.durableSession||null!==this.pendingPlan)return void this.rejectUnexpectedPlan(e.planId,"Unexpected tip playback plan.");if(!this.stagePlan(e.planId,e.playback,null))return;(null!==this.pendingChipTip&&this.pendingChipTip.clipId===e.choiceId&&(this.pendingChipTip.isBought=!0,this.pendingChipTip.planId=e.planId),this.startTipResponseTimeout(),null!==e.energyBalance)&&(null===(m=(g=this.options).onBalanceChange)||void 0===m||m.call(g,e.energyBalance));const v=e.choiceId===(null===(t=this.state.tips)||void 0===t||null===(i=t.nextState)||void 0===i?void 0:i.choiceId),y=null===(s=this.state.tips)||void 0===s?void 0:s.actions.find(t=>t.choiceId===e.choiceId),S=null===(n=this.state.tips)||void 0===n||null===(a=n.customActions)||void 0===a?void 0:a.find(t=>t.clipId===e.choiceId),b=v?null===(r=this.state.tips)||void 0===r||null===(l=r.nextState)||void 0===l?void 0:l.label:null!==(o=null===y||void 0===y?void 0:y.label)&&void 0!==o?o:null===S||void 0===S?void 0:S.label;b&&this.appendChatMessage({id:"tip-".concat(e.planId),sender:"user",text:"Tip sent: ".concat(b),durable:!0,planId:null}),this.options.analytics.tipActivated(null!==b&&void 0!==b?b:e.choiceId,null!==(c=v?null===(d=this.state.tips)||void 0===d||null===(u=d.nextState)||void 0===u?void 0:u.tipPrice:null===y||void 0===y?void 0:y.tipPrice)&&void 0!==c?c:0,null!==(h=null===(p=this.durableSession)||void 0===p?void 0:p.stateId)&&void 0!==h?h:"unknown"),this.patchState({phase:"performing",isAwaitingReply:!0,notice:null,progress:v&&null!==this.state.progress?(0,f.A)((0,f.A)({},this.state.progress),{},{messagesInState:0,complete:!1}):this.state.progress}),S&&this.scheduleIdleInterrupt(e.planId,{custom:!0})}handleChatReply(e){var t,i;null!==e.energyBalance&&(null===(t=(i=this.options).onBalanceChange)||void 0===t||t.call(i,e.energyBalance));null===e.messageId?this.clearTipResponseTimeout():this.timers.clearOperationTimeout(),null!==e.messageId&&this.pendingMessageId===e.messageId&&(this.pendingMessageId=null);const s=()=>{var t;this.state.isTipPending&&this.patchState({isTipPending:!1}),null!==e.messageId&&this.updateChatMessages(t=>
1t.id===e.messageId?(0,f.A)((0,f.A)({},t),{},{durable:!0}):t);const i=Date.now(),s=null!==(t=e.replies)&&void 0!==t?t:[{speakerId:null,text:e.replyText}];this.patchState({chatMessages:[...this.state.chatMessages,...s.map((e,t)=>({id:0===t?"assistant-".concat(i):"assistant-".concat(i,"-").concat(t),sender:"assistant",text:e.text,durable:!0,planId:null,speakerId:e.speakerId}))]}),this.patchState({phase:null===this.pendingPlan?"idle":this.state.phase,isMessageSending:!1,isAwaitingReply:!1,animateTipButton:e.animateTipButton}),this.tryAutoPlayPendingChip()};if(null===this.pendingPlan||null!==this.awaitingCommitPlanId)return null!==this.pendingPlan?(this.patchState({isAwaitingReply:!0}),void this.scheduleTipReveal(s)):void s();this.heldChatReply=s}resync(e){return!(this.disposed||!this.started||"fatal"===this.state.phase)&&("connecting"!==this.state.phase&&(this.forceRecovery(e),!0))}continueBilling(){return!(this.disposed||!Pe(this.state.billingState)||this.state.isBillingContinuing)&&(this.send({type:"billing_continue"})?(this.hasPaidBillingConsent=!0,this.patchState({isBillingContinuing:!0}),!0):(this.forceRecovery("billing_continue_send_failed"),!1))}notifyUserActivity(){const e=Date.now();"idle"!==this.state.phase||Pe(this.state.billingState)||e-this.lastUserActivitySentAt<2e3||this.send({type:"user_activity"})&&(this.lastUserActivitySentAt=e)}setMuted(e){this.playback.setMuted(e),this.patchState({muted:e})}retry(){if(this.disposed)return;this.options.analytics.clearTerminalReason(),this.timers.clearAll(),this.reconnectAttempts=0,this.reconnectStartedAt=this.now(),this.invalidatePlaybackOperations(),this.abandonCurrentSocket(4001,"manual retry"),this.playback.suspend();const e=this.discardUncommittedWork();this.patchState((0,f.A)((0,f.A)({phase:"connecting",canStart:!1,needsResumeGesture:!1,fatalError:null,fatalAction:null,fatalKind:null,isReconnecting:this.started,isOffline:!navigator.onLine},Te),xe(e,this.state.recoverableMessage))),this.scheduleReconnect(!0)}recoverSession(){this.options.onSessionInvalid()}takeRecoverableMessage(){const e=this.state.recoverableMessage;return null!==e&&this.patchState({recoverableMessage:null,notice:null}),e}connect(){if(this.disposed||null!==this.socket)return;if(!navigator.onLine)return void this.patchState({phase:"connecting",isReconnecting:this.started,isOffline:!0});let e;this.timers.clearReconnect(),this.timers.clearConnectionTimeouts(),this.hasSessionOnSocket=!1;let t=!1;try{var i;const s=this.options.getAccessToken();if(!s)return void this.enterFatal("signin","authentication","missing_session");t=!0;const n=null!==(i=this.options.streamId)&&void 0!==i?i:be.Ln,a=function(e,t){const i=new URL(t?"".concat(e,"/").concat(t):e);return i.protocol="https:"===i.protocol?"wss:":"ws:",i.toString()}(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://api.botify.ai/chatbot/v2",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{NODE_ENV:"production",PUBLIC_URL:"",WDS_SOCKET_HOST:void 0,WDS_SOCKET_PATH:void 0,WDS_SOCKET_PORT:void 0,FAST_REFRESH:!0,REACT_APP_SENTRY_DSN:"https://[email protected]/23",REACT_APP_USE_THEME:"botify",REACT_APP_WEB_API_URL:"https://api.exh.ai/strapi-secondary/api",REACT_APP_WEB_API_TOKEN:"84a16cdbe4a1ec91fb1b9f300cedcaa137374d78afb7a93271166584261e22b4722442bb8df0cf3f6fa9d575c24df8ce5a2b419fa9de11c6220ec2933cbb777fe6cceb1b4bdb1b8c0739722ec0a3645f26d2f1baf2b07461cb53aa930c35bb55a8c74c505e6646b39c1db8201322ef77b2da36c89f59667f6befb5f412a05596",REACT_APP_PRODUCT_NAME:"Botify AI",REACT_APP_AMPLITUDE_KEY:"cd80b9d1ba0f68979987279bdaaa80f4",REACT_APP_CHATBOT_API_TOKEN:"eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6ImJvdGlmeS13ZWItdjMifQ.O-w89I5aX2OE_i4k6jdHZJEDWECSUfOb1lr9UdVH4oTPMkFGUNm9BNzoQjcXOu8NEiIXq64-481hnenHdUrXfg",REACT_APP_USERS_API_URL:"https://api.botify.ai/chatbot/v2",REACT_APP_SUPPORT_EMAIL:"[email protected]",REACT_APP_TOS_LINK:"/terms-of-service",REACT_APP_PRIVACY_LINK:"/privacy-policy",REACT_APP_METRICS_API_URL:"https://api.exh.ai/strapi/bm",REACT_APP_METRICS_API_KEY:"2c60fa57a44917c339757eab441428047b30a996b5f93f0b0460b4ab8d18157d",REACT_APP_AMPLITUDE_PROXY_URL:"https://edge.botify.ai"}.REACT_APP_STREAMING_BACKEND_ORIGIN;if(void 0!==t)return"".concat(Y(K(t,"REACT_APP_STREAMING_BACKEND_ORIGIN")),"/ws");const i=K(null!==e&&void 0!==e?e:"https://api.botify.ai/chatbot/v2","REACT_APP_USERS_API_URL");return"".concat(Y(i),"/stream/ws")}(),n===be.Ln?void 0:n);e=this.createSocket(a,function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(0===e.length)throw new G("accessToken","must not be empty");const i=(new TextEncoder).encode(e);let s="";for(const a of i)s+=String.fromCharCode(a);const n=btoa(s).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");return[q,"video-stream-suggestions-v1","video-stream-custom-tips-v1","video-stream-custom-tip-suggestions-v1","video-stream-group-chat-v1",...t.perMessageBilling?["video-stream-per-message-billing-v1"]:[],"".concat("base64.websocket.bearer.").concat(n)]}(s,{perMessageBilling:!0===this.options.perMessageBilling}))}catch(n){const e=t?"configuration":"authentication";return void this.enterFatal("authentication"===e?"signin":"retry",e,"authentication"===e?"missing_session":"invalid_backend_origin")}this.socket=e;const s=++this.socketGeneration;this.patchState({phase:"connecting",isOffline:!1}),this.timers.startConnectTimeout(1e4,()=>{this.isCurrentSocket(e,s)&&(this.options.analytics.error("connection","connect_timeout"),this.beginRecovery())}),e.addEventListener("open",()=>{this.isCurrentSocket(e,s)&&(this.timers.clearConnectTimeout(),e.protocol===q?this.timers.startSessionReadyTimeout(1e4,()=>{this.isCurrentSocket(e,s)&&!this.hasSessionOnSocket&&(this.options.analytics.error("connection","session_ready_timeout"),this.beginRecovery())}):this.enterFatal("signin","protocol","unsupported_subprotocol"))}),e.addEventListener("message",t=>{if(this.isCurrentSocket(e,s)&&"fatal"!==this.state.phase)try{this.handleServerMessage(Q(t.data),s)}
1catch(i){this.enterFatal("retry","protocol","invalid_server_message")}}),e.addEventListener("error",()=>{this.isCurrentSocket(e,s)&&this.options.analytics.error("connection","socket_error")}),e.addEventListener("close",t=>{this.isCurrentSocket(e,s)&&(this.abandonCurrentSocket(),this.disposed||"fatal"===this.state.phase||this.handleSocketClose(t.code))})}handleServerMessage(e,t){var i,s,n;switch(e.type){case"session_ready":return void this.handleSessionReady(e,t);case"playback_committed":return void this.handlePlaybackCommitted(e);case"billing_status":return void this.handleBillingStatus(e);case"chat_history":if(!this.hasSessionOnSocket||this.state.chatMessages.length>0)return;return this.hasReceivedReply=!0,void this.patchState({chatMessages:e.messages.map((e,t)=>({id:"".concat(_e).concat(t),sender:e.sender,text:e.text,durable:!0,planId:null,speakerId:e.speakerId}))});case"opening_message":if(!this.hasSessionOnSocket||this.hasReceivedReply)return;return this.hasReceivedReply=!0,void(null!==(i=e.replies)&&void 0!==i?i:[{speakerId:null,text:e.replyText}]).forEach((e,t)=>{this.appendChatMessage({id:0===t?"assistant-opening":"assistant-opening-".concat(t),sender:"assistant",text:e.text,durable:!0,planId:null,speakerId:e.speakerId})});case"custom_tip_suggestions":return this.spentChipRow=null,void this.patchState({customTipSuggestions:e.suggestions,customTipSuggestionsRowId:e.rowId,customTipSuggestionsLanguage:e.language});case"suggestions":if(!this.hasSessionOnSocket||!this.state.hasStreamStarted||this.state.isMessageSending||this.state.isMessageQueued||null!==(null!==(s=null===(n=this.pendingPlan)||void 0===n?void 0:n.messageId)&&void 0!==s?s:null))return;return void this.patchState({suggestions:e.suggestions});case"turn_result":return void this.handleTurnResult(e);case"chat_reply":return void this.handleChatReply(e);case"tip_result":return void this.handleTipResult(e);case"progress_reset":return this.hasReceivedReply=!1,this.delayedReply=null,this.patchState({chatMessages:[],isReplyRevealPending:!1}),void this.beginRecovery();case"custom_tip_result":var a,r;if(this.clearCustomTipTimeout(),this.spentChipRow=null,null!==e.energyBalance)null===(a=(r=this.options).onBalanceChange)||void 0===a||a.call(r,e.energyBalance);return"pending"===this.state.customTipSubmitStatus&&this.patchState({customTipSubmitStatus:"accepted"}),void(null!==this.pendingChipTip&&null===this.pendingChipTip.clipId&&(this.pendingChipTip.clipId=e.clipId,this.syncPendingChipTip()));case"progress":return void this.patchState({progress:e});case"tips":return this.patchState({tips:e}),void this.syncPendingChipTip();case"proactive_result":return void this.handleProactiveResult(e.planId,e.playback);case"error":this.handleServerError(e)}}handleBillingStatus(e){var t,i;null!==e.balance&&(null===(t=(i=this.options).onBalanceChange)||void 0===t||t.call(i,e.balance));const s="free"===this.state.billingState&&"payment_required"===e.state,n="payment_required"===e.state&&this.state.isBillingContinuing,a="payment_required"===e.state&&!s&&!n&&this.hasStartedCurrentSocket&&this.hasPaidBillingConsent;!a||this.send({type:"billing_continue"})?(this.patchState({billingState:e.state,billingPriceEnergy:e.priceEnergy,billingPeriodSeconds:e.periodSeconds,isBillingContinuing:n||a,showFreeTimeEnded:"payment_required"===e.state&&(s||this.state.showFreeTimeEnded)}),"paid"===e.state&&null!==this.queuedMessage&&null===this.pendingPlan&&null===this.awaitingCommitPlanId&&"idle"===this.state.phase&&this.sendQueuedMessage(this.state.badgeView),this.tryAutoPlayPendingChip()):this.forceRecovery("billing_continue_send_failed")}handleSessionReady(e,t){var i,s;if(this.hasSessionOnSocket)return void this.enterFatal("retry","protocol","duplicate_session_ready");this.hasSessionOnSocket=!0,this.timers.clearSessionReadyTimeout();const n=new Map(e.stateBadges.map(e=>[e.stateId,e])),a=n.get(e.stateId);if(!a)return void this.enterFatal("retry","protocol","missing_state_badge");if(this.stateBadges=n,this.discoveredActions=new Map(Object.entries(e.discoveredActionIdsByState).map(e=>{let t=(0,_.A)(e,2),i=t[0],s=t[1];return[i,new Set(s)]})),this.durableSession={revision:e.revision,stateId:e.stateId,anchorId:e.anchorId},this.patchState({badgeView:(0,f.A)((0,f.A)({},a),{},{discovered:null!==(i=null===(s=this.discoveredActions.get(e.stateId))||void 0===s?void 0:s.size)&&void 0!==i?i:0}),stateTrack:e.stateBadges,animateTipButton:e.animateTipButton,customTipsEnabled:e.customTipsEnabled,customTipPrice:e.customTipPrice,messagePrice:e.messagePrice,speakers:e.speakers}),!this.started)return void this.playback.loadSession(e);const r=this.operationGeneration;this.restoringSession=!0,this.playback.restoreSession(e).then(()=>
1{if(!this.disposed&&t===this.socketGeneration&&r===this.operationGeneration)return this.restoringSession=!1,this.patchState({phase:"ready",canStart:this.playback.canStart}),this.startPlaybackInternal(!1)}).catch(e=>{this.disposed||t!==this.socketGeneration||r!==this.operationGeneration||"fatal"===this.state.phase||(this.restoringSession=!1,Re(e)?this.patchState({phase:"ready",canStart:this.playback.canStart,needsResumeGesture:!0,isReconnecting:!1,isOffline:!1}):this.enterFatal("retry","playback","restore_failed"))})}handleTurnResult(e){if("thinking"!==this.state.phase||this.pendingMessageId!==e.messageId||null===this.durableSession)return void this.rejectUnexpectedPlan(e.planId,"Unexpected message playback plan.");if(this.timers.clearOperationTimeout(),!this.stagePlan(e.planId,e.playback,e.messageId))return;this.pendingMessageId=null,this.updateChatMessages(t=>t.id===e.messageId?(0,f.A)((0,f.A)({},t),{},{planId:e.planId}):t),this.patchState({phase:"performing",isMessageSending:!1,isAwaitingReply:!1,notice:null}),this.hasReceivedReply?(this.delayedReply={planId:e.planId,text:e.replyText},this.patchState({isReplyRevealPending:!0})):(this.hasReceivedReply=!0,this.appendChatMessage({id:"assistant-".concat(e.planId),sender:"assistant",text:e.replyText,durable:!1,planId:e.planId}));const t=this.playback.secondsUntilPendingChoiceStarts();null!==t&&t>4&&this.scheduleIdleInterrupt(e.planId)}handleProactiveResult(e,t){const i="thinking"===this.state.phase&&null!==this.pendingMessageId&&null===this.pendingPlan;if(i){const t=this.state.chatMessages.find(e=>e.id===this.pendingMessageId&&"user"===e.sender);if(!t||null===this.pendingMessageId||null!==this.queuedMessage)return void this.rejectUnexpectedPlan(e,"A proactive plan crossed an unavailable message.");this.timers.clearOperationTimeout(),this.queuedMessage={id:this.pendingMessageId,text:t.text,wasAlreadySent:!0},this.pendingMessageId=null}"idle"!==this.state.phase&&!i||null!==this.pendingMessageId||null!==this.pendingPlan||null===this.durableSession?this.rejectUnexpectedPlan(e,"Unexpected proactive playback plan."):this.stagePlan(e,t,null)&&this.patchState({phase:"performing",isMessageSending:!1,isMessageQueued:i||this.state.isMessageQueued,notice:null})}stagePlan(e,t,i){var s,n;try{if(!function(e,t){return t.has(e.start.stateId)&&t.has(e.end.stateId)}(t,this.stateBadges))throw new Error("Playback plan references missing state metadata.");this.playback.stagePlan(e,t)}catch(a){return this.send({type:"playback_failed",planId:e,reason:we(a)}),this.enterFatal("retry","playback","invalid_playback_plan"),!1}return this.pendingPlan={planId:e,baseRevision:null!==(s=null===(n=this.durableSession)||void 0===n?void 0:n.revision)&&void 0!==s?s:0,destination:(0,f.A)({},t.end),playback:t,messageId:i},!0}handlePlanCompleted(e){var t;if(this.disposed||(null===(t=this.pendingPlan)||void 0===t?void 0:t.planId)!==e||null!==this.awaitingCommitPlanId)this.enterFatal("retry","persistence","unexpected_plan_completion");else{if(this.revealDelayedReply(e),this.clearDelayedReply(),this.clearDelayedIdleInterrupt(),this.patchState({isClipPlaying:!1}),null!==this.heldChatReply){const e=this.heldChatReply;this.heldChatReply=null,this.patchState({isAwaitingReply:!0}),this.scheduleTipReveal(e)}this.send({type:"playback_completed",planId:e})?(this.awaitingCommitPlanId=e,this.patchState({isAwaitingCommit:!0,isIdleInterrupting:!1,isCustomInterrupting:!1}),this.timers.startOperationTimeout(1e4,()=>{this.awaitingCommitPlanId===e&&this.forceRecovery("playback_commit_timeout")})):this.forceRecovery("playback_completion_send_failed")}}handlePlaybackCommitted(e){var t,i,s,n,a,r,l,o;const c=this.pendingPlan;if(null===c||this.awaitingCommitPlanId!==e.planId||null===this.durableSession)return void this.enterCommitConflict();let d;try{d=function(e,t){if(t.planId!==e.planId)throw new fe("plan");if(t.revision<=e.baseRevision)throw new fe("revision");if(t.stateId!==e.destination.stateId||t.anchorId!==e.destination.anchorId)throw new fe("position");return{revision:t.revision,stateId:t.stateId,anchorId:t.anchorId}}(c,e)}catch(g){return void this.enterCommitConflict()}const u=null!==(t=null===(i=this.durableSession)||void 0===i?void 0:i.stateId)&&void 0!==t?t:null;this.durableSession=d,this.timers.clearOperationTimeout();const h=this.stateBadges.get(d.stateId);if(!h||e.discoveredActionIds.length>h.actionTotal)return void this.enterCommitConflict();this.discoveredActions.set(d.stateId,new Set(e.discoveredActionIds)),this.patchState({chatMessages:this.state.chatMessages.map(t=>t.planId===e.planId?(0,f.A)((0,f.A)({},t),{},{durable:!0}):t).slice(-8)}),this.pendingPlan=null,this.awaitingCommitPlanId=null,(null===(s=this.pendingChipTip)||void 0===s?void 0:s.planId)===e.planId&&this.clearPendingChipTip();const p=c.playback.choiceId===(null===(n=this.state.tips)||void 0===n||null===(a=n.nextState)||void 0===a?void 0:a.choiceId)?null===(r=this.state.tips)||void 0===r?void 0:r.nextState:null===(l=this.state.tips)||void 0===l?void 0:l.actions.find(e=>e.choiceId===c.playback.choiceId);this.options.analytics.playbackCommitted(null!==(o=null===p||void 0===p?void 0:p.label)&&void 0!==o?o:c.playback.choiceId,c.playback.choiceId,d.stateId,c.playback.clips.length),null!==u&&d.stateId!==u&&this.options.analytics.stateActivated(d.stateId);const m=(0,f.A)((0,f.A)({},h),{},{discovered:e.discoveredActionIds.length});null===this.queuedMessage||Pe(this.state.billingState)?(this.patchState({phase:"idle",isAwaitingCommit:!1,isIdleInterrupting:!1,isCustomInterrupting:!1,isMessageQueued:null!==this.queuedMessage,isMessageSending:!1,notice:null,badgeView:m}),this.tryAutoPlayPendingChip()):this.sendQueuedMessage(m)}sendQueuedMessage(e){const t=this.queuedMessage;null!==t&&(this.send({type:"user_message",messageId:t.id,text:t.text})?(this.queuedMessage=null,this.pendingMessageId=t.id,t.wasAlreadySe
1nt||(this.appendChatMessage({id:t.id,sender:"user",text:t.text,durable:!1,planId:null}),this.options.analytics.messageSent("message")),this.patchState({phase:"thinking",isAwaitingCommit:!1,isIdleInterrupting:!1,isCustomInterrupting:!1,isMessageQueued:!1,isMessageSending:!0,notice:null,badgeView:e,suggestions:[]}),this.startTurnResultTimeout(t.id)):this.forceRecovery("queued_message_send_failed"))}handleServerError(e){var t;if("pending"===this.state.customTipSubmitStatus){this.clearCustomTipTimeout(),this.clearPendingChipTip(),this.restoreSpentChipRow();const t="subscription_required"===e.code||"insufficient_energy"===e.code;this.patchState({customTipSubmitStatus:t?"idle":"failed"})}const i="stale_progress"===e.code||"progress_unavailable"===e.code?"persistence":"connection";if("billing_not_available"===e.code)return this.options.analytics.error(i,e.code),void this.beginRecovery();if("stale_progress"===e.code||"progress_unavailable"===e.code)return this.options.analytics.error(i,e.code),void this.beginRecovery();if("playback_pending"!==e.code){if("subscription_required"===e.code||"insufficient_energy"===e.code){var s;this.options.analytics.error("connection",e.code),this.timers.clearOperationTimeout(),this.clearTipResponseTimeout(),this.clearCustomTipTimeout();const t=null===this.pendingMessageId?null:null!==(s=this.state.chatMessages.find(e=>e.id===this.pendingMessageId&&"user"===e.sender))&&void 0!==s?s:null;var n,a,r,l;if(this.pendingMessageId=null,null!==t&&this.removeUncommittedChat(),this.patchState((0,f.A)({phase:"idle",isMessageSending:!1,isTipPending:!1,isAwaitingReply:!1,customTipSubmitStatus:"idle"},null===t?{}:{recoverableMessage:t.text,notice:"Add energy to send that message."})),"subscription_required"===e.code)null===(n=(a=this.options).onSubscriptionRequired)||void 0===n||n.call(a);else null===(r=(l=this.options).onInsufficientEnergy)||void 0===r||r.call(l);return}if("payment_required"===e.code&&"thinking"===this.state.phase&&null!==this.pendingMessageId&&null===this.pendingPlan&&null===this.queuedMessage){const e=this.state.chatMessages.find(e=>e.id===this.pendingMessageId&&"user"===e.sender);if(e){const t=Pe(this.state.billingState)?this.state.billingState:"payment_required",i="free"===this.state.billingState&&"payment_required"===t;return this.timers.clearOperationTimeout(),this.queuedMessage={id:e.id,text:e.text,wasAlreadySent:!0},this.pendingMessageId=null,void this.patchState({phase:"idle",billingState:t,showFreeTimeEnded:i||this.state.showFreeTimeEnded,isBillingContinuing:!1,isMessageSending:!1,isMessageQueued:!0,notice:null})}}if(e.retryable&&(null===(t=this.socket)||void 0===t?void 0:t.readyState)===WebSocket.OPEN){if("thinking"===this.state.phase){var o;this.options.analytics.error(i,e.code);const t=this.discardUncommittedWork();return this.patchState({phase:"idle",isMessageSending:!1,notice:Me(e.code,this.streamName),recoverableMessage:null!==(o=t.recoverableMessage)&&void 0!==o?o:this.state.recoverableMessage}),void this.tryAutoPlayPendingChip()}if("idle"===this.state.phase)return this.options.analytics.error(i,e.code),void this.patchState({notice:Me(e.code,this.streamName)})}this.enterFatal("retry",i,e.code)}}handlePlaybackFailure(e){this.disposed||"fatal"===this.state.phase||(null!==e.planId&&this.send({type:"playback_failed",planId:e.planId,reason:e.reason}),this.enterFatal("retry","playback","media_failure"))}handleSocketClose(e){1008!==e?this.beginRecovery():this.enterFatal("signin","authentication","policy_violation")}beginRecovery(){this.invalidatePlaybackOperations(),this.abandonCurrentSocket(4001,"frontend recovery"),null===this.reconnectStartedAt&&(this.reconnectStartedAt=this.now());const e=this.discardUncommittedWork();this.playback.suspend(),this.patchState((0,f.A)((0,f.A)({phase:"connecting",canStart:!1,isReconnecting:this.started,isOffline:!navigator.onLine,needsResumeGesture:!1},Te),xe(e,this.state.recoverableMessage))),this.scheduleReconnect(!1)}scheduleReconnect(e){if(this.disposed||"fatal"===this.state.phase||!navigator.onLine)return;if(this.reconnectAttempts>=5)return void this.enterFatal("retry","connection","retry_exhausted","retry_exhausted");const t=this.reconnectAttempts+1,i=Math.min(8e3,500*2**(t-1)),s=e?0:i+Math.floor(250*this.random());this.timers.scheduleReconnect(s,()=>{!this.disposed&&navigator.onLine&&null===this.socket&&(this.reconnectAttempts=t,this.connect())})}completeRecovery(){null!==this.reconnectStartedAt&&(this.options.analytics.reconnectCompleted(),this.reconnectStartedAt=null,this.reconnectAttempts=0,this.options.analytics.clearTerminalReason())}forceRecovery(e){this.options.analytics.error("connection",e),this.beginRecovery()}enterCommitConflict(){this.enterFatal("retry","persistence","commit_conflict")}enterFatal(e,t,i){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"session_error";if(this.disposed||"fatal"===this.state.phase)return;this.options.analytics.error(t,i),this.options.analytics.setTerminalReason(s),this.timers.clearAll(),this.clearDelayedWork(),this.invalidatePlaybackOperations();const n=this.discardUncommittedWork();this.playback.suspend(),this.abandonCurrentSocket(4e3,"frontend session stopped");const a="signin"===e?"session":"playback"===t?"video":"connection";this.patchState((0,f.A)({phase:"fatal",fatalError:Ae(a),fatalAction:e,fatalKind:a,canStart:!1,isReconnecting:!1,isOffline:!1,isMessageSending:!1,isMessageQueued:!1,isAwaitingCommit:!1,isIdleInterrupting:!1,isCustomInterrupting:!1,isReplyRevealPending:!1},xe(n,this.state.recoverableMessage)))}discardUncommittedWork(){var e,t,i,s,n,a;this.heldChatReply=null,this.clearTipResponseTimeout(),this.clearTipRevealTimeout(),this.clearCustomTipTimeout(),this.clearPendingChipTip(),this.spentChipRow=null,(this.state.isTipPending||this.state.isAwaitingReply)&&this.patchState({isTipPending:!1,isAwaitingReply:!1}),"pending"===this.state.customTipSubmitStatus&&this.patchState({customTipSubmitStatus:"idle"});const r=null!==(e=null!==(t=this.pendingMessageId)&&void 0!==t?t:null===(i=this.pendingPlan)||void 0===i?void 0:i.messageId)&&void 0!==e?e:null,l=null!==(s=this.queuedMessage)&&void 0!==s?s:null===r?null:null!==(n=this.state.chatMessages.find(e=>e.id===r&&"user"===e.sender))&&void 0!==n?n:null;return this.pendingMessageId=null,this.queuedMessage=null,this.pendingPlan=null,this.awaitingCommitPlanId=null,this.timers.clearOperationTimeout(),this.clearDelayedWork(),this.removeUncommittedChat(),this.clearCustomCut(),this.patchState({isMessageSending:!1,isMessageQueued:!1,isAwaitingCommit:!1,isIdleInterrupting:!1,isCustomInterrupting:!1,isReplyRevealPending:!1,isClipPlaying:!1,suggestions:[]}),{recoverableMessage:null!==(a=null===l||void 0===l?void 0:l.text)&&void 0!==a?a:null}}startTurnResultTimeout(e){this.timers.startOperationTimeout(45e3,()=>{this.pendingMessageId===e&&"thinking"===this.state.phase&&this.forceRecovery("turn_result_timeout")})}pulseCustomCut(){null!==this.customCutTimeout&&clearTimeout(this.customCutTimeout),this.patchState({isCustomCutting:!0}),this.customCutTimeout=setTimeout(()=>{this.customCutTimeout=null,this.patchState({isCustomCutting:!1})},700)}clearCustomCut(){null!==this.customCutTimeout&&(clearTimeout(this.customCutTimeout),this.customCutTimeout=null),this.lastClipKind=null,this.state.isCustomCutting&&this.patchState({isCustomCutting:!1})}startCustomTipTimeout(){this.clearCustomTipTimeout(),this.customTipTimeout=setTimeout(()=>{this.customTipTimeout=null,"pending"===this.state.customTipSubmitStatus&&this.patchState({customTipSubmitStatus:"failed"})},45e3)}clearCustomTipTimeout(){null!==this.customTipTimeout&&(clearTimeout(this.customTipTimeout),this.customTipTimeout=null)}restoreSpentChipRow(){const e=this.spentChipRow;this.spentChipRow=null,null===e||this.state.customTipSuggestions.length>0||this.patchState({customTipSuggestions:e.suggestions,customTipSuggestionsRowId:e.rowId})}startPendingChipTip(e){var t,i;this.clearPendingChipTip(),this.pendingChipTip={clipId:null,knownClipIds:new Set((null!==(t=null===(i=this.state.tips)||void 0===i?void 0:i.customActions)&&void 0!==t?t:[]).map(e=>e.clipId)),isListed:!1,isBought:!1,planId:null}
1,this.startPendingChipTimeout(45e3),this.patchState({pendingCustomTipChip:e})}startPendingChipTimeout(e){this.clearPendingChipTimeout(),this.pendingChipTipTimeout=setTimeout(()=>{this.pendingChipTipTimeout=null,this.clearPendingChipTip()},e)}clearPendingChipTimeout(){null!==this.pendingChipTipTimeout&&(clearTimeout(this.pendingChipTipTimeout),this.pendingChipTipTimeout=null)}clearPendingChipTip(){this.clearPendingChipTimeout(),this.pendingChipTip=null,null!==this.state.pendingCustomTipChip&&this.patchState({pendingCustomTipChip:null})}resolvePendingChipAction(){var e,t;const i=this.pendingChipTip;if(null===i)return;const s=null!==(e=null===(t=this.state.tips)||void 0===t?void 0:t.customActions)&&void 0!==e?e:[],n=s.find(e=>e.clipId===i.clipId);if(void 0!==n)return n;const a=s.find(e=>!i.knownClipIds.has(e.clipId));return void 0!==a&&(i.clipId=a.clipId),a}syncPendingChipTip(){const e=this.pendingChipTip,t=this.resolvePendingChipAction();null!==e&&void 0!==t&&("error"!==t.status?(e.isListed||(e.isListed=!0,this.startPendingChipTimeout(3e5)),"completed"===t.status&&this.tryAutoPlayPendingChip()):this.clearPendingChipTip())}tryAutoPlayPendingChip(){var e;const t=this.pendingChipTip;null===t||t.isBought||"completed"!==(null===(e=this.resolvePendingChipAction())||void 0===e?void 0:e.status)||null===t.clipId||"idle"!==this.state.phase||this.state.isTipPending||null!==this.queuedMessage||Pe(this.state.billingState)||this.buyTip(t.clipId)&&(t.isBought=!0)}startTipResponseTimeout(){this.clearTipResponseTimeout(),this.tipResponseTimeout=setTimeout(()=>{this.tipResponseTimeout=null,this.state.isTipPending&&this.forceRecovery("tip_response_timeout")},45e3)}clearTipResponseTimeout(){null!==this.tipResponseTimeout&&(clearTimeout(this.tipResponseTimeout),this.tipResponseTimeout=null)}scheduleTipReveal(e){this.clearTipRevealTimeout(),this.tipRevealTimeout=setTimeout(()=>{this.tipRevealTimeout=null,e()},420)}clearTipRevealTimeout(){null!==this.tipRevealTimeout&&(clearTimeout(this.tipRevealTimeout),this.tipRevealTimeout=null)}send(e){const t=this.socket;if((null===t||void 0===t?void 0:t.readyState)!==WebSocket.OPEN)return!1;try{return t.send(Z(e)),!0}catch(i){return!1}}rejectUnexpectedPlan(e,t){this.send({type:"playback_failed",planId:e,reason:t}),this.enterFatal("retry","protocol","unexpected_plan")}scheduleIdleInterrupt(e,t){this.clearDelayedIdleInterrupt();const i=null!==t&&void 0!==t&&t.custom?1e3:Math.floor(180+141*this.random());this.delayedIdleInterrupt=setTimeout(()=>{var i;if(this.delayedIdleInterrupt=null,this.disposed||(null===(i=this.pendingPlan)||void 0===i?void 0:i.planId)!==e)return;const s=this.operationGeneration;this.patchState({isIdleInterrupting:!0,isCustomInterrupting:Boolean(null===t||void 0===t?void 0:t.custom)}),this.playback.startPendingPlanNow(480).then(()=>{var t;this.disposed||s!==this.operationGeneration||(null===(t=this.pendingPlan)||void 0===t?void 0:t.planId)!==e||this.patchState({isIdleInterrupting:!1,isCustomInterrupting:!1})}).catch(t=>{var i;this.disposed||s!==this.operationGeneration||(null===(i=this.pendingPlan)||void 0===i?void 0:i.planId)!==e||"fatal"===this.state.phase||this.handlePlaybackFailure({planId:e,reason:we(t)})})},i)}revealDelayedReply(e){var t;if((null===(t=this.delayedReply)||void 0===t?void 0:t.planId)!==e)return;const i=this.delayedReply;this.delayedReply=null,this.appendChatMessage({id:"assistant-".concat(e),sender:"assistant",text:i.text,durable:!1,planId:e}),this.patchState({isReplyRevealPending:!1})}handleCanStartChange(e){if(this.disposed)return;const t={canStart:e};!e||"connecting"!==this.state.phase||this.started||this.restoringSession||(t.phase="ready",t.isReconnecting=!1,t.notice=null),this.patchState(t)}appendChatMessage(e){this.patchState({chatMessages:[...this.state.chatMessages,e]})}updateChatMessages(e){this.patchState({chatMessages:this.state.chatMessages.map(e)})}removeUncommittedChat(){this.patchState({chatMessages:this.state.chatMessages.filter(e=>e.durable)})}clearDelayedReply(){this.delayedReply=null,this.state.isReplyRevealPending&&this.patchState({isReplyRevealPending:!1})}clearDelayedIdleInterrupt(){null!==this.delayedIdleInterrupt&&(clearTimeout(this.delayedIdleInterrupt),this.delayedIdleInterrupt=null)}clearDelayedWork(){this.clearDelayedReply(),this.clearDelayedIdleInterrupt()}invalidatePlaybackOperations(){this.operationGeneration+=1,this.restoringSession=!1,this.startPlaybackInFlight=!1}abandonCurrentSocket(e,t){const i=this.socket;if(null!==i&&(this.socket=null,this.socketGeneration+=1,this.hasSessionOnSocket=!1,this.hasStartedCurrentSocket=!1,this.timers.clearConnectionTimeouts(),void 0!==e&&(i.readyState===WebSocket.OPEN||i.readyState===WebSocket.CONNECTING)))try{i.close(e,t)}catch(s){}}isCurrentSocket(e,t){return!this.disposed&&this.socket===e&&this.socketGeneration===t}patchState(e){this.disposed||(this.state=(0,f.A)((0,f.A)({}
1,this.state),e),this.listeners.forEach(e=>e(this.state)))}recoverAfterBackground(){if(this.disposed||!this.started)return;if("fatal"===this.state.phase)return void("video"===this.state.fatalKind&&this.retry());const e=this.socket;null!==e?e.readyState!==WebSocket.CONNECTING&&(e.readyState===WebSocket.OPEN?this.playback.isPlaying||this.resumeAfterBackground(e):this.forceRecovery("background_socket_interrupted")):this.beginRecovery()}async resumeAfterBackground(e){const t=await this.playback.resume();this.disposed||this.socket!==e||e.readyState!==WebSocket.OPEN||"fatal"===this.state.phase||t||this.forceRecovery("background_playback_interrupted")}}function Pe(e){return"payment_required"===e||"insufficient_energy"===e||"unavailable"===e}function ke(e){return"payment_required"===e||"paid"===e}function we(e){return(e instanceof Error?e.message:"Unknown playback error.").slice(0,500)}function xe(e,t){var i;const s=null!==(i=e.recoverableMessage)&&void 0!==i?i:t;return{recoverableMessage:s,notice:null!==s?"Your last message wasn\u2019t completed.":null}}function Ae(e){switch(e){case"session":return"Your session has expired.";case"video":return"Try again to continue the stream.";case"connection":return"Check your connection and try again."}}function Re(e){return"object"===typeof e&&null!==e&&"name"in e&&"NotAllowedError"===e.name}function Me(e,t){switch(e){case"model_timeout":return"".concat(t," took too long to respond. You can try another message.");case"model_unavailable":return"".concat(t," is briefly unavailable. You can try again.");case"model_refusal":return"".concat(t," couldn\u2019t respond to that request. Try asking another way.");default:return"That message could not be completed. You can try again."}}const Ee=6e3,Be=[.88,1.06,.95,1.14,.91];function je(e,t,i){const n=(0,s.useRef)(new Map);return(0,s.useEffect)(()=>{const t=new Set(e.map(e=>e.id));n.current.forEach((e,i)=>{t.has(i)||n.current.delete(i)})},[e]),e=>{if("assistant"!==e.sender||!t||function(){var e,t,i;return null!==(e=null===(t=(i=window).matchMedia)||void 0===t?void 0:t.call(i,"(prefers-reduced-motion: reduce)").matches)&&void 0!==e&&e}())return null;const s=n.current.get(e.id);if((null===s||void 0===s?void 0:s.text)===e.text)return s;const a=function(e){var t;return null!==(t=e.map(e=>e.current).find(e=>"true"===(null===e||void 0===e?void 0:e.dataset.active)))&&void 0!==t?t:null}(i),r=function(e,t){var i;const s=null!==(i=e.match(/\s*\S+(?:\s+|$)/g))&&void 0!==i?i:[];if(s.length<2)return null;const n=s.slice(0,-1).map((e,t)=>function(e,t){const i=e.trim(),s=/[.!?\u2026]["'\u2019\u201d)]*$/.test(i)?260:/[,;:]["'\u2019\u201d)]*$/.test(i)?100:0,n=65+5*Math.min(i.length,12);return Math.round((n+s)*Be[t%Be.length]*1.2)}(e,t)),a=n.reduce((e,t)=>e+t,0),r=null===t?Ee:Math.max(0,t-600),l=Math.min(a,Ee,r),o=0===a?0:l/a;let c=0;const d=[0];return n.forEach(e=>{c+=e*o,d.push(c)}),{chunks:s,revealAtMs:d}}(e.text,function(e){if(null===e||!Number.isFinite(e.duration)||!Number.isFinite(e.currentTime)||!Number.isFinite(e.playbackRate)||e.playbackRate<=0)return null;return Math.max(0,e.duration-e.currentTime)/e.playbackRate*1e3}(a));if(null===r)return null;const l=(0,f.A)((0,f.A)({},r),{},{finished:!1,text:e.text,startedAtMs:performance.now(),video:a});return n.current.set(e.id,l),l}}function Ne(e,t){if(e.finished)return e.chunks.length;const i=t-e.startedAtMs;let s=0;for(;s<e.revealAtMs.length&&e.revealAtMs[s]<=i;)s+=1;return s}var Le=i(59063),Ve=i(75865);const Fe={name:"Ivy",voiceId:"zmcVlqmyk3Jpn5AVYcAL",provider:"inworld",cacheId:110},Oe={name:"Celeste",voiceId:"cgSgspJ2msm6clMCkdW9",provider:"inworld",cacheId:119},Ue={domina:Oe},De={"family-vacation":{mila:Oe,kira:Fe}};const $e=e=>"assistant"===e.sender&&!e.id.startsWith("assistant-opening")&&!e.id.startsWith("history-");function qe(e,t,i){var n;let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"emma";const r=(0,s.useRef)(null),l=(0,s.useRef)(null),o=(0,s.useRef)(new Set),c=(0,s.useRef)(!1),d=(0,s.useRef)(!1),u=(0,s.useState)(()=>new Set),h=(0,_.A)(u,2),p=h[0],m=h[1],g=(0,s.useState)(null),v=(0,_.A)(g,2),y=v[0],S=v[1],b=(0,s.useCallback)(e=>{m(t=>t.has(e)?t:new Set([...t,e]))},[]),f=(0,s.useCallback)(()=>
1(r.current||(r.current=new Audio,r.current.preload="auto"),r.current),[]),T=(0,s.useRef)(new Set),I=(0,s.useCallback)((e,t)=>{const i=setTimeout(()=>{T.current.delete(i),e()},t);return T.current.add(i),i},[]),C=(0,s.useCallback)(()=>{T.current.forEach(e=>clearTimeout(e)),T.current.clear()},[]),P=(0,s.useCallback)(()=>{var e,t;null===(e=l.current)||void 0===e||e.abort(),l.current=null,null===(t=r.current)||void 0===t||t.pause()},[]),k=(0,s.useCallback)(()=>{if(!c.current)try{const e=f();e.src="data:audio/wav;base64,UklGRiwAAABXQVZFZm10IBAAAAABAAEAQB8AAIA+AAACABAAZGF0YQgAAAAAAAAAAAAAAA==",e.load(),e.play().then(()=>{c.current=!0},()=>{})}catch(e){}},[f]),w=(0,s.useMemo)(()=>e.filter($e),[e]),x=(0,s.useMemo)(()=>w.filter(e=>null===e.planId&&!p.has(e.id)).map(e=>e.id),[p,w]),A=null!==(n=x[0])&&void 0!==n?n:null;return(0,s.useEffect)(()=>{var e;if(t)return d.current=!0,P(),C(),void S(null);const s=d.current;if(d.current=!1,i&&P(),null!==y)return;const n=w.find(e=>!o.current.has(e.id));if(!n)return;if(null!==n.planId&&!s)return;o.current.add(n.id);const r=w.some(e=>!o.current.has(e.id));if(i)return b(n.id),void(r&&(S(n.id),I(()=>S(null),(u=n.text,Math.min(3500,Math.max(900,35*u.length))))));var u;P();const h=new AbortController;l.current=h;const p=f(),m=function(e){var t;let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(!(0,be.Cw)(e))return Fe;if(null!==i){var s;const t=null===(s=De[e])||void 0===s?void 0:s[i];if(t)return t}return null!==(t=Ue[e])&&void 0!==t?t:Fe}(a,null!==(e=n.speakerId)&&void 0!==e?e:null);S(n.id);const g=I(()=>b(n.id),1e3);(0,Ve.p)({audio:p,cacheKey:{botId:"".concat("video-stream-").concat(a).concat(n.speakerId?"-".concat(n.speakerId):""),text:n.text,voiceStrapiId:m.cacheId},signal:h.signal,fetchSpeech:e=>Le.FH.generateSpeech({text:n.text,voice_name:m.name,voice_id:m.voiceId,voice_provider:m.provider,predict_emotion:!0,signal:e}),play:e=>h.signal.aborted?Promise.resolve():e.play().then(()=>{c.current=!0}),onPlaybackStarted:()=>{h.signal.aborted||(clearTimeout(g),b(n.id))}}).then(()=>((e,t)=>new Promise(i=>{if(t.aborted||e.ended||"function"!==typeof e.addEventListener)return void i();const s=()=>{clearTimeout(n),e.removeEventListener("ended",s),e.removeEventListener("error",s),t.removeEventListener("abort",s),i()},n=setTimeout(s,3e4);e.addEventListener("ended",s),e.addEventListener("error",s),t.addEventListener("abort",s)}))(p,h.signal)).catch(e=>{h.signal.aborted||console.warn("[video-stream] TTS playback failed",e)}).finally(()=>{clearTimeout(g),T.current.delete(g),b(n.id),S(e=>e===n.id?null:e)})},[y,C,f,t,i,I,b,w,P,a]),(0,s.useEffect)(()=>()=>{P(),C()},[C,P]),{delayedTextMessageId:A,hiddenMessageIds:x,speakingMessageId:y,unlockAudio:k}}
1var He=i(33749),We=i(89438),Ge=i(34367),Ke=i(9214),Ye=i(61707),Qe=i(44641),Ze=i(90990);const ze={streamMain:"VideoStreamingPage_streamMain__aNPzb",streamPage:"VideoStreamingPage_streamPage__hkLAh",srOnly:"VideoStreamingPage_srOnly__XsaJo",streamStage:"VideoStreamingPage_streamStage__Az+o-",streamMedia:"VideoStreamingPage_streamMedia__rTUIU",streamVideo:"VideoStreamingPage_streamVideo__5xYDx",streamScrim:"VideoStreamingPage_streamScrim__iXgU9",streamMediaCutting:"VideoStreamingPage_streamMediaCutting__9GGb4",streamFrameCut:"VideoStreamingPage_streamFrameCut__kyupZ",streamMediaCustomCut:"VideoStreamingPage_streamMediaCustomCut__ObRD9",streamCustomCut:"VideoStreamingPage_streamCustomCut__s9TWL",streamVideoChatToggle:"VideoStreamingPage_streamVideoChatToggle__5R5Cn",streamHeader:"VideoStreamingPage_streamHeader__Q5Zik",stateProgressBadge:"VideoStreamingPage_stateProgressBadge__VKWF9",streamClose:"VideoStreamingPage_streamClose__4he6a",streamSound:"VideoStreamingPage_streamSound__oMAFN",streamCloseIcon:"VideoStreamingPage_streamCloseIcon__viMNQ",streamSoundIcon:"VideoStreamingPage_streamSoundIcon__FHMaR",stateProgressBadgeStatus:"VideoStreamingPage_stateProgressBadgeStatus__DcNht",stateProgressBadgeContent:"VideoStreamingPage_stateProgressBadgeContent__C4vEq",stateProgressBadgeEnergy:"VideoStreamingPage_stateProgressBadgeEnergy__1+oS+",stateProgressBadgeEnergyIcon:"VideoStreamingPage_stateProgressBadgeEnergyIcon__1CBi3",stateProgressBadgeEnergyValue:"VideoStreamingPage_stateProgressBadgeEnergyValue__+boYL",stateProgressBadgeLabel:"VideoStreamingPage_stateProgressBadgeLabel__TFNZ6",stateBadgeWordIn:"VideoStreamingPage_stateBadgeWordIn__j79HM",stateProgressBadgeSignal:"VideoStreamingPage_stateProgressBadgeSignal__B39r-",stateBadgeThinking:"VideoStreamingPage_stateBadgeThinking__EESwN",stateBadgePerforming:"VideoStreamingPage_stateBadgePerforming__KFvAR",stateBadgeRipple:"VideoStreamingPage_stateBadgeRipple__RFct4",stateProgressBadgePerimeterFrame:"VideoStreamingPage_stateProgressBadgePerimeterFrame__Fe4P9",stateProgressBadgePerimeter:"VideoStreamingPage_stateProgressBadgePerimeter__yI+w8",stateProgressBadgePerimeterBase:"VideoStreamingPage_stateProgressBadgePerimeterBase__nBoTl",stateProgressBadgePerimeterProgress:"VideoStreamingPage_stateProgressBadgePerimeterProgress__Q7UR5",stateProgressBadgeBloom:"VideoStreamingPage_stateProgressBadgeBloom__QdvYb",stateBadgeBloom:"VideoStreamingPage_stateBadgeBloom__DQqXH",streamInterface:"VideoStreamingPage_streamInterface__OOveK",streamInterfaceAboveKeyboardBar:"VideoStreamingPage_streamInterfaceAboveKeyboardBar__YN-om",streamInterfaceHidden:"VideoStreamingPage_streamInterfaceHidden__e+e36",streamChat:"VideoStreamingPage_streamChat__dk6Yj",streamChatHidden:"VideoStreamingPage_streamChatHidden__6cJhN",streamTipsDismiss:"VideoStreamingPage_streamTipsDismiss__zVEM3",streamChatSummary:"VideoStreamingPage_streamChatSummary__fDEqO",streamChatMessages:"VideoStreamingPage_streamChatMessages__uPPI3",streamChatHistoryIn:"VideoStreamingPage_streamChatHistoryIn__MGEpJ",streamChatMessageToggle:"VideoStreamingPage_streamChatMessageToggle__z2vt4",streamCustomStreamBanner:"VideoStreamingPage_streamCustomStreamBanner__6LYe5",streamReply:"VideoStreamingPage_streamReply__RiKsC",streamReplyIn:"VideoStreamingPage_streamReplyIn__xcYO9",streamReplyUser:"VideoStreamingPage_streamReplyUser__YqZxP",streamReplyText:"VideoStreamingPage_streamReplyText__rcJED",streamReplySpeaker:"VideoStreamingPage_streamReplySpeaker__j57Zg",streamInputWrap:"VideoStreamingPage_streamInputWrap__q2aGm",streamInput:"VideoStreamingPage_streamInput__bApdH",mentionMenu:"VideoStreamingPage_mentionMenu__H6eXN",mentionOption:"VideoStreamingPage_mentionOption__5yj8r",streamGroupPill:"VideoStreamingPage_streamGroupPill__jLvGF",streamNotice:"VideoStreamingPage_streamNotice__gssqE",streamNoticeText:"VideoStreamingPage_streamNoticeText__o+c+d",streamNoticeAction:"VideoStreamingPage_streamNoticeAction__19TWr",streamSuggestions:"VideoStreamingPage_streamSuggestions__vcRmz",streamSuggestionsIn:"VideoStreamingPage_streamSuggestionsIn__FvVz+",streamSuggestion:"VideoStreamingPage_streamSuggestion__RZIBe",customTipChips:"VideoStreamingPage_customTipChips__mNqgR",customTipChip:"VideoStreamingPage_customTipChip__nryP9",customTipChipIn:"VideoStreamingPage_customTipChipIn__r6Zff",customTipChipText:"VideoStreamingPage_customTipChipText__sgOYb",tipPrice:"VideoStreamingPage_tipPr
1ice__UZUcJ",customTipChipPending:"VideoStreamingPage_customTipChipPending__Y05QM",streamComposer:"VideoStreamingPage_streamComposer__QNCR-",streamSend:"VideoStreamingPage_streamSend__yzWOR",streamPrimaryAction:"VideoStreamingPage_streamPrimaryAction__DGVfB",streamRetry:"VideoStreamingPage_streamRetry__Lhulh",streamSendIcon:"VideoStreamingPage_streamSendIcon__C6GVO",streamSendIconEnabled:"VideoStreamingPage_streamSendIconEnabled__DFU2-",streamReconnect:"VideoStreamingPage_streamReconnect__YWyo0",streamReconnectIn:"VideoStreamingPage_streamReconnectIn__lwpMg",streamReconnectOffline:"VideoStreamingPage_streamReconnectOffline__FqzZP",streamReconnectLabel:"VideoStreamingPage_streamReconnectLabel__oGItW",streamTransitionMask:"VideoStreamingPage_streamTransitionMask__Easjf",streamCutBloom:"VideoStreamingPage_streamCutBloom__jVy3P",streamTransitionFlash:"VideoStreamingPage_streamTransitionFlash__62I5U",streamCutFlash:"VideoStreamingPage_streamCutFlash__9xAcQ",streamTransitionLabel:"VideoStreamingPage_streamTransitionLabel__g9Aud",streamTransitionLabelIn:"VideoStreamingPage_streamTransitionLabelIn__B0zgH",streamOverlay:"VideoStreamingPage_streamOverlay__KwF7U",streamError:"VideoStreamingPage_streamError__0o-aZ",streamOverlayPassive:"VideoStreamingPage_streamOverlayPassive__JN5y9",streamBillingOverlay:"VideoStreamingPage_streamBillingOverlay__5Cx+x",streamPreparingStatus:"VideoStreamingPage_streamPreparingStatus__K9fPs",streamPreparingSpinner:"VideoStreamingPage_streamPreparingSpinner__BeNGe",streamReconnectSpin:"VideoStreamingPage_streamReconnectSpin__r6MN0",paidMessageDialog:"VideoStreamingPage_paidMessageDialog__5p1UE",streamOverlayCard:"VideoStreamingPage_streamOverlayCard__IHjdy",streamErrorCard:"VideoStreamingPage_streamErrorCard__oIb5h",streamKicker:"VideoStreamingPage_streamKicker__IAhRi",streamTitle:"VideoStreamingPage_streamTitle__H1x71",streamCopy:"VideoStreamingPage_streamCopy__9m--i",streamErrorMessage:"VideoStreamingPage_streamErrorMessage__sb0lR",streamBillingActions:"VideoStreamingPage_streamBillingActions__sbl4U",streamBillingSecondaryAction:"VideoStreamingPage_streamBillingSecondaryAction__++KvC",streamBillingEndAction:"VideoStreamingPage_streamBillingEndAction__mtU51",streamTips:"VideoStreamingPage_streamTips__OCLbb",streamTipNext:"VideoStreamingPage_streamTipNext__8Odlb",streamTipNextLabel:"VideoStreamingPage_streamTipNextLabel__4uX5C",streamTipList:"VideoStreamingPage_streamTipList__CRzaM",streamTipEmpty:"VideoStreamingPage_streamTipEmpty__WOlR2",streamTipsToggle:"VideoStreamingPage_streamTipsToggle__o3Kqk",streamTipsPrompt:"VideoStreamingPage_streamTipsPrompt__Wtfi7",tipPending:"VideoStreamingPage_tipPending__VLguj",clipPlaying:"VideoStreamingPage_clipPlaying__XTAwH",chatHidden:"VideoStreamingPage_chatHidden__73Cj5",tipsOpen:"VideoStreamingPage_tipsOpen__F5IwU",levelPrompt:"VideoStreamingPage_levelPrompt__m8ytG",levelMaxBadge:"VideoStreamingPage_levelMaxBadge__QtcWC",levelMaxBadgeHidden:"VideoStreamingPage_levelMaxBadgeHidden__jAuhn",levelMaxHeart:"VideoStreamingPage_levelMaxHeart__Ikg3y",levelMaxLabel:"VideoStreamingPage_levelMaxLabel__VqPah",levelProgress:"VideoStreamingPage_levelProgress__YiDX8",levelProgressReady:"VideoStreamingPage_levelProgressReady__qE5sW",levelProgressFill:"VideoStreamingPage_levelProgressFill__Hgc0W",levelReadyShimmer:"VideoStreamingPage_levelReadyShimmer__3E6VF",levelMessage:"VideoStreamingPage_levelMessage__O3ZYQ",levelSkip:"VideoStreamingPage_levelSkip__IfDGV",levelSkipMilestone:"VideoStreamingPage_levelSkipMilestone__k8Dkc",levelSkipMilestonePulse:"VideoStreamingPage_levelSkipMilestonePulse__GpTed",levelSkipMilestoneShimmer:"VideoStreamingPage_levelSkipMilestoneShimmer__FXCgH",levelSkipIcon:"VideoStreamingPage_levelSkipIcon__6c4yf",levelSkipLabel:"VideoStreamingPage_levelSkipLabel__ynYmC",levelSkipOverlay:"VideoStreamingPage_levelSkipOverlay__N8ys0",levelSkipOverlayIn:"VideoStreamingPage_levelSkipOverlayIn__uQL0Q",customTipInputOverlay:"VideoStreamingPage_customTipInputOverlay__JpBKw",levelSkipDialog:"VideoStreamingPage_levelSkipDialog__Xin2E",levelSkipClose:"VideoStreamingPage_levelSkipClose__pALBv",levelSkipTitle:"VideoStreamingPage_levelSkipTitle__7-v0r",levelSkipCopy:"VideoStreamingPage_levelSkipCopy__M-wYk",levelSkipConfirm:"VideoStreamingPage_levelSkipConfirm__K+FbK",levelTrack:"VideoStreamingPage_levelTrack__Y4
1jSc",levelTrackStep:"VideoStreamingPage_levelTrackStep__TtwA1",levelTrackDot:"VideoStreamingPage_levelTrackDot__JAL2e",levelTrackDotLocked:"VideoStreamingPage_levelTrackDotLocked__6stzI",levelTrackDotCurrent:"VideoStreamingPage_levelTrackDotCurrent__Tq+BD",levelTrackLabel:"VideoStreamingPage_levelTrackLabel__iYjgc",levelTrackLine:"VideoStreamingPage_levelTrackLine__p9hmL",levelTrackLineDone:"VideoStreamingPage_levelTrackLineDone__nJeeK",levelResetButton:"VideoStreamingPage_levelResetButton__wMTme",levelResetConfirm:"VideoStreamingPage_levelResetConfirm__vh2tb",levelResetCancel:"VideoStreamingPage_levelResetCancel__yHcmA",streamTipItem:"VideoStreamingPage_streamTipItem__8pmz8",streamTipPrice:"VideoStreamingPage_streamTipPrice__DDci9",streamTipCustom:"VideoStreamingPage_streamTipCustom__ETuyj",streamTipCustomLabel:"VideoStreamingPage_streamTipCustomLabel__tSvJ1",streamTipsDivider:"VideoStreamingPage_streamTipsDivider__npFoL",streamTipCustomStatus:"VideoStreamingPage_streamTipCustomStatus__A567u",streamTipCustomStatusLabel:"VideoStreamingPage_streamTipCustomStatusLabel__aseAa",streamTipSpinner:"VideoStreamingPage_streamTipSpinner__OJ-3-",streamTipRemove:"VideoStreamingPage_streamTipRemove__pPjE-",customTipThanksDialog:"VideoStreamingPage_customTipThanksDialog__f-PCg",customTipRing:"VideoStreamingPage_customTipRing__9+OeX",customTipRingTrack:"VideoStreamingPage_customTipRingTrack__q1hc4",customTipRingArc:"VideoStreamingPage_customTipRingArc__muqfZ",customTipRingSpark:"VideoStreamingPage_customTipRingSpark__zTZxr",customTipInputWrap:"VideoStreamingPage_customTipInputWrap__C9yoj",customTipInput:"VideoStreamingPage_customTipInput__UffD1",customTipInputFooter:"VideoStreamingPage_customTipInputFooter__rhRr3",customTipPromptChips:"VideoStreamingPage_customTipPromptChips__Na5ZY",customTipPromptChip:"VideoStreamingPage_customTipPromptChip__-mmoZ",customTipCounter:"VideoStreamingPage_customTipCounter__UGBTp",streamTipWatched:"VideoStreamingPage_streamTipWatched__1lINO",streamTyping:"VideoStreamingPage_streamTyping__XqGtI",streamTypingHidden:"VideoStreamingPage_streamTypingHidden__1c0mN",streamTypingDots:"VideoStreamingPage_streamTypingDots__iadg0",typingDot:"VideoStreamingPage_typingDot__Zdd--",tipPlay:"VideoStreamingPage_tipPlay__jxeYo",tipPlayGhost:"VideoStreamingPage_tipPlayGhost__IQujC"};var Je=i(44414);const Xe=e=>"video-stream:paid-message-confirmed:".concat(e);function et(e){var t,i,a,r,l,o,c,d,p,m,g,y,S,b,I,C,P,k;let w=e.accessLevel,x=e.areTipSuggestionsEnabled,A=e.isTipSuggestionsResolved,R=void 0===A||A,M=e.energyBalance,E=e.getAccessToken,B=e.isAnonymous,j=e.isEnergyLoaded,N=e.isLoginOpen,L=e.isNativeApp,V=e.monetizationType,F=void 0===V?"default":V,O=e.isMonetizationResolved,U=void 0===O||O,D=e.onEnergyBalanceChange,$=e.onOpenEnergyPaywall,q=e.onOpenSubscriptionPaywall,H=e.onSessionInvalid,W=e.streamId,G=void 0===W?be.Ln:W;const K=(0,n.Zp)(),Y=(0,s.useRef)(null),Q=(0,s.useRef)(null),Z=(0,s.useRef)(null),z=(0,He.v0)(),J=(0,s.useState)(()=>(0,Ye.DE)("live_stream")),X=(0,_.A)(J,2),ee=X[0],te=X[1],ie=(0,s.useState)(null),se=(0,_.A)(ie,2),ne=se[0],ae=se[1],re=(0,s.useRef)(null),le=(0,s.useRef)(null),oe=(0,s.useRef)(null),ce=(0,s.useRef)(null),de=(0,s.useRef)(null),ue=(0,s.useRef)(null),he=(0,s.useRef)(null),pe=(0,s.useRef)(null),me=(0,s.useRef)(null),ge=(0,s.useState)((0,f.A)({},Ie)),ve=(0,_.A)(ge,2),ye=ve[0],Se=ve[1],fe=qe(ye.chatMessages,ye.isClipPlaying,ye.muted,G),Te=fe.delayedTextMessageId,we=fe.hiddenMessageIds,xe=fe.speakingMessageId,Ae=fe.unlockAudio,Re=(0,Qe.fS)(null!==w&&void 0!==w?w:"basic","ultra"),Me=(0,s.useRef)(w),Ee=(0,s.useRef)(q),Be=(0,s.useRef)($);Ee.current=q,Be.current=$;const Ne=(0,s.useRef)(F);Ne.current=F;const Le=(0,s.useState)(""),Ve=(0,_.A)(Le,2),Fe=Ve[0],Oe=Ve[1],Ue=(0,s.useState)(!1),De=(0,_.A)(Ue,2),$e=De[0],et=De[1],rt=(0,s.useState)(!1),lt=(0,_.A)(rt,2),ot=lt[0],ct=lt[1],dt=(0,s.useState)(!1),ut=(0,_.A)(dt,2),ht=ut[0],pt=ut[1],mt=(0,s.useState)(!1),gt=(0,_.A)(mt,2),vt=gt[0],yt=gt[1],St=(0,s.useState)(!1),bt=(0,_.A)(St,2),ft=bt[0],_t=bt[1],Tt=(0,s.useState)(!1),It=(0,_.A)(Tt,2),Ct=It[0],Pt=It[1],kt=(0,s.use
1State)("closed"),wt=(0,_.A)(kt,2),xt=wt[0],At=wt[1],Rt=(0,s.useState)("closed"),Mt=(0,_.A)(Rt,2),Et=Mt[0],Bt=Mt[1],jt=(0,s.useState)(""),Nt=(0,_.A)(jt,2),Lt=Nt[0],Vt=Nt[1],Ft=(0,s.useState)(!1),Ot=(0,_.A)(Ft,2),Ut=Ot[0],Dt=Ot[1],$t=(0,s.useState)(null),qt=(0,_.A)($t,2),Ht=qt[0],Wt=qt[1];(0,s.useEffect)(()=>{const e=Y.current,t=Q.current;if(!e||!t||!U)return;const i=new T(function(){if("function"===typeof crypto.randomUUID)return crypto.randomUUID();return"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2))}(),G);re.current=i;const s=new Ce({videos:[e,t],getAccessToken:E,onSessionInvalid:H,onBalanceChange:D,onSubscriptionRequired:()=>Ee.current(),onInsufficientEnergy:()=>Be.current(),analytics:i,streamId:G,perMessageBilling:"per_message"===Ne.current});Z.current=s;const n=s.subscribe(Se),a=e=>{e.persisted||i.end("pagehide")};return window.addEventListener("pagehide",a),s.start(),()=>{window.removeEventListener("pagehide",a),n(),s.dispose(),i.end("route_exit"),re.current===i&&(re.current=null),Z.current===s&&(Z.current=null)}},[E,U,D,H,G]),(0,s.useEffect)(()=>{var e;const t=Me.current;Me.current=w,t!==w&&(0,Qe.fS)(null!==w&&void 0!==w?w:"basic",null!==t&&void 0!==t?t:"basic")&&(null===(e=Z.current)||void 0===e||e.resync("access_level_changed"))},[w]),(0,s.useEffect)(()=>{var e;"fatal"!==ye.phase||N||(null===(e=pe.current)||void 0===e||e.focus())},[N,ye.fatalKind,ye.phase]),(0,s.useEffect)(()=>{var e;ye.hasStreamStarted&&U&&(e=F,v.logExposure(e))},[ye.hasStreamStarted,U,F]);const Gt=(0,s.useRef)(null);(0,s.useEffect)(()=>{var e,t,i,s;if("fatal"!==ye.phase)return void(Gt.current=null);const n=null!==(e=ye.fatalError)&&void 0!==e?e:"The stream stopped unexpectedly.",a="".concat(null!==(t=ye.fatalKind)&&void 0!==t?t:"unknown",":").concat(n);Gt.current!==a&&(Gt.current=a,null===(i=re.current)||void 0===i||i.errorShown(null!==(s=ye.fatalKind)&&void 0!==s?s:"unknown",n))},[ye.fatalError,ye.fatalKind,ye.phase]);const Kt=null!==(t=null===(i=ye.chatMessages[ye.chatMessages.length-1])||void 0===i?void 0:i.id)&&void 0!==t?t:null;(0,s.useEffect)(()=>{const e=oe.current;ot&&e&&(e.scrollTop=e.scrollHeight)},[ot,Kt,ye.isMessageQueued,ye.isMessageSending,ye.isReplyRevealPending]);const Yt=e=>{if(Ae(),B)return H(),!1;const t=Z.current;if(!t||!at(t.snapshot))return!1;const i=t.snapshot.messagePrice;if(null!==i&&i>0&&j&&null!==M&&M<i)return $(),!1;if(null!==i&&i>0&&!(e=>{try{return"1"===localStorage.getItem(Xe(e))}catch(t){return!1}})(G))return Wt({text:e}),!1;return!!(null===e?t.continueChat():t.sendMessage(e))&&(Oe(""),ct(!1),pt(!1),!0)},Qt=()=>Wt(null),Zt=()=>{var e;if(L&&Ze.bW.navigateBack())return;const t=null===(e=window.history.state)||void 0===e?void 0:e.idx;K("number"===typeof t&&t>0?-1:"/")},zt=!ye.hasStreamStarted&&"connecting"===ye.phase,Jt=!ye.hasStreamStarted&&"ready"===ye.phase,Xt=ye.needsResumeGesture&&"ready"===ye.phase,ei=Pe(ye.billingState),ti=Jt&&!Xt&&!ei&&"payment_required"!==ye.billingState,ii=ye.hasStreamStarted&&"payment_required"===ye.billingState&&!ye.showFreeTimeEnded&&!ye.isBillingContinuing&&"fatal"!==ye.phase&&!ye.isReconnecting&&!ye.isOffline,si=zt||Jt||Xt||ii,ni=ye.hasStreamStarted&&(ye.showFreeTimeEnded||"insufficient_energy"===ye.billingState||"unavailable"===ye.billingState)&&"fatal"!==ye.phase&&!ye.isReconnecting&&!ye.isOffline,ai=ni||ii||Jt&&ei?ye.billingState:null,ri=$e&&/CriOS/i.test(navigator.userAgent),li=ye.hasStreamStarted&&!si&&!ni&&"fatal"!==ye.phase,oi=ye.isMessageSending||ye.isMessageQueued,ci=li&&!oi&&!ei&&!ye.isTipPending,di=at(ye),ui=!di||0===Fe.trim().length,hi=ye.isMessageSending?"Sending message\u2026":ye.isMessageQueued?"Message queued":ui?"Send unavailable":"Send message",pi=0===Fe.trim().length&&!oi,mi=ye.hasStreamStarted&&ye.isReconnecting&&!ye.isOffline,gi=ye.hasStreamStarted&&ye.isOffline,vi=ye.hasStreamStarted&&"payment_required"===ye.billingState&&ye.isBillingContinuing,yi=ye.isIdleInterrupting&&!ye.isCustomInterrupting||mi||vi,Si=!Xt&&(ii||Jt&&ke(ye.billingState)),bi=null===ye.billingPriceEnergy?null:"".concat(ye.billingPriceEnergy," \u26a1"),fi=ye.isMessageSending||ye.isReplyRevealPending||null!==Te,_i=!di||"idle"!==ye.phase||ye.isAwaitingReply||fi||null!==xe,Ti=vt&&null!==ye.tips,Ii=null!==(a=null===(r=ye.tips)||void 0===r?void 0:r.customActions)&&void 0!==a?a:[],Ci=[...Ii].reverse(),Pi=ye.animateTipButton||ft,ki=ye.chatMessages.length>0||fi,wi=ye.isTipPending||ht,xi=ye.chatMessages.filter(e=>!we.includes(e.id)),Ai=null!==(l=xi[xi.length-1])&&void 0!==l?l:null,Ri=ye.speakers.length>1,Mi=e=>{var t;return e&&(null===(t=ye.speakers.find(t=>
1t.id===e))||void 0===t?void 0:t.name)||null},Ei=Mi(null===(o=ye.chatMessages.find(e=>e.id===Te))||void 0===o?void 0:o.speakerId),Bi=Ei?"".concat(Ei," is typing"):(0,be.oz)(G),ji=Ri?/(^|[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])@((?:[\0-\x08\x0E-\x1F!-\?A-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)$/.exec(Fe):null,Ni=null===ji?[]:ye.speakers.filter(e=>e.name.toLowerCase().startsWith(ji[2].toLowerCase())),Li=je(ye.chatMessages,li,[Y,Q]),Vi="session"===ye.fatalKind||"signin"===ye.fatalAction,Fi=!0===(null===(c=ye.progress)||void 0===c?void 0:c.complete)&&Boolean(null===(d=ye.tips)||void 0===d?void 0:d.nextState),Oi=null!==ye.progress&&null===ye.progress.requiredMessages,Ui=ye.stateTrack.findIndex(e=>{var t;return e.stateId===(null===(t=ye.badgeView)||void 0===t?void 0:t.stateId)}),Di=ye.isTipPending&&ye.isAwaitingReply,$i=!Fi&&null!==ye.progress&&ye.progress.messagesInState>0&&ye.progress.messagesInState%10===0,qi="video"===ye.fatalKind?"Video couldn\u2019t load":Vi?"Sign in to continue":ye.hasStreamStarted?"Couldn\u2019t reconnect":"Couldn\u2019t connect",Hi=()=>{var e,t;null===(e=re.current)||void 0===e||e.startTapped("paid","paid_continue"),null===(t=Z.current)||void 0===t||t.continueBilling()},Wi=()=>{var e,t,i,s,n;const a=null===(e=ye.tips)||void 0===e?void 0:e.nextState;a&&(B?H():(null===(t=re.current)||void 0===t||t.tipTapped(a.label,a.tipPrice,null!==(i=null===(s=ye.badgeView)||void 0===s?void 0:s.stateId)&&void 0!==i?i:"unknown"),!a.requiresSubscription||Re?null===(n=Z.current)||void 0===n||n.buyTip(a.choiceId):q()))},Gi=()=>{var e,t;if(B)return void H();const i=null!==(e=null===(t=ye.tips)||void 0===t?void 0:t.actions)&&void 0!==e?e:[];!Re&&i.length>0&&i.every(e=>e.requiresSubscription)?q():At("level")},Ki=null!==(p=ye.customTipPrice)&&void 0!==p?p:200,Yi=x?ye.customTipSuggestions:[],Qi="closed"===Et?ye.pendingCustomTipChip:null,Zi="closed"===Et?Yi:[],zi=null!==Qi||Zi.length>0,Ji=ye.customTipSuggestionsRowId,Xi="pending"===ye.customTipSubmitStatus,es=Xi||null!==Qi,ts=()=>{var e;if("thanks"!==Et||!Ut){if("input"===Et){var t,i,s;if(Xi)return;null===(t=re.current)||void 0===t||t.customTipClosed(null!==(i=null===(s=ye.badgeView)||void 0===s?void 0:s.stateId)&&void 0!==i?i:"unknown",Lt.trim().length>0)}null===(e=Z.current)||void 0===e||e.resetCustomTipSubmit(),Bt("closed")}},is=Yi,ss=(0,s.useRef)(ts);ss.current=ts;const ns=(0,s.useRef)(!1);(0,s.useEffect)(()=>{var e;if(ti&&ye.canStart){var t;if(!ns.current)ns.current=!0,null===(t=re.current)||void 0===t||t.startTapped("free"===ye.billingState?"free":"unknown","initial_start");null===(e=Z.current)||void 0===e||e.startPlayback()}},[ti,ye.billingState,ye.canStart]),(0,s.useEffect)(()=>{var e;(Xt||ii||Jt&&!ti)&&!N&&(null===(e=he.current)||void 0===e||e.focus())},[ti,N,ii,Jt,Xt]),(0,s.useEffect)(()=>{var e;ni&&!N&&(null===(e=me.current)||void 0===e||e.focus())},[N,ni,ye.billingState]),(0,s.useEffect)(()=>{if(!Ct)return;const e=e=>{"Escape"===e.key&&Pt(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Ct]),(0,s.useEffect)(()=>{if("closed"===Et)return;const e=e=>{"Escape"===e.key&&ss.current()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Et]),(0,s.useEffect)(()=>{if("thanks"!==Et||ye.customTipsEnabled)return;Dt(!0);const e=window.setTimeout(()=>Dt(!1),2500);return()=>window.clearTimeout(e)},[Et]),(0,s.useEffect)(()=>{var e;"accepted"===ye.customTipSubmitStatus&&"input"===Et&&(Vt(""),Bt("thanks"),null===(e=Z.current)||void 0===e||e.resetCustomTipSubmit())},[Et,ye.customTipSubmitStatus]),(0,s.useEffect)(()=>{"failed"===ye.customTipSubmitStatus&&"input"===Et&&Bt("failed")},[Et,ye.customTipSubmitStatus]);const as=(0,s.useRef)(null);(0,s.useEffect)(()=>{const e=as.current;if(null===e)return;const t=t=>{if(0===t.deltaY||t.shiftKey)return;const i=e.scrollWidth-e.clientWidth;if(i<=0)return;const s=e.scrollLeft<=0,n=e.scrollLeft>=i-1;t.deltaY<0&&s||t.deltaY>0&&n||(t.preventDefault(),e.scrollLeft=Math.max(0,Math.min(i,e.scrollLeft+t.deltaY)))};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)},[Zi.length]);const rs=null!==(m=xi.filter(e=>"assistant"===e.sender&&!(e=>e.id.startsWith(_e))(e))[1])&&void 0!==m?m:null,ls=null!==(g=null===rs||void 0===rs?void 0:rs.id)&&void 0!==g?g:null,os=rs?Li(rs):null,cs=os?os.startedAtMs+os.revealAtMs[os.revealAtMs.length-1]:null,ds=(0,s.use
1State)(null),us=(0,_.A)(ds,2),hs=us[0],ps=us[1];(0,s.useEffect)(()=>{if(!ls)return void ps(null);const e=null===cs?0:Math.max(0,cs-performance.now()),t=setTimeout(()=>ps(ls),e+600);return()=>clearTimeout(t)},[ls,cs]);const ms=ye.hasStreamStarted&&null!==ls&&hs===ls&&!ee,gs=ms&&z.enabled;(0,s.useEffect)(()=>{var e;ms&&z.isResolved&&((0,He.n1)(z.enabled),z.enabled&&(null===(e=re.current)||void 0===e||e.customStreamBannerShown()))},[ms,z.isResolved,z.enabled]);const vs=()=>{var e,t;"offer"===ne&&(null===(e=re.current)||void 0===e||e.customStreamOfferClosed(Ye.Vc));"comingSoon"===ne&&(null===(t=re.current)||void 0===t||t.customStreamComingSoonClosed(Ye.Vc));ae(null)};(0,s.useEffect)(()=>{var e;R&&ye.customTipSuggestions.length>0&&(e=x,h()||u.logExposure(e?"enabled":"control"))},[ye.customTipSuggestions,x,R]);const ys=(0,s.useRef)(null);return(0,s.useEffect)(()=>{var e,t,i;null!==Ji&&0!==Zi.length&&ys.current!==Ji&&(ys.current=Ji,null===(e=re.current)||void 0===e||e.customTipChipsShown(Ji,null!==(t=null===(i=ye.badgeView)||void 0===i?void 0:i.stateId)&&void 0!==t?t:"unknown",Zi.map(e=>e.chip),Ki,ye.customTipSuggestionsLanguage))},[Ji,Zi,Ki,null===(y=ye.badgeView)||void 0===y?void 0:y.stateId,ye.customTipSuggestionsLanguage]),(0,s.useEffect)(()=>{var e;const t=null===(e=ye.tips)||void 0===e?void 0:e.customActions;if(null===t||void 0===t)return void(ue.current=null);const i=ue.current;null!==i&&t.some(e=>"completed"===e.status&&"completed"!==i.get(e.clipId))&&_t(!0),ue.current=new Map(t.map(e=>[e.clipId,e.status]))},[null===(S=ye.tips)||void 0===S?void 0:S.customActions]),(0,s.useEffect)(()=>{if(null===ai)return void(le.current=null);if(!Pe(ai)||le.current===ai)return;const e=re.current;e&&(le.current=ai,e.billingGateShown(ai,ye.billingPriceEnergy,ye.billingPeriodSeconds))},[ai,ye.billingPeriodSeconds,ye.billingPriceEnergy]),(0,Je.jsxs)("div",{className:ze.streamPage,children:[(0,Je.jsxs)("section",{className:nt(ze.streamStage,Di&&ze.tipPending,ye.isClipPlaying&&ze.clipPlaying,Ti&&ze.tipsOpen,ht&&ze.chatHidden),"aria-label":"Interactive AI character stream",onPointerDownCapture:Ae,onClickCapture:e=>{var t;!Ti||null!==(t=de.current)&&void 0!==t&&t.contains(e.target)||(yt(!1),e.preventDefault(),e.stopPropagation())},children:[(0,Je.jsxs)("div",{className:nt(ze.streamMedia,yi&&ze.streamMediaCutting,ye.isCustomCutting&&ze.streamMediaCustomCut),"aria-hidden":"true",children:[(0,Je.jsx)("video",{ref:Y,className:ze.streamVideo,"data-active":"true",preload:"auto",playsInline:!0}),(0,Je.jsx)("video",{ref:Q,className:ze.streamVideo,"data-active":"false",preload:"auto",playsInline:!0})]}),(0,Je.jsx)("div",{className:ze.streamScrim}),ki&&li&&!Ti?(0,Je.jsx)("button",{type:"button",className:ze.streamVideoChatToggle,"aria-label":ot?"Show the latest chat message":ht?"Show chat text":"Hide chat text",onClick:()=>{ot?ct(!1):pt(e=>!e)}}):null,Ti?(0,Je.jsx)("button",{type:"button",className:ze.streamTipsDismiss,"aria-label":"Close tip menu",onClick:()=>yt(!1)}):null,(0,Je.jsxs)("header",{className:ze.streamHeader,"aria-hidden":!li||ht,"data-testid":"stream-header",children:[(0,Je.jsx)("button",{type:"button",className:ze.streamClose,"aria-label":"Close stream",onClick:Zt,children:(0,Je.jsx)("svg",{className:ze.streamCloseIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"M15 6 9 12l6 6"})})}),li&&null!==ye.progress&&null!==ye.progress.requiredMessages?(0,Je.jsxs)("div",{className:ze.levelPrompt,"aria-label":"Level progress",children:[(0,Je.jsxs)("button",{type:"button",className:nt(ze.levelProgress,Fi&&ze.levelProgressReady),disabled:ye.isTipPending,role:Fi?void 0:"progressbar","aria-label":Fi?"Go to next level":"Level details","aria-valuemin":Fi?void 0:0,"aria-valuemax":Fi?void 0:ye.progress.requiredMessages,"aria-valuenow":Fi?void 0:Math.min(ye.progress.messagesInState,ye.progress.requiredMessages),onClick:()=>{Fi?Wi():Gi()},children:[(0,Je.jsx)("span",{className:ze.levelProgressFill,style:{width:"".concat(0===ye.progress.requiredMessages?100:Math.min(100,ye.progress.messagesInState/ye.progress.requiredMessages*100),"%")},"aria-hidden":"true"}),(0,Je.jsx)("span",{className:ze.levelMessage,children:Fi?"Go to
1next level":"Level up in ".concat(Math.max(0,ye.progress.requiredMessages-ye.progress.messagesInState)," msgs")})]}),null!==(b=ye.tips)&&void 0!==b&&b.nextState&&!Fi?(0,Je.jsxs)("button",{type:"button",className:nt(ze.levelSkip,$i&&ze.levelSkipMilestone),"aria-label":"Boost to next level",disabled:ye.isTipPending,onClick:()=>{var e;const t=null===(e=ye.tips)||void 0===e?void 0:e.nextState;t&&(B?H():t.requiresSubscription?Wi():Pt(!0))},children:[(0,Je.jsx)("svg",{className:ze.levelSkipIcon,viewBox:"0 0 10 15","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"M0.564 8.49c0-.152.053-.287.17-.428l5.731-6.978c.469-.568 1.195-.193.932.504L5.545 6.486h3.545c.281 0 .492.2.492.469 0 .152-.059.287-.17.428l-5.736 6.978c-.469.569-1.195.2-.926-.504l1.852-4.898H1.057c-.288 0-.493-.2-.493-.469Z"})}),(0,Je.jsx)("span",{className:ze.levelSkipLabel,children:"Boost"})]},$i?"skip-".concat(ye.progress.messagesInState):"skip"):null]}):null,li&&Oi?(0,Je.jsxs)("button",{type:"button",className:nt(ze.levelMaxBadge,wi&&ze.levelMaxBadgeHidden),"aria-label":"Level details",tabIndex:wi?-1:0,onClick:Gi,children:[(0,Je.jsx)("svg",{className:ze.levelMaxHeart,viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"M12 21C12 21 4 15.9 4 10.6 4 7.6 6.2 5.5 8.7 5.5c1.5 0 2.7.8 3.3 2 .6-1.2 1.8-2 3.3-2 2.5 0 4.7 2.1 4.7 5.1C20 15.9 12 21 12 21Z"})}),(0,Je.jsx)("span",{className:ze.levelMaxLabel,children:"Max"})]}):null,(0,Je.jsx)("button",{type:"button",className:ze.streamSound,"aria-label":ye.muted?"Turn sound on":"Turn sound off","aria-pressed":ye.muted,onClick:()=>{var e;const t=Z.current;if(!t)return;const i=!ye.muted;t.setMuted(i),null===(e=re.current)||void 0===e||e.soundToggled(!i)},children:(0,Je.jsxs)("svg",{className:ze.streamSoundIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,Je.jsx)("path",{d:"M11 5 6 9H3v6h3l5 4V5Z"}),ye.muted?(0,Je.jsxs)(Je.Fragment,{children:[(0,Je.jsx)("path",{d:"m16 9 5 5"}),(0,Je.jsx)("path",{d:"m21 9-5 5"})]}):(0,Je.jsxs)(Je.Fragment,{children:[(0,Je.jsx)("path",{d:"M15.5 8.5a5 5 0 0 1 0 7"}),(0,Je.jsx)("path",{d:"M18 6a8.5 8.5 0 0 1 0 12"})]})]})})]}),(0,Je.jsxs)("div",{className:nt(ze.streamInterface,!li&&ze.streamInterfaceHidden,ri&&ze.streamInterfaceAboveKeyboardBar),"aria-hidden":!li,children:[ki&&!Ti?(0,Je.jsxs)("div",{className:nt(ze.streamChat,wi&&ze.streamChatHidden),"aria-hidden":wi,"aria-live":ot?"off":"polite","aria-atomic":!ot,children:[ot?(0,Je.jsx)("div",{ref:oe,className:ze.streamChatMessages,role:"log","aria-label":"Recent chat","aria-live":"polite","aria-relevant":"additions text",children:xi.map(e=>(0,Je.jsx)("button",{type:"button",className:ze.streamChatMessageToggle,onClick:()=>ct(!1),children:(0,Je.jsx)(st,{message:e,revealTimeline:null,speakerName:Mi(e.speakerId)})},e.id))}):(0,Je.jsxs)("button",{type:"button",className:ze.streamChatSummary,"aria-expanded":"false",onClick:()=>{wi?pt(!1):ct(!0)},children:[(0,Je.jsx)("span",{className:ze.srOnly,children:"Show recent chat. "}),Ai?(0,Je.jsx)(st,{message:Ai,revealTimeline:Li(Ai),speakerName:Mi(Ai.speakerId)}):null]}),gs?(0,Je.jsx)(We.w,{className:ze.streamCustomStreamBanner,onOpen:()=>{var e,t;null===(e=re.current)||void 0===e||e.customStreamBannerTapped(Ye.Vc,null!==M&&void 0!==M?M:0,B),null===(t=re.current)||void 0===t||t.customStreamOfferShown(Ye.Vc),ae("offer")},onClose:()=>{var e;null===(e=re.current)||void 0===e||e.customStreamBannerClosed(),(0,Ye.oA)("live_stream"),te(!0)}}):null]}):null,ye.notice||ye.recoverableMessage?(0,Je.jsxs)("div",{className:ze.streamNotice,children:[(0,Je.jsx)("p",{id:"stream-notice",className:ze.streamNoticeText,role:"status",children:null!==(I=ye.notice)&&void 0!==I?I:"Your previous message wasn\u2019t completed."}),ye.recoverableMessage?(0,Je.jsx)("button",{type:"button",className:ze.streamNoticeAction,disabled:Fe.trim().length>0,"aria-label":Fe.trim().length>0?"Restore the previous message after sending or clearing the current draft":"Restore the previous message",title:Fe.trim().length>0?"Send or clear your current draft first.":void 0,onClick:()=>{var e,t;if(Fe.trim().length>0)return;const i=null===(e=Z.current)||void 0===e?void 0:e.takeRecoverableMessage();i&&(Oe(i),null===(t=ce.current)||void 0===t||t.focus())},children:"Restore"}):null]}):null,vt&&null!==ye.tips?(0,Je.jsxs)("div",{ref:de,className:ze.streamTips,role:"region","aria-label":"Tip menu",children:[(0,Je.jsxs)(Je.Fragment,{children:[Ii.length>0?(0,Je.jsxs)("div",{className:ze.streamTipsDivider,children:["My customs \xb7 ",Ii.length]}):null,(0,Je.jsxs)("button",{type:"button",className:nt(ze.streamTipItem,ze.streamTipCustom),onClick:()=>{var e,t,i,s;null===(e=re.current)||void 0===e||e.customTipTapped(null!==(t=null===(i=ye.badgeView)||void 0===i?void 0:i.stateId)&&void 0!==t?t:"unknown"),null===(s=Z.current)||void 0===s||s.resetCustomTipSubmit(),yt(!1),Bt("input")},children:[(0,Je.jsxs)("span",{className:ze.streamTipCustomLabel,children:[(0,Je.jsx)("span",{"aria-hidden":"true",children:"\u2728"}),(0,Je.jsx)("span",{children:"Tell me what to do\u2026"})]}),ye.customTipsEnabled?(0,Je.jsx)(it,{value:Ki}):null]}),ye.tips.customActionsUnavailable?(0,Je.jsx)("div",{className:nt(ze.streamTipItem,ze.streamTipCustomStatus),role:"status",children:(0,Je.jsxs)("span",{className:ze.streamTipCustomStatusLabel,children:[(0,Je.jsx)("span",{"aria-hidden":"true",children:"\u26a0\ufe0f"}),(0,Je.jsx)("span",{children:"Your tips are unavailable right now"})]})}):null,Ci.map(e=>"completed"===e.status?(0,Je.jsxs)("button",{type:"button",className:ze.streamTipItem,disabled:ye.isClipPlaying||ye.isMessageSending,onClick:()=>{var t,i,s,n;null===(t=re.current)||void 0===t||t.tipTapped(e.label,0,null!==(i=null===(s=ye.badgeView)||void 0===s?void 0:s.stateId)&&void 0!==i?i:"unknown"),null!==(n=Z.current)&&void 0!==n&&n.buyTip(e.clipI
1d)&&yt(!1)},children:[(0,Je.jsx)("span",{children:e.label}),(0,Je.jsxs)("span",{className:nt(ze.tipPrice,ze.tipPlay),"aria-hidden":"true",children:[(0,Je.jsx)("span",{className:ze.tipPlayGhost,children:"Free"}),(0,Je.jsx)("svg",{viewBox:"0 0 12 14",children:(0,Je.jsx)("path",{d:"M1.8 1.2v11.6a.7.7 0 0 0 1.06.6l9.28-5.8a.7.7 0 0 0 0-1.2L2.86.6a.7.7 0 0 0-1.06.6Z"})})]})]},e.clipId):(0,Je.jsxs)("div",{className:nt(ze.streamTipItem,ze.streamTipCustomStatus),children:[(0,Je.jsxs)("span",{className:ze.streamTipCustomStatusLabel,children:["error"===e.status?(0,Je.jsx)("span",{"aria-hidden":"true",children:"\u26a0\ufe0f"}):(0,Je.jsx)("span",{className:ze.streamTipSpinner,"aria-hidden":"true"}),(0,Je.jsx)("span",{children:e.label})]}),"error"===e.status?(0,Je.jsx)("button",{type:"button",className:ze.streamTipRemove,"aria-label":'Remove failed tip "'.concat(e.label,'"'),onClick:()=>{var t;return null===(t=Z.current)||void 0===t?void 0:t.deleteCustomTip(e.clipId)},children:(0,Je.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})}):(0,Je.jsx)("span",{className:ze.srOnly,children:"Generating\u2026"})]},e.clipId))]}),ye.tips.actions.length>0||null!==ye.tips.nextState?(0,Je.jsx)("div",{className:ze.streamTipsDivider,children:"Quick actions"}):null,ye.tips.actions.map(e=>(0,Je.jsxs)("button",{type:"button",className:ze.streamTipItem,disabled:ye.isClipPlaying||ye.isMessageSending,onClick:()=>{var t,i,s,n;null===(t=re.current)||void 0===t||t.tipTapped(e.label,e.tipPrice,null!==(i=null===(s=ye.badgeView)||void 0===s?void 0:s.stateId)&&void 0!==i?i:"unknown",e.watched),e.requiresSubscription?q():null!==(n=Z.current)&&void 0!==n&&n.buyTip(e.choiceId)&&yt(!1)},children:[(0,Je.jsx)("span",{children:e.label}),e.requiresSubscription?(0,Je.jsx)("span",{className:ze.tipPrice,children:"\ud83d\udd12"}):e.watched?(0,Je.jsxs)("span",{className:nt(ze.tipPrice,ze.tipPlay),"aria-hidden":"true",children:[(0,Je.jsx)("span",{className:ze.tipPlayGhost,children:"Free"}),(0,Je.jsx)("svg",{viewBox:"0 0 12 14",children:(0,Je.jsx)("path",{d:"M1.8 1.2v11.6a.7.7 0 0 0 1.06.6l9.28-5.8a.7.7 0 0 0 0-1.2L2.86.6a.7.7 0 0 0-1.06.6Z"})})]}):(0,Je.jsx)(it,{value:e.tipPrice})]},e.choiceId)),null!==ye.tips.nextState?(0,Je.jsxs)("button",{type:"button",className:ze.streamTipItem,disabled:ye.isClipPlaying||ye.isMessageSending,onClick:()=>{var e,t,i,s,n;if(B)H();else{var a,r,l;if(null!==(e=ye.tips)&&void 0!==e&&e.nextState)null===(a=re.current)||void 0===a||a.tipTapped(ye.tips.nextState.label,ye.tips.nextState.tipPrice,null!==(r=null===(l=ye.badgeView)||void 0===l?void 0:l.stateId)&&void 0!==r?r:"unknown");null!==(t=ye.tips)&&void 0!==t&&null!==(i=t.nextState)&&void 0!==i&&i.requiresSubscription?q():null!==(s=ye.tips)&&void 0!==s&&s.nextState&&null!==(n=Z.current)&&void 0!==n&&n.buyTip(ye.tips.nextState.choiceId)&&yt(!1)}},children:[(0,Je.jsx)("span",{children:ye.tips.nextState.label}),ye.tips.nextState.requiresSubscription?(0,Je.jsx)("span",{className:ze.tipPrice,children:"\ud83d\udd12"}):(0,Je.jsx)(it,{value:ye.tips.nextState.tipPrice})]}):null]}):null,ye.isAwaitingReply||oi||null!==Te?(0,Je.jsxs)("div",{className:nt(ze.streamTyping,Ti&&ze.streamTypingHidden),"aria-hidden":Ti,"aria-live":"polite",children:[Bi,(0,Je.jsxs)("span",{className:ze.streamTypingDots,"aria-hidden":"true",children:[(0,Je.jsx)("span",{children:"."}),(0,Je.jsx)("span",{children:"."}),(0,Je.jsx)("span",{children:"."})]})]}):null,zi?(0,Je.jsxs)("div",{ref:as,className:ze.customTipChips,role:"group","aria-label":"Suggested tips",children:[null!==Qi?(0,Je.jsxs)("div",{className:nt(ze.customTipChip,ze.customTipChipPending),role:"status",children:[(0,Je.jsx)("span",{className:ze.customTipChipText,children:Qi}),(0,Je.jsx)("span",{className:ze.streamTipSpinner,"aria-hidden":"true"}),(0,Je.jsx)("span",{className:ze.srOnly,children:"Preparing your video\u2026"})]}):null,Zi.map((e,t)=>(0,Je.jsxs)("button",{type:"button",className:ze.customTipChip,disabled:es,onClick:()=>((e,t)=>{var i,s,n,a,r,l,o;const c=null!==Ji&&void 0!==Ji?Ji:"unknown",d=null!==(i=null===(s=ye.badgeView)||void 0===s?void 0:s.stateId)&&void 0!==i?i:"unknown",u=null!==(n=null===(a=Zi.find(t=>t.suggestionId!==e.suggestionId))||void 0===a?void 0:a.chip)&&void 0!==n?n:null;var h;null===(r=re.current)||void 0===r||r.customTipChipTapped(c,d,e.chip,u,t,Ki,ye.customTipSuggestionsLanguage),null===(l=re.current)||void 0===l||l.customTipSubmitted(e.chip,Ki,d,null!==w&&void 0!==w?w:"anonymous","chip",!0),B?H():null!==(o=Z.current)&&void 0!==o&&o.requestSuggestedCustomTip(e.suggestionId)&&(null===(h=re.current)||void 0===h||h.suggestionTipSubmitted(c,d,e.chip,Ki,ye.customTipSuggestionsLanguage,null!==w&&void 0!==w?w:"anonymous"))})(e,t),children:[(0,Je.jsx)("span",{className:ze.customTipChipText,children:e.chip}),(0,Je.jsx)(it,{value:Ki})]},e.suggestionId))]}):null,(0,Je.jsxs)("form",{className:ze.streamComposer,onSubmit:e=>{e.preventDefault(),Fe.trim().length>0&&Yt(Fe)},children:[(0,Je.jsxs)("button",{type:"button",className:nt(ze.streamTipsToggle,Pi&&ze.streamTipsPrompt),disabled:ye.isTipPending||null===ye.tips,"aria-expanded":vt,"aria-label":vt?"Hide what you can ask for":"Show what you can ask for",onClick:()=>{var e,t,i,s,n,a;if(null===(e=re.current)||void 0===e||e.sendTipButtonTapped(null!==(t=null===(i=ye.badgeView)||void 0===i?void 0:i.stateId)&&void 0!==t?t:"unknown",P
1i),_t(!1),null===(s=Z.current)||void 0===s||s.acknowledgeTipPrompt(),B)return void H();const r=null!==(n=null===(a=ye.tips)||void 0===a?void 0:a.actions)&&void 0!==n?n:[];!Re&&r.length>0&&r.every(e=>e.requiresSubscription)?q():yt(e=>!e)},children:[(0,Je.jsx)("span",{"aria-hidden":"true",children:"\u2726"}),(0,Je.jsx)("span",{children:"Send tip"})]}),(0,Je.jsx)("label",{className:ze.srOnly,htmlFor:"stream-message",children:"Message"}),(0,Je.jsxs)("div",{className:ze.streamInputWrap,children:[Ni.length>0?(0,Je.jsx)("div",{className:ze.mentionMenu,role:"listbox","aria-label":"Ask one of them",children:Ni.map(e=>(0,Je.jsxs)("button",{type:"button",role:"option","aria-selected":!1,className:ze.mentionOption,onMouseDown:e=>e.preventDefault(),onClick:()=>(e=>{var t;if(null===ji)return;const i=Fe.slice(0,ji.index+ji[1].length);Oe("".concat(i,"@").concat(e," ")),null===(t=ce.current)||void 0===t||t.focus()})(e.name),children:["@",e.name]},e.id))}):null,(0,Je.jsx)("input",{ref:ce,id:"stream-message",className:ze.streamInput,type:"text",inputMode:"text",autoComplete:"off",maxLength:500,value:Fe,placeholder:"Type a message",disabled:!ci,"aria-describedby":ye.notice||ye.recoverableMessage?"stream-notice":void 0,onFocus:()=>{var e;et(!0),null===(e=Z.current)||void 0===e||e.notifyUserActivity()},onBlur:()=>et(!1),onChange:e=>{var t;Oe(e.target.value),null===(t=Z.current)||void 0===t||t.notifyUserActivity()}})]}),pi?(0,Je.jsx)("button",{className:ze.streamSend,type:"button",disabled:_i,"aria-label":"Continue",title:"Continue",onClick:()=>{var e;null===(e=re.current)||void 0===e||e.continueButtonTapped(),Yt(null)},children:(0,Je.jsxs)("svg",{className:nt(ze.streamSendIcon,!_i&&ze.streamSendIconEnabled),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,Je.jsx)("path",{d:"m5 5 7 7-7 7"}),(0,Je.jsx)("path",{d:"m13 5 7 7-7 7"})]})}):(0,Je.jsx)("button",{className:ze.streamSend,type:"submit",disabled:ui,"aria-label":hi,"aria-busy":oi||void 0,children:(0,Je.jsxs)("svg",{className:nt(ze.streamSendIcon,!ui&&ze.streamSendIconEnabled),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:[(0,Je.jsx)("path",{d:"m4 12 15-7-5 14-2.5-5.5L4 12Z"}),(0,Je.jsx)("path",{d:"m11.5 13.5 3-3"})]})})]})]}),Ct&&null!==(C=ye.tips)&&void 0!==C&&C.nextState&&!ye.tips.nextState.requiresSubscription?(0,Je.jsx)("div",{className:ze.levelSkipOverlay,onClick:e=>{e.target===e.currentTarget&&Pt(!1)},children:(0,Je.jsxs)("div",{className:ze.levelSkipDialog,role:"dialog","aria-modal":"true","aria-labelledby":"level-skip-title","aria-describedby":"level-skip-copy",children:[(0,Je.jsx)("button",{type:"button",className:ze.levelSkipClose,"aria-label":"Close boost dialog",onClick:()=>Pt(!1),children:(0,Je.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})}),(0,Je.jsx)("h2",{id:"level-skip-title",className:ze.levelSkipTitle,children:"Make it hotter"}),(0,Je.jsx)("p",{id:"level-skip-copy",className:ze.levelSkipCopy,children:"Boost the intimacy level with her and get more spicy tips."}),(0,Je.jsxs)("button",{type:"button",className:ze.levelSkipConfirm,"aria-label":"Unlock for ".concat(ye.tips.nextState.tipPrice," energy"),onClick:()=>{Pt(!1),Wi()},children:[(0,Je.jsx)("span",{children:"Unlock"}),(0,Je.jsx)(it,{value:ye.tips.nextState.tipPrice})]})]})}):null,"closed"!==xt?(0,Je.jsx)("div",{className:ze.levelSkipOverlay,onClick:e=>{e.target===e.currentTarget&&At("closed")},children:"level"===xt?(0,Je.jsxs)("div",{className:ze.levelSkipDialog,role:"dialog","aria-modal":"true","aria-labelledby":"level-window-title","aria-describedby":"level-window-copy",children:[(0,Je.jsx)("button",{type:"button",className:ze.levelSkipClose,"aria-label":"Close level dialog",onClick:()=>At("closed"),children:(0,Je.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})}),(0,Je.jsx)("h2",{id:"level-window-title",className:ze.levelSkipTitle,children:Oi?"Max level reached":"Make it hotter"}),(0,Je.jsx)("p",{id:"level-window-copy",className:ze.levelSkipCopy,children:Oi?"You\u2019ve reached the highest intimacy level. You can restart the story from the very beginning.":"Boost the intimacy level with her and get more spicy tips."}),ye.stateTrack.length>1?(0,Je.jsx)("div",{className:ze.levelTrack,"aria-hidden":"true",children:ye.stateTrack.map((e,t)=>(0,Je.jsxs)(s.Fragment,{children:[t>0?(0,Je.jsx)("span",{className:nt(ze.levelTrackLine,t<=Ui&&ze.levelTrackLineDone)}):null,(0,Je.jsxs)("span",{className:ze.levelTrackStep,children:[(0,Je.jsx)("span",{className:nt(ze.levelTrackDot,t<Ui&&ze.levelTrackDotDone,t===Ui&&ze.levelTrackDotCurrent,t>Ui&&ze.levelTrackDotLocked),children:t<Ui?"\u2713":t===Ui?t+1:"\ud83d\udd12"}),(0,Je.jsx)("span",{className:ze.levelTrackLabel,children:t<=Ui+1?e.label:"???"})]})]},e.stateId))}):null,null!==(P=ye.tips)&&void 0!==P&&P.nextState&&!ye.tips.nextState.requiresSubscription?(0,Je.jsxs)("button",{type:"button",className:ze.levelSkipConfirm,"aria-label":"Unlock for ".concat(ye.tips.nextState.tipPrice," energy"),onClick:()=>{At("closed"),Wi()},children:[(0,Je.jsx)("span",{children:"Unlock"}),(0,Je.jsx)(it,{value:ye.tips.nextState.tipPrice})]}):null,(0,Je.jsxs)("button",{type:"button",className:ze.levelResetButton,onClick:()=>At("confirm"),children:[(0,Je.jsx)("span",{"aria-hidden":"true",children:"\u21ba"}),(0,Je.jsx)("span",{children:"Reset all progress"})]})]}):(0,Je.jsxs)("div",{className:ze.levelSkipDialog,role:"dialog","aria-modal":"true","aria-labelledby":"level-reset-title","aria-describedby":"level-reset-copy",children:[(0,Je.jsx)("button",{type:"button",className:ze.levelSkipClose,"aria-label":"Close reset dialog",onClick:()=>At("closed"),children:(0,Je.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})}),(0,Je.jsx)("h2",{id:"level-reset-title",className:ze.levelSkipTitle,children:"Reset all progress?"}),(0,Je.jsxs)("p",{id:"level-reset-copy",className:ze.levelSkipCopy,children:["Your intimacy level, chat history and progress will be erased, and the stream will restart from the very beginning."," ",(0,Je.jsx)("strong",{children:"Your custom clips won\u2019t be deleted."})]}),(0,Je.jsx)("button",{type:"button",className:nt(ze.levelSkipConfirm,ze.levelResetConfirm),onClick:()=>{var e;At("closed"),null===(e=Z.current)||void 0===e||e.resetProgress()},children:"Reset all progress"}),(0,Je.jsx)("button",{type:"button",className:ze.levelResetCancel,onClick:()=>At("closed"),children:"Keep playing"})]})}):null,"closed"!==Et?(0,Je.jsx)("div",{className:nt(ze.levelSkipOverlay,"input"===Et&&ze.customTipInputOverlay),onClick:e=>{e.target===e.currentTarget&&ts()},children:"input"===Et?(0,Je.jsxs)("div",{className:ze.levelSkipDialog,role:"dialog","aria-modal":"true","aria-labelledby":"
1custom-tip-title","aria-describedby":"custom-tip-copy",children:[(0,Je.jsx)("button",{type:"button",className:ze.levelSkipClose,"aria-label":"Close custom fantasy dialog",onClick:ts,children:(0,Je.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})}),(0,Je.jsx)("h2",{id:"custom-tip-title",className:ze.levelSkipTitle,children:"Your own fantasy \ud83d\ude08"}),(0,Je.jsx)("p",{id:"custom-tip-copy",className:ze.levelSkipCopy,children:"Tell her what to do and she\u2019ll act it out on stream, just for you."}),(0,Je.jsx)("label",{className:ze.srOnly,htmlFor:"custom-tip-prompt",children:"Describe your fantasy"}),(0,Je.jsxs)("div",{className:ze.customTipInputWrap,children:[(0,Je.jsx)("textarea",{id:"custom-tip-prompt",className:ze.customTipInput,maxLength:300,rows:3,value:Lt,placeholder:"Tell her what to do\u2026",autoFocus:!0,onChange:e=>Vt(e.target.value)}),(0,Je.jsxs)("div",{className:ze.customTipInputFooter,children:[(0,Je.jsxs)("span",{className:ze.customTipCounter,"aria-hidden":"true",children:[Lt.length," / ",300]}),is.length>0?(0,Je.jsx)("div",{className:ze.customTipPromptChips,role:"group","aria-label":"Suggested fantasies",children:is.map(e=>(0,Je.jsx)("button",{type:"button",className:ze.customTipPromptChip,onClick:()=>{return t=e.chip,void Vt(t.slice(0,300));var t},children:e.chip},e.suggestionId))}):null]})]}),(0,Je.jsxs)("button",{type:"button",className:ze.levelSkipConfirm,disabled:0===Lt.trim().length||Xi,"aria-busy":Xi||void 0,"aria-label":"Request for ".concat(Ki," energy"),onClick:()=>{var e,t,i;const s=Lt.trim();if(0===s.length||Xi)return;const n=is.some(e=>e.chip===s);var a;(null===(e=re.current)||void 0===e||e.customTipSubmitted(s,Ki,null!==(t=null===(i=ye.badgeView)||void 0===i?void 0:i.stateId)&&void 0!==t?t:"unknown",null!==w&&void 0!==w?w:"anonymous","typed",n),ye.customTipsEnabled)?null===(a=Z.current)||void 0===a||a.requestCustomTip(s):(Vt(""),Bt("thanks"))},children:[(0,Je.jsx)("span",{children:Xi?"Requesting\u2026":"Request for"}),(0,Je.jsx)(it,{value:Ki})]})]}):"failed"===Et?(0,Je.jsxs)("div",{className:ze.levelSkipDialog,role:"dialog","aria-modal":"true","aria-labelledby":"custom-tip-failed-title","aria-describedby":"custom-tip-failed-copy",children:[(0,Je.jsx)("h2",{id:"custom-tip-failed-title",className:ze.levelSkipTitle,children:"Oops! Something went wrong"}),(0,Je.jsx)("p",{id:"custom-tip-failed-copy",className:ze.levelSkipCopy,children:"Your custom tip couldn\u2019t be started. Your energy will be refunded automatically in a few minutes."}),(0,Je.jsx)("button",{type:"button",className:ze.levelSkipConfirm,onClick:()=>{var e;null===(e=Z.current)||void 0===e||e.resetCustomTipSubmit(),Bt("closed"),yt(!1)},children:"Back to stream"})]}):(0,Je.jsxs)("div",{className:ye.customTipsEnabled?"".concat(ze.levelSkipDialog," ").concat(ze.customTipThanksDialog):ze.levelSkipDialog,role:"dialog","aria-modal":"true","aria-labelledby":"custom-tip-thanks-title","aria-describedby":"custom-tip-thanks-copy",children:[ye.customTipsEnabled?(0,Je.jsxs)("div",{className:ze.customTipRing,"aria-hidden":"true",children:[(0,Je.jsx)("span",{className:ze.customTipRingTrack}),(0,Je.jsx)("span",{className:ze.customTipRingArc}),(0,Je.jsx)("span",{className:ze.customTipRingSpark,children:"\u2728"})]}):null,(0,Je.jsx)("h2",{id:"custom-tip-thanks-title",className:ze.levelSkipTitle,children:ye.customTipsEnabled?"".concat((0,be.ZN)(G),"\u2019s recording your custom video"):"She can\u2019t wait to try it"}),(0,Je.jsx)("p",{id:"custom-tip-thanks-copy",className:ze.levelSkipCopy,children:ye.customTipsEnabled?(0,Je.jsxs)(Je.Fragment,{children:["It\u2019ll appear in ",(0,Je.jsx)("strong",{children:"My Customs"})," in ~2 minutes."]}):"No energy was charged - custom fantasies are still in the works. We saved yours and you\u2019ll be the first to try."}),(0,Je.jsx)("button",{type:"button",className:ze.levelSkipConfirm,disabled:!ye.customTipsEnabled&&Ut,onClick:()=>Bt("closed"),children:"Got it"})]})}):null,yi?(0,Je.jsxs)("div",{className:ze.streamTransitionMask,role:"status","aria-live":"polite","aria-atomic":"true","aria-busy":"true",children:[(0,Je.jsx)("span",{className:ze.streamTransitionFlash,"aria-hidden":"true"}),(0,Je.jsx)("span",{className:ze.streamTransitionLabel,children:mi?"Restoring stream\u2026":vi?"Starting stream\u2026":"Next scene\u2026"})]}):null,gi?(0,Je.jsx)("div",{className:nt(ze.streamReconnect,ze.streamReconnectOffline),role:"status","aria-atomic":"true",children:(0,Je.jsx)("span",{className:ze.streamReconnectLabel,children:"You\u2019re offline. We\u2019ll reconnect automatically."})}):null,zt||ti?(0,Je.jsx)("div",{className:nt(ze.streamOverlay,ze.streamOverlayPassive),children:(0,Je.jsxs)("div",{className:ze.streamPreparingStatus,role:"status","aria-atomic":"true",children:[ye.isOffline?null:(0,Je.jsx)("span",{className:ze.streamPreparingSpinner,"aria-hidden":"true"}),(0,Je.jsx)("span",{children:ye.isOffline?"You\u2019re offline. We\u2019ll reconnect automatically.":"Preparing stream\u2026"})]})}):null,Jt&&!ti||Xt||ii?(0,Je.jsx)("div",{className:ze.streamOverlay,role:"dialog","aria-labelledby":"stream-start-title","aria-describedby":"stream-start-copy",children:(0,Je.jsxs)("div",{className:ze.streamOverlayCard,children:[(0,Je.jsx)("span",{className:ze.streamKicker,children:Xt?"Stream paused":ii?"Paid streaming":"Live now"}),Ri?(0,Je.jsxs)("span",{className:ze.streamGroupPill,"data-testid":"stream-group-pill",children:["Group stream \xb7 ",ye.speakers.map(e=>e.name).join(" & ")]}):null,(0,Je.jsx)("h1",{id:"stream-start-title",className:ze.streamTitle,children:Xt?"Ready to resume":"Ready when you are"}),(0,Je.jsx)("p",{id:"stream-start-copy",className:ze.streamCopy,children:Xt?"Tap once to continue from your saved moment.":Si&&null!==bi?"Streaming costs ".concat(bi," per minute while it\u2019s running."):"Start the stream, then send a message whenever you\u2019re ready."}),(0,Je.jsx)("button",{ref:he,type:"button",className:ze.streamPrimaryAction,disabled:ii?ye.isBillingContinuing:!ye.canStart||"ready"!==ye.phase,onClick:()=>{const e=B&&ke(ye.billingState);var t;ye.hasStreamStarted||e||(null===(t=re.current)||void 0===t||t.startTapped("free"===ye.billingState?"free":ke(ye.billingState)?"paid":"unknown","initial_start"));if(e)H();else if(ii)Hi();else{var i;null===(i=Z.current)||void 0===i||i.startPlayback()}},children:B&&ke(ye.billingState)?"Sign in to continue":Xt?"Resume stream":ii&&null!==bi?"Continue for ".concat(bi):Jt&&"payment_required"===ye.billingState&&null!==bi?"Start for ".concat(bi):"Start stream"})]})}):null,ni?(0,Je.jsx)(tt,{actionRef:me,isAnonymous:B,isContinuing:ye.isBillingContinuing,onContinue:Hi,onEnd:Zt,onOpenEnergyPaywall:$,onSignIn:H,priceEnergy:ye.billingPriceEnergy,state:ye.billingState}
1):null,null!==Ht&&null!==ye.messagePrice?(0,Je.jsx)("div",{className:ze.levelSkipOverlay,onClick:e=>{e.target===e.currentTarget&&Qt()},children:(0,Je.jsxs)("div",{className:nt(ze.levelSkipDialog,ze.paidMessageDialog),role:"dialog","aria-modal":"true","aria-labelledby":"paid-message-title","aria-describedby":"paid-message-copy",children:[(0,Je.jsx)("button",{type:"button",className:ze.levelSkipClose,"aria-label":"Not now",onClick:Qt,children:(0,Je.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"m6 6 12 12M18 6 6 18"})})}),(0,Je.jsx)("h2",{id:"paid-message-title",className:ze.levelSkipTitle,children:"Before you send"}),(0,Je.jsxs)("p",{id:"paid-message-copy",className:ze.levelSkipCopy,children:["Each message you send ",Ri?"them":"her"," costs ",ye.messagePrice," ","energy."]}),(0,Je.jsx)("button",{type:"button",className:ze.levelSkipConfirm,onClick:()=>{const e=Ht;Wt(null),null!==e&&((e=>{try{localStorage.setItem(Xe(e),"1")}catch(t){}})(G),Yt(e.text))},children:"Confirm"})]})}):null,"fatal"===ye.phase?(0,Je.jsx)("div",{className:ze.streamError,role:"alertdialog","aria-labelledby":"stream-error-title","aria-describedby":"stream-error-message",children:(0,Je.jsxs)("div",{className:ze.streamErrorCard,children:[(0,Je.jsx)("span",{className:ze.streamKicker,children:"Stream paused"}),(0,Je.jsx)("h2",{id:"stream-error-title",className:ze.streamTitle,children:qi}),(0,Je.jsx)("p",{id:"stream-error-message",className:ze.streamErrorMessage,children:null!==(k=ye.fatalError)&&void 0!==k?k:"The stream stopped unexpectedly."}),(0,Je.jsx)("button",{ref:pe,type:"button",className:ze.streamRetry,onClick:()=>{var e,t;return Vi?null===(e=Z.current)||void 0===e?void 0:e.recoverSession():null===(t=Z.current)||void 0===t?void 0:t.retry()},children:Vi?"Sign in":"Retry"})]})}):null]}),"offer"===ne?(0,Je.jsx)(Ke.J,{price:Ye.Vc,onStart:()=>{var e,t;null===(e=re.current)||void 0===e||e.customStreamStartTapped(Ye.Vc,null!==M&&void 0!==M?M:0),null===(t=re.current)||void 0===t||t.customStreamComingSoonShown(Ye.Vc),(0,Ye.Fu)(),te(!0),ae("comingSoon")},onClose:vs}):null,"comingSoon"===ne?(0,Je.jsx)(Ge.n,{onClose:vs}):null]})}function tt(e){let t=e.actionRef,i=e.isAnonymous,s=e.isContinuing,n=e.onContinue,a=e.onEnd,r=e.onOpenEnergyPaywall,l=e.onSignIn,o=e.priceEnergy,c=e.state;const d="insufficient_energy"===c,u="unavailable"===c,h=i,p=null===o?"Continue":"Continue for ".concat(o," \u26a1"),m=s?"Continuing\u2026":p,g=h?"Account needed":d?"Energy needed":u?"Billing paused":"Free time ended",v=h?"Sign in to continue":d?"Not enough energy":u?"Billing is temporarily unavailable":"Keep the stream going",y=h?"Sign in to get energy and continue the stream.":d?"Add energy, then continue to start the next paid minute.":u?"You haven\u2019t been charged. Try continuing again in a moment.":"Your free stream time has ended. Continue to start the next paid minute.";return(0,Je.jsx)("div",{className:nt(ze.streamOverlay,ze.streamBillingOverlay),role:"alertdialog","aria-labelledby":"stream-billing-title","aria-describedby":"stream-billing-copy",children:(0,Je.jsxs)("div",{className:nt(ze.streamOverlayCard,ze.streamBillingCard),children:[(0,Je.jsx)("span",{className:ze.streamKicker,children:g}),(0,Je.jsx)("h2",{id:"stream-billing-title",className:ze.streamTitle,children:v}),(0,Je.jsx)("p",{id:"stream-billing-copy",className:ze.streamCopy,children:y}),(0,Je.jsxs)("div",{className:ze.streamBillingActions,children:[h?(0,Je.jsx)("button",{ref:t,type:"button",className:ze.streamPrimaryAction,onClick:l,children:"Sign in"}):d?(0,Je.jsx)("button",{ref:t,type:"button",className:ze.streamPrimaryAction,onClick:r,children:"Get energy"}):(0,Je.jsx)("button",{ref:t,type:"button",className:ze.streamPrimaryAction,disabled:s,"aria-busy":s||void 0,onClick:n,children:m}),(0,Je.jsx)("button",{type:"button",className:ze.streamBillingEndAction,onClick:a,children:"End stream"})]})]})})}function it(e){let t=e.value;return 0===t?(0,Je.jsx)("span",{className:ze.tipPrice,children:"Free"}):(0,Je.jsxs)("span",{className:ze.tipPrice,children:[(0,Je.jsx)("svg",{viewBox:"0 0 10 15","aria-hidden":"true",children:(0,Je.jsx)("path",{d:"M0.564 8.49c0-.152.053-.287.17-.428l5.731-6.978c.469-.568 1.195-.193.932.504L5.545 6.486h3.545c.281 0 .492.2.492.469 0 .152-.059.287-.17.428l-5.736 6.978c-.469.569-1.195.2-.926-.504l1.852-4.898H1.057c-.288 0-.493-.2-.493-.469Z"})}),t]})}function st(e){var t;let i=e.message,n=e.revealTimeline,a=e.speakerName,r=void 0===a?null:a;
1const l="user"===i.sender,o=function(e,t){const i=(0,s.useState)(null),n=(0,_.A)(i,2),a=n[0],r=n[1],l=null===t?0:(null===a||void 0===a?void 0:a.timeline)===t?a.visibleChunkCount:Ne(t,performance.now());return(0,s.useEffect)(()=>{var e,i;if(null===t)return;let s=null;const n=()=>{null!==s&&(clearTimeout(s),s=null),t.finished=!0,r({timeline:t,visibleChunkCount:t.chunks.length})},a=()=>{const e=Ne(t,performance.now());if(r({timeline:t,visibleChunkCount:e}),e>=t.chunks.length)return;const i=t.startedAtMs+t.revealAtMs[e];s=setTimeout(a,Math.max(0,Math.ceil(i-performance.now())))};return null===(e=t.video)||void 0===e||e.addEventListener("ended",n),null!==(i=t.video)&&void 0!==i&&i.ended?n():a(),()=>{var e;null!==s&&clearTimeout(s),null===(e=t.video)||void 0===e||e.removeEventListener("ended",n)}},[t]),null===t?{isStreaming:!1,text:e}:{isStreaming:l<t.chunks.length,text:t.chunks.slice(0,l).join("")}}(i.text,n),c=o.text;return(0,Je.jsxs)("span",{className:nt(ze.streamReply,l&&ze.streamReplyUser),"aria-label":"".concat(l?"You":null!==r&&void 0!==r?r:"Character",": ").concat(i.text),children:[r&&!l?(0,Je.jsx)("span",{className:ze.streamReplySpeaker,"data-speaker":null!==(t=i.speakerId)&&void 0!==t?t:void 0,"aria-hidden":"true",children:r}):null,(0,Je.jsx)("span",{className:ze.streamReplyText,"aria-hidden":"true",children:c})]})}function nt(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return t.filter(Boolean).join(" ")}function at(e){const t="performing"===e.phase||"idle"===e.phase&&!e.isReplyRevealPending&&!e.isAwaitingCommit&&!e.isIdleInterrupting;return e.hasStreamStarted&&t&&!e.needsResumeGesture&&!e.isMessageSending&&!e.isMessageQueued&&!e.isOffline&&!e.isReconnecting&&!Pe(e.billingState)}var rt=i(78213);function lt(e){var t;let i=e.streamId,c=void 0===i?be.Ln:i;const d=(0,s.useContext)(a.BR),p=d.energy,m=d.isEnergyLoaded,g=d.isLoginOpened,v=d.setEnergy,y=d.setIsEnergyPaywallOpened,f=d.setIsLoginOpened,_=d.setIsPaywallModalOpened,T=d.setPaywallType,I=d.user,C=d.isNativeApp,P=(()=>{const e=h(),t=(0,o.z)(u,"control",e);return{enabled:e||"enabled"===t.variant,isResolved:e||t.isResolved}})(),k=P.enabled,w=P.isResolved,x=S(),A=x.monetizationType,R=x.isResolved,M=(0,s.useCallback)(()=>r.d.getToken(),[]),E=(0,s.useCallback)(()=>f(!0),[f]),B=(0,s.useCallback)(()=>{l._w.setPaywallContext("live_chat"),y(!0)},[y]),j=(0,s.useCallback)(()=>{l._w.setPaywallContext("live_chat"),T("ultra"),_(!0)},[_,T]),N=(0,be.__)(c,!(null===I||void 0===I||!I.isPaid));return(0,rt.IH)(N),N?(0,Je.jsx)(b.J,{className:ze.streamMain,hideFooter:!0,lockResponsiveLayout:!0,children:(0,Je.jsx)(et,{accessLevel:null!==(t=null===I||void 0===I?void 0:I.accessLevel)&&void 0!==t?t:null,areTipSuggestionsEnabled:k,isTipSuggestionsResolved:w,energyBalance:p,getAccessToken:M,isAnonymous:!I||I.isAnon,isEnergyLoaded:m,isLoginOpen:g,isMonetizationResolved:R,isNativeApp:C,monetizationType:A,onEnergyBalanceChange:v,onOpenEnergyPaywall:B,onOpenSubscriptionPaywall:j,onSessionInvalid:E,streamId:c})}):(0,Je.jsx)(n.C5,{to:"/video-stream/".concat(be.Ln),replace:!0})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.