@floe-ai/sdk 0.1.0-dev.16 → 0.1.0-dev.17

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.
@@ -17071,6 +17071,38 @@ class ic extends th {
17071
17071
  generateSessionId() {
17072
17072
  return `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
17073
17073
  }
17074
+ /**
17075
+ * Validate client key and check if bot is enabled for this site.
17076
+ * This is called before showing any UI to ensure the bot should be displayed.
17077
+ */
17078
+ async validateClientKeyAndBotStatus() {
17079
+ const t = new AbortController(), r = setTimeout(() => t.abort(), 4e3);
17080
+ try {
17081
+ const i = await fetch(`${this.config.apiUrl}/sites/validate-client-key`, {
17082
+ method: "POST",
17083
+ headers: {
17084
+ "Content-Type": "application/json"
17085
+ },
17086
+ body: JSON.stringify({
17087
+ clientKey: this.config.clientKey,
17088
+ origin: window.location.origin
17089
+ }),
17090
+ signal: t.signal
17091
+ });
17092
+ if (clearTimeout(r), !i.ok) {
17093
+ let s = null;
17094
+ try {
17095
+ s = await i.json();
17096
+ } catch {
17097
+ }
17098
+ return { valid: !1, error: (s == null ? void 0 : s.error) || i.statusText || `HTTP ${i.status}` };
17099
+ }
17100
+ const o = await i.json();
17101
+ return o.valid ? { valid: !0 } : { valid: !1, error: o.error || "Validation failed" };
17102
+ } catch (i) {
17103
+ return clearTimeout(r), i instanceof TypeError || i instanceof DOMException && i.name === "AbortError" ? (console.warn("[OnboardingSDK] Client key validation failed due to network/timeout, proceeding anyway:", i), { valid: !0 }) : (console.warn("[OnboardingSDK] Unexpected error during client key validation:", i), { valid: !1 });
17104
+ }
17105
+ }
17074
17106
  /**
17075
17107
  * Start screen sharing: sends the tab/window as a WebRTC video track to Pipecat.
17076
17108
  */
@@ -17090,17 +17122,22 @@ class ic extends th {
17090
17122
  return;
17091
17123
  }
17092
17124
  try {
17125
+ const t = await this.validateClientKeyAndBotStatus();
17126
+ if (!t.valid) {
17127
+ this.config.debug && console.log("[OnboardingSDK] Bot is disabled or invalid:", t.error);
17128
+ return;
17129
+ }
17093
17130
  this.overlay.inject(), this.initReactUI(), this.config.userInfo && (this.config.userInfo.externalId || this.config.userInfo.email) && await this.checkEndUserStatus();
17094
- const t = this.shouldSkipOnboardingModal();
17095
- let r = !0;
17096
- if (t)
17097
- console.log("[OnboardingSDK] 🔄 Skipping onboarding modal for returning user"), this._discoveryPopupShown = !0, this.isReturningUser = !0, r = !1, console.log("[OnboardingSDK] Bot will stay closed - user clicks to start");
17131
+ const r = this.shouldSkipOnboardingModal();
17132
+ let i = !0;
17133
+ if (r)
17134
+ console.log("[OnboardingSDK] 🔄 Skipping onboarding modal for returning user"), this._discoveryPopupShown = !0, this.isReturningUser = !0, i = !1, console.log("[OnboardingSDK] Bot will stay closed - user clicks to start");
17098
17135
  else if (this.config.enableDiscoveryPopup !== !1) {
17099
17136
  console.log("[OnboardingSDK] 🎉 Showing welcome popup before connect");
17100
- const s = await this.showWelcomePopupAsync();
17101
- this._discoveryPopupShown = !0, this.markUserVisited(), s ? (this._pendingDiscoveryStart = !0, console.log("[OnboardingSDK] User chose guided discovery - will start after connect"), r = !0) : (console.log("[OnboardingSDK] User skipped onboarding - bot will stay closed"), this.hasSkippedOnboarding = !0, r = !1);
17137
+ const a = await this.showWelcomePopupAsync();
17138
+ this._discoveryPopupShown = !0, this.markUserVisited(), a ? (this._pendingDiscoveryStart = !0, console.log("[OnboardingSDK] User chose guided discovery - will start after connect"), i = !0) : (console.log("[OnboardingSDK] User skipped onboarding - bot will stay closed"), this.hasSkippedOnboarding = !0, i = !1);
17102
17139
  }
17103
- if (!r) {
17140
+ if (!i) {
17104
17141
  console.log("[OnboardingSDK] 📍 Initialized in minimized state - user clicks to connect"), this._isMinimized = !0, this.agentState = "idle", this.isInitialized = !0, this.renderReactUI(), this.emit("ready");
17105
17142
  return;
17106
17143
  }
@@ -17111,9 +17148,9 @@ class ic extends th {
17111
17148
  enableScreenShare: this.config.enableScreenCapture || !1,
17112
17149
  callbacks: this.createPipecatCallbacks()
17113
17150
  }), await this.pipecatClient.initDevices(), console.log("[OnboardingSDK] Devices initialized"), this.setupAudioPlayback();
17114
- const i = `${this.config.apiUrl}/sites/start-session`;
17115
- console.log("[OnboardingSDK] Starting session via floe-api proxy:", i);
17116
- const o = {
17151
+ const o = `${this.config.apiUrl}/sites/start-session`;
17152
+ console.log("[OnboardingSDK] Starting session via floe-api proxy:", o);
17153
+ const s = {
17117
17154
  clientKey: this.config.clientKey,
17118
17155
  origin: window.location.origin,
17119
17156
  sessionData: {
@@ -17122,16 +17159,16 @@ class ic extends th {
17122
17159
  dailyRoomProperties: { start_video_off: !0 }
17123
17160
  }
17124
17161
  };
17125
- if (this.config.userInfo && (o.sessionData.userInfo = this.config.userInfo), await this.pipecatClient.startBotAndConnect({
17126
- endpoint: i,
17127
- requestData: o
17162
+ if (this.config.userInfo && (s.sessionData.userInfo = this.config.userInfo), await this.pipecatClient.startBotAndConnect({
17163
+ endpoint: o,
17164
+ requestData: s
17128
17165
  // Type assertion needed for nested structure
17129
17166
  }), this.config.enableScreenCapture)
17130
17167
  if (await this.overlay.showScreenShareModal())
17131
17168
  try {
17132
17169
  await this.startScreenShare();
17133
- } catch (a) {
17134
- console.error("[OnboardingSDK] Screen share failed:", a);
17170
+ } catch (c) {
17171
+ console.error("[OnboardingSDK] Screen share failed:", c);
17135
17172
  }
17136
17173
  else
17137
17174
  console.log("[OnboardingSDK] Screen share declined by user");