@floe-ai/sdk 0.1.0-dev.11 → 0.1.0-dev.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16223,6 +16223,9 @@ class th {
16223
16223
  // Scroll tracking for Fast Execution System
16224
16224
  O(this, "scrollHandler", null);
16225
16225
  O(this, "scrollDebounceTimer", null);
16226
+ // URL tracking for SPAs
16227
+ O(this, "urlCheckInterval", null);
16228
+ O(this, "popstateHandler", null);
16226
16229
  this.sdk = e, this.lastUrl = window.location.href;
16227
16230
  }
16228
16231
  /**
@@ -16344,18 +16347,21 @@ class th {
16344
16347
  * Stop tracking page events
16345
16348
  */
16346
16349
  stop() {
16347
- this.isTracking && (this.isTracking = !1, this.clickHandler && (document.removeEventListener("click", this.clickHandler, !0), this.clickHandler = null), this.focusHandler && (document.removeEventListener("focus", this.focusHandler, !0), this.focusHandler = null), this.blurHandler && (document.removeEventListener("blur", this.blurHandler, !0), this.blurHandler = null), this.inputHandler && (document.removeEventListener("input", this.inputHandler, !0), this.inputHandler = null), this.keydownHandler && (document.removeEventListener("keydown", this.keydownHandler, !0), this.keydownHandler = null), this.scrollHandler && (window.removeEventListener("scroll", this.scrollHandler), this.scrollHandler = null), this.scrollDebounceTimer && (clearTimeout(this.scrollDebounceTimer), this.scrollDebounceTimer = null), this.inputDebounceTimers.forEach((e) => clearTimeout(e)), this.inputDebounceTimers.clear(), console.log("[PageTracker] Stopped tracking"));
16350
+ this.isTracking && (this.isTracking = !1, this.clickHandler && (document.removeEventListener("click", this.clickHandler, !0), this.clickHandler = null), this.focusHandler && (document.removeEventListener("focus", this.focusHandler, !0), this.focusHandler = null), this.blurHandler && (document.removeEventListener("blur", this.blurHandler, !0), this.blurHandler = null), this.inputHandler && (document.removeEventListener("input", this.inputHandler, !0), this.inputHandler = null), this.keydownHandler && (document.removeEventListener("keydown", this.keydownHandler, !0), this.keydownHandler = null), this.scrollHandler && (window.removeEventListener("scroll", this.scrollHandler), this.scrollHandler = null), this.scrollDebounceTimer && (clearTimeout(this.scrollDebounceTimer), this.scrollDebounceTimer = null), this.urlCheckInterval && (clearInterval(this.urlCheckInterval), this.urlCheckInterval = null), this.popstateHandler && (window.removeEventListener("popstate", this.popstateHandler), this.popstateHandler = null), this.inputDebounceTimers.forEach((e) => clearTimeout(e)), this.inputDebounceTimers.clear(), console.log("[PageTracker] Stopped tracking"));
16348
16351
  }
16349
16352
  /**
16350
16353
  * Setup URL change tracking for SPAs
16351
16354
  */
16352
16355
  setupUrlTracking() {
16353
- setInterval(() => {
16356
+ this.urlCheckInterval || (this.urlCheckInterval = setInterval(() => {
16354
16357
  const e = window.location.href;
16355
16358
  e !== this.lastUrl && (this.lastUrl = e, this.sendPageMetadata());
16356
- }, 1e3), window.addEventListener("popstate", () => {
16357
- setTimeout(() => this.sendPageMetadata(), 100);
16358
- });
16359
+ }, 1e3), this.popstateHandler = () => {
16360
+ setTimeout(() => {
16361
+ const e = window.location.href;
16362
+ e !== this.lastUrl && (this.lastUrl = e, this.sendPageMetadata());
16363
+ }, 100);
16364
+ }, window.addEventListener("popstate", this.popstateHandler));
16359
16365
  }
16360
16366
  /**
16361
16367
  * Send current page metadata
@@ -16810,6 +16816,8 @@ class ec extends Yd {
16810
16816
  // Audio analyzer for user mic FFT
16811
16817
  O(this, "userMicStream", null);
16812
16818
  // User's mic stream for analysis
16819
+ O(this, "userMicStreamRequestId", 0);
16820
+ // Guards async getUserMedia against disconnect races
16813
16821
  O(this, "audioElements", []);
16814
16822
  O(this, "pageTracker");
16815
16823
  O(this, "screenShareEnabled", !1);
@@ -16938,18 +16946,24 @@ class ec extends Yd {
16938
16946
  * Setup user microphone analysis for waveform visualization
16939
16947
  */
16940
16948
  async setupUserMicAnalysis() {
16949
+ const t = ++this.userMicStreamRequestId;
16941
16950
  try {
16942
- this.userMicStream = await navigator.mediaDevices.getUserMedia({
16951
+ const r = await navigator.mediaDevices.getUserMedia({
16943
16952
  audio: {
16944
16953
  echoCancellation: !0,
16945
16954
  noiseSuppression: !0,
16946
16955
  autoGainControl: !0
16947
16956
  }
16948
- }), console.log("[OnboardingSDK] 🎤 User mic stream captured for visualization"), this.userAudioAnalyzer && this.userMicStream && this.userAudioAnalyzer.start(this.userMicStream, (t) => {
16949
- this.userIsSpeaking && (this.audioLevels = t, this.renderReactUI());
16950
16957
  });
16951
- } catch (t) {
16952
- console.warn("[OnboardingSDK] Could not capture mic for visualization:", t);
16958
+ if (t !== this.userMicStreamRequestId || !this.userAudioAnalyzer) {
16959
+ console.log("[OnboardingSDK] 🎤 Mic stream request invalidated (disconnect/reconnect occurred), stopping tracks"), r.getTracks().forEach((i) => i.stop());
16960
+ return;
16961
+ }
16962
+ this.userMicStream && this.userMicStream.getTracks().forEach((i) => i.stop()), this.userMicStream = r, console.log("[OnboardingSDK] 🎤 User mic stream captured for visualization"), this.userAudioAnalyzer && this.userAudioAnalyzer.start(r, (i) => {
16963
+ this.userIsSpeaking && (this.audioLevels = i, this.renderReactUI());
16964
+ });
16965
+ } catch (r) {
16966
+ console.warn("[OnboardingSDK] Could not capture mic for visualization:", r);
16953
16967
  }
16954
16968
  }
16955
16969
  /**
@@ -17053,9 +17067,9 @@ class ec extends Yd {
17053
17067
  * Disconnect and minimize the UI (instead of removing it)
17054
17068
  */
17055
17069
  async disconnectAndMinimize() {
17056
- this.pageTracker.stop(), this.domIntrospector.stopCapturing(), this.navigationCompleteDetector && this.navigationCompleteDetector.stop(), this.pipecatClient && (await this.pipecatClient.disconnect(), this.pipecatClient = null), this.transport && (this.transport = null), this.audioElements && (this.audioElements.forEach((t) => {
17070
+ this.pageTracker.stop(), this.domIntrospector.stopCapturing(), this.navigationCompleteDetector && this.navigationCompleteDetector.stop(), this.overlay.clearHighlight(), this.pipecatClient && (await this.pipecatClient.disconnect(), this.pipecatClient = null), this.transport && (this.transport = null), this.audioElements && (this.audioElements.forEach((t) => {
17057
17071
  t.pause(), t.remove();
17058
- }), this.audioElements = []), this.botAudioAnalyzer && (this.botAudioAnalyzer.destroy(), this.botAudioAnalyzer = null), this.userAudioAnalyzer && (this.userAudioAnalyzer.destroy(), this.userAudioAnalyzer = null), this.userMicStream && (this.userMicStream.getTracks().forEach((t) => t.stop()), this.userMicStream = null), this.audioLevels = [], this.isConnected = !1, this.agentState = "idle", this._isMinimized = !0, this.botTranscript = "", this.userTranscript = "", this.renderReactUI(), console.log("[OnboardingSDK] Disconnected and minimized"), this.emit("disconnected"), this.emit("minimized");
17072
+ }), this.audioElements = []), this.botAudioAnalyzer && (this.botAudioAnalyzer.destroy(), this.botAudioAnalyzer = null), this.userAudioAnalyzer && (this.userAudioAnalyzer.destroy(), this.userAudioAnalyzer = null), this.userMicStreamRequestId++, this.userMicStream && (this.userMicStream.getTracks().forEach((t) => t.stop()), this.userMicStream = null), this.audioLevels = [], this.isConnected = !1, this.agentState = "idle", this._isMinimized = !0, this.botTranscript = "", this.userTranscript = "", this.renderReactUI(), console.log("[OnboardingSDK] Disconnected and minimized"), this.emit("disconnected"), this.emit("minimized");
17059
17073
  }
17060
17074
  /**
17061
17075
  * Connect with progress stages for better UX.
@@ -17120,7 +17134,9 @@ class ec extends Yd {
17120
17134
  console.log("[OnboardingSDK] Connected to Pipecat"), this.isConnected = !0, this.agentState = "listening", this.micEnabled = ((t = this.pipecatClient) == null ? void 0 : t.isMicEnabled) ?? this.config.enableAudio !== !1, console.log("[OnboardingSDK] 🎤 Mic state on connect:", this.micEnabled ? "ON" : "MUTED"), this.clearConnectionProgress(), this.renderReactUI(), this.emit("connected");
17121
17135
  },
17122
17136
  onDisconnected: () => {
17123
- console.log("[OnboardingSDK] Disconnected from Pipecat"), this.isConnected = !1, this.agentState = "idle", this.renderReactUI(), this.emit("disconnected"), this.pageTracker.stop();
17137
+ console.log("[OnboardingSDK] Disconnected from Pipecat"), this.isConnected = !1, this.agentState = "idle", this.pageTracker.stop(), this.domIntrospector.stopCapturing(), this.navigationCompleteDetector && this.navigationCompleteDetector.stop(), this.overlay.clearHighlight(), this.audioElements && (this.audioElements.forEach((t) => {
17138
+ t.pause(), t.remove();
17139
+ }), this.audioElements = []), this.botAudioAnalyzer && (this.botAudioAnalyzer.destroy(), this.botAudioAnalyzer = null), this.userAudioAnalyzer && (this.userAudioAnalyzer.destroy(), this.userAudioAnalyzer = null), this.userMicStreamRequestId++, this.userMicStream && (console.log("[OnboardingSDK] 🎤 Stopping user microphone stream"), this.userMicStream.getTracks().forEach((t) => t.stop()), this.userMicStream = null), this.audioLevels = [], this.renderReactUI(), this.emit("disconnected");
17124
17140
  },
17125
17141
  onBotReady: () => {
17126
17142
  var t;
@@ -17169,7 +17185,7 @@ class ec extends Yd {
17169
17185
  }), console.log("[OnboardingSDK] 📝 Added assistant message to history:", this.botTranscript.substring(0, 50) + "...")), this.botTranscript = "", this.renderReactUI(), this.emit("botSpeaking", !1);
17170
17186
  },
17171
17187
  onServerMessage: (t) => {
17172
- console.log("[OnboardingSDK] Server message:", t), this.handleServerMessage(t), t.type === "session_paused" && (console.log("[OnboardingSDK] Session paused:", t), this.agentState = "paused", this.pausedSessionId = t.session_id || null, this.renderReactUI(), this.emit("sessionPaused", t));
17188
+ console.log("[OnboardingSDK] Server message:", t), this.handleServerMessage(t);
17173
17189
  },
17174
17190
  onError: (t) => {
17175
17191
  console.error("[OnboardingSDK] Error:", t), this.emit("error", t);
@@ -17279,7 +17295,7 @@ class ec extends Yd {
17279
17295
  console.log("[OnboardingSDK] 🎯 Received direct hybrid action:", r.action), this.handleHybridAction(r);
17280
17296
  return;
17281
17297
  }
17282
- r.type === "highlight" ? (console.log("[OnboardingSDK] Handling highlight command"), r.target ? this.overlay.highlightTarget(r.target, r.options) : r.selector && this.overlay.highlight(r.selector, r.options)) : r.type === "tooltip" && r.text ? this.overlay.showTooltip(r.text, r.options) : r.type === "action" ? r.target ? this.handleHybridAction(r) : this.actionExecutor.executeWithConsent(r.action) : r.type === "clear_highlight" ? this.overlay.clearHighlight() : r.type === "batched_navigation" ? this.handleBatchedNavigation(r) : r.type === "fast_action" ? this.executeActionFast(r) : r.type === "session_paused" ? (console.log("[OnboardingSDK] Session paused:", r), this.agentState = "paused", this.pausedSessionId = r.session_id || null, this.renderReactUI(), this.emit("sessionPaused", r)) : console.log("[OnboardingSDK] Unhandled server message type:", r.type || "unknown");
17298
+ r.type === "highlight" ? (console.log("[OnboardingSDK] Handling highlight command"), r.target ? this.overlay.highlightTarget(r.target, r.options) : r.selector && this.overlay.highlight(r.selector, r.options)) : r.type === "tooltip" && r.text ? this.overlay.showTooltip(r.text, r.options) : r.type === "action" ? r.target ? this.handleHybridAction(r) : this.actionExecutor.executeWithConsent(r.action) : r.type === "clear_highlight" ? this.overlay.clearHighlight() : r.type === "batched_navigation" ? this.handleBatchedNavigation(r) : r.type === "fast_action" ? this.executeActionFast(r) : r.type === "session_paused" ? (console.log("[OnboardingSDK] Session paused:", r), this.agentState = "paused", this.pausedSessionId = r.session_id || null, this.overlay.clearHighlight(), this.renderReactUI(), this.emit("sessionPaused", r)) : console.log("[OnboardingSDK] Unhandled server message type:", r.type || "unknown");
17283
17299
  }
17284
17300
  /**
17285
17301
  * Handle hybrid UI action from bot
@@ -18588,9 +18604,9 @@ class ec extends Yd {
18588
18604
  * Disconnect and cleanup
18589
18605
  */
18590
18606
  async disconnect() {
18591
- this.pageTracker.stop(), this.domIntrospector.stopCapturing(), this.navigationCompleteDetector && this.navigationCompleteDetector.stop(), this.pipecatClient && (await this.pipecatClient.disconnect(), this.pipecatClient = null), this.transport && (this.transport = null), this.audioElements && (this.audioElements.forEach((t) => {
18607
+ this.pageTracker.stop(), this.domIntrospector.stopCapturing(), this.navigationCompleteDetector && this.navigationCompleteDetector.stop(), this.overlay.clearHighlight(), this.pipecatClient && (await this.pipecatClient.disconnect(), this.pipecatClient = null), this.transport && (this.transport = null), this.audioElements && (this.audioElements.forEach((t) => {
18592
18608
  t.pause(), t.remove();
18593
- }), this.audioElements = []), this.botAudioAnalyzer && (this.botAudioAnalyzer.destroy(), this.botAudioAnalyzer = null), this.userAudioAnalyzer && (this.userAudioAnalyzer.destroy(), this.userAudioAnalyzer = null), this.userMicStream && (this.userMicStream.getTracks().forEach((t) => t.stop()), this.userMicStream = null), this.audioLevels = [], this.reactRoot && (this.reactRoot.unmount(), this.reactRoot = null), this.reactContainer && (this.reactContainer.remove(), this.reactContainer = null), this.overlay.remove(), this.isInitialized = !1, this.isConnected = !1, this.agentState = "idle", console.log("[OnboardingSDK] Disconnected"), this.emit("disconnected");
18609
+ }), this.audioElements = []), this.botAudioAnalyzer && (this.botAudioAnalyzer.destroy(), this.botAudioAnalyzer = null), this.userAudioAnalyzer && (this.userAudioAnalyzer.destroy(), this.userAudioAnalyzer = null), this.userMicStreamRequestId++, this.userMicStream && (this.userMicStream.getTracks().forEach((t) => t.stop()), this.userMicStream = null), this.audioLevels = [], this.reactRoot && (this.reactRoot.unmount(), this.reactRoot = null), this.reactContainer && (this.reactContainer.remove(), this.reactContainer = null), this.overlay.remove(), this.isInitialized = !1, this.isConnected = !1, this.agentState = "idle", console.log("[OnboardingSDK] Disconnected"), this.emit("disconnected");
18594
18610
  }
18595
18611
  }
18596
18612
  typeof window < "u" && (window.OnboardingSDK = ec);