obi-sdk 0.6.5 → 0.6.6

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.
@@ -18,9 +18,9 @@ export declare const ObiSDKConfigSchema: z.ZodObject<{
18
18
  metadata?: any;
19
19
  }>>;
20
20
  }, "strip", z.ZodTypeAny, {
21
+ debug: boolean;
21
22
  enableVoice: boolean;
22
23
  enableScreenCapture: boolean;
23
- debug: boolean;
24
24
  apiKey?: string | undefined;
25
25
  user?: {
26
26
  id: string;
@@ -29,9 +29,9 @@ export declare const ObiSDKConfigSchema: z.ZodObject<{
29
29
  } | undefined;
30
30
  }, {
31
31
  apiKey?: string | undefined;
32
+ debug?: boolean | undefined;
32
33
  enableVoice?: boolean | undefined;
33
34
  enableScreenCapture?: boolean | undefined;
34
- debug?: boolean | undefined;
35
35
  user?: {
36
36
  id: string;
37
37
  email?: string | undefined;
@@ -0,0 +1,6 @@
1
+ import { O } from "./obi-widget-94e8c026.js";
2
+ import "./types-e0297e7b.js";
3
+ export {
4
+ O as ObiWidget
5
+ };
6
+ //# sourceMappingURL=index-d7a5d2f6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-d7a5d2f6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -497,6 +497,11 @@ class ObiClient {
497
497
  params: { path: { id } }
498
498
  });
499
499
  }
500
+ async startSession(id, token) {
501
+ return await this.client.GET("/sessions/{id}/start-session", {
502
+ params: { path: { id }, query: token ? { token } : {} }
503
+ });
504
+ }
500
505
  async getSessionRecording(id) {
501
506
  return await this.client.GET("/sessions/{id}/recording", {
502
507
  params: { path: { id } }
@@ -10108,53 +10113,6 @@ function n$2(t2) {
10108
10113
  function r$1(r2) {
10109
10114
  return n$2({ ...r2, state: true, attribute: false });
10110
10115
  }
10111
- class StorageManager {
10112
- /**
10113
- * Create a new StorageManager with a specific namespace
10114
- * @param namespace The namespace to prefix all keys with
10115
- */
10116
- constructor(namespace) {
10117
- this.namespace = namespace;
10118
- }
10119
- /**
10120
- * Get a value from localStorage with the namespace prefix
10121
- * @param key The key to retrieve
10122
- * @returns The stored value or null if not found
10123
- */
10124
- getItem(key) {
10125
- return localStorage.getItem(`${this.namespace}.${key}`);
10126
- }
10127
- /**
10128
- * Set a value in localStorage with the namespace prefix
10129
- * @param key The key to set
10130
- * @param value The value to store
10131
- */
10132
- setItem(key, value) {
10133
- localStorage.setItem(`${this.namespace}.${key}`, value);
10134
- }
10135
- /**
10136
- * Remove a value from localStorage with the namespace prefix
10137
- * @param key The key to remove
10138
- */
10139
- removeItem(key) {
10140
- localStorage.removeItem(`${this.namespace}.${key}`);
10141
- }
10142
- /**
10143
- * Clear all keys that belong to this namespace
10144
- */
10145
- clear() {
10146
- for (let i3 = 0; i3 < localStorage.length; i3++) {
10147
- const key = localStorage.key(i3);
10148
- if (key && key.startsWith(`${this.namespace}.`)) {
10149
- localStorage.removeItem(key);
10150
- }
10151
- }
10152
- }
10153
- }
10154
- const STORAGE_KEYS = {
10155
- SESSION_DATA: "session_data"
10156
- };
10157
- const storage = new StorageManager("io.obi.widget");
10158
10116
  const DEBUG_BUILD$2 = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
10159
10117
  const SDK_VERSION = "9.23.0";
10160
10118
  const GLOBAL_OBJ = globalThis;
@@ -16016,6 +15974,53 @@ function withComponentErrorTracking(componentName) {
16016
15974
  }
16017
15975
  };
16018
15976
  }
15977
+ class StorageManager {
15978
+ /**
15979
+ * Create a new StorageManager with a specific namespace
15980
+ * @param namespace The namespace to prefix all keys with
15981
+ */
15982
+ constructor(namespace) {
15983
+ this.namespace = namespace;
15984
+ }
15985
+ /**
15986
+ * Get a value from localStorage with the namespace prefix
15987
+ * @param key The key to retrieve
15988
+ * @returns The stored value or null if not found
15989
+ */
15990
+ getItem(key) {
15991
+ return localStorage.getItem(`${this.namespace}.${key}`);
15992
+ }
15993
+ /**
15994
+ * Set a value in localStorage with the namespace prefix
15995
+ * @param key The key to set
15996
+ * @param value The value to store
15997
+ */
15998
+ setItem(key, value) {
15999
+ localStorage.setItem(`${this.namespace}.${key}`, value);
16000
+ }
16001
+ /**
16002
+ * Remove a value from localStorage with the namespace prefix
16003
+ * @param key The key to remove
16004
+ */
16005
+ removeItem(key) {
16006
+ localStorage.removeItem(`${this.namespace}.${key}`);
16007
+ }
16008
+ /**
16009
+ * Clear all keys that belong to this namespace
16010
+ */
16011
+ clear() {
16012
+ for (let i3 = 0; i3 < localStorage.length; i3++) {
16013
+ const key = localStorage.key(i3);
16014
+ if (key && key.startsWith(`${this.namespace}.`)) {
16015
+ localStorage.removeItem(key);
16016
+ }
16017
+ }
16018
+ }
16019
+ }
16020
+ const STORAGE_KEYS = {
16021
+ SESSION_DATA: "session_data"
16022
+ };
16023
+ const storage = new StorageManager("io.obi.widget");
16019
16024
  var __defProp$7 = Object.defineProperty;
16020
16025
  var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
16021
16026
  var __decorateClass$7 = (decorators, target, key, kind) => {
@@ -17601,199 +17606,245 @@ class ObiWidget extends i$1 {
17601
17606
  this.obiClient = null;
17602
17607
  this.closeNavTimeoutRef = null;
17603
17608
  this.researchingTimeoutRef = null;
17604
- this.connectObi = withSentryAsyncHandler(async (sessionToken) => {
17605
- if (this.activeSession) {
17606
- trackEvent("connection_already_exists", { sessionToken }, "ObiWidget");
17607
- console.log("Connection already exists");
17608
- return;
17609
- }
17610
- trackEvent("session_connection_started", { sessionToken }, "ObiWidget");
17611
- setGlobalContext({ sessionId: sessionToken });
17612
- try {
17613
- const session = this.createSession(sessionToken);
17614
- if (!session) {
17615
- this.handleSessionCreationFailure(() => this.removeSessionUrlParams());
17609
+ this.connectObi = withSentryAsyncHandler(
17610
+ async (sessionToken) => {
17611
+ if (this.activeSession) {
17612
+ trackEvent("connection_already_exists", { sessionToken }, "ObiWidget");
17613
+ console.log("Connection already exists");
17616
17614
  return;
17617
17615
  }
17618
- this.setupSessionEventListeners(session, () => this.removeSessionUrlParams());
17619
- session.on("screenCaptureRequested", withSentryAsyncHandler(async () => {
17620
- trackEvent("screen_capture_requested", {}, "ObiWidget");
17621
- try {
17622
- const canvas = await html2canvas(document.documentElement, {
17623
- useCORS: true,
17624
- allowTaint: true,
17625
- foreignObjectRendering: true
17626
- });
17627
- const dataUrl = canvas.toDataURL("image/png");
17628
- this.activeSession.emit("screenCaptureComplete", dataUrl);
17629
- trackEvent("screen_capture_completed", {}, "ObiWidget");
17630
- } catch (e2) {
17631
- captureException(e2, {
17632
- componentName: "ObiWidget",
17633
- handlerName: "screenCaptureRequested",
17634
- sessionToken
17616
+ trackEvent("session_connection_started", { sessionToken }, "ObiWidget");
17617
+ setGlobalContext({ sessionId: sessionToken });
17618
+ try {
17619
+ const session = this.createSession(sessionToken);
17620
+ if (!session) {
17621
+ this.handleSessionCreationFailure(() => this.removeSessionUrlParams());
17622
+ return;
17623
+ }
17624
+ this.setupSessionEventListeners(session, () => this.removeSessionUrlParams());
17625
+ session.on(
17626
+ "screenCaptureRequested",
17627
+ withSentryAsyncHandler(
17628
+ async () => {
17629
+ trackEvent("screen_capture_requested", {}, "ObiWidget");
17630
+ try {
17631
+ const canvas = await html2canvas(document.documentElement, {
17632
+ useCORS: true,
17633
+ allowTaint: true,
17634
+ foreignObjectRendering: true
17635
+ });
17636
+ const dataUrl = canvas.toDataURL("image/png");
17637
+ this.activeSession.emit("screenCaptureComplete", dataUrl);
17638
+ trackEvent("screen_capture_completed", {}, "ObiWidget");
17639
+ } catch (e2) {
17640
+ captureException(e2, {
17641
+ componentName: "ObiWidget",
17642
+ handlerName: "screenCaptureRequested",
17643
+ sessionToken
17644
+ });
17645
+ console.error("[obi] error capturing screen:", e2);
17646
+ this.activeSession.emit("screenCaptureComplete", "error");
17647
+ trackEvent(
17648
+ "screen_capture_failed",
17649
+ {
17650
+ error: e2 instanceof Error ? e2.message : String(e2)
17651
+ },
17652
+ "ObiWidget"
17653
+ );
17654
+ }
17655
+ },
17656
+ "screenCaptureRequested",
17657
+ "ObiWidget"
17658
+ )
17659
+ );
17660
+ const connectionInfo = await session.connect();
17661
+ if (connectionInfo) {
17662
+ this.sessionToken = sessionToken;
17663
+ this.roomToken = connectionInfo.token;
17664
+ this.roomUrl = connectionInfo.url;
17665
+ setGlobalContext({
17666
+ sessionId: sessionToken,
17667
+ widgetState: this.state.toString()
17635
17668
  });
17636
- console.error("[obi] error capturing screen:", e2);
17637
- this.activeSession.emit("screenCaptureComplete", "error");
17638
- trackEvent("screen_capture_failed", {
17639
- error: e2 instanceof Error ? e2.message : String(e2)
17640
- }, "ObiWidget");
17669
+ this.removeSessionUrlParams();
17670
+ trackEvent(
17671
+ "session_connection_established",
17672
+ {
17673
+ sessionToken,
17674
+ hasRoomToken: !!connectionInfo.token
17675
+ },
17676
+ "ObiWidget"
17677
+ );
17641
17678
  }
17642
- }, "screenCaptureRequested", "ObiWidget"));
17643
- const connectionInfo = await session.connect();
17644
- if (connectionInfo) {
17645
- this.sessionToken = sessionToken;
17646
- this.roomToken = connectionInfo.token;
17647
- this.roomUrl = connectionInfo.url;
17648
- setGlobalContext({
17649
- sessionId: sessionToken,
17650
- widgetState: this.state.toString()
17679
+ this.activeSession = session;
17680
+ } catch (error) {
17681
+ console.error("Failed to start session:", error);
17682
+ captureException(error, {
17683
+ componentName: "ObiWidget",
17684
+ handlerName: "connectObi",
17685
+ sessionToken
17651
17686
  });
17652
- this.removeSessionUrlParams();
17653
- trackEvent("session_connection_established", {
17654
- sessionToken,
17655
- hasRoomToken: !!connectionInfo.token
17656
- }, "ObiWidget");
17687
+ this.handleSessionCreationFailure(() => this.removeSessionUrlParams());
17657
17688
  }
17658
- this.activeSession = session;
17659
- } catch (error) {
17660
- console.error("Failed to start session:", error);
17661
- captureException(error, {
17662
- componentName: "ObiWidget",
17663
- handlerName: "connectObi",
17664
- sessionToken
17665
- });
17666
- this.handleSessionCreationFailure(() => this.removeSessionUrlParams());
17667
- }
17668
- }, "connectObi", "ObiWidget");
17689
+ },
17690
+ "connectObi",
17691
+ "ObiWidget"
17692
+ );
17669
17693
  this.handleCourseSelectEvent = (event) => {
17670
17694
  const customEvent = event;
17671
17695
  this.selectedCourse = customEvent.detail;
17672
17696
  this.showCourseModal = false;
17673
17697
  this.showSessionStartModal = true;
17674
17698
  };
17675
- this.handleUrlSessionEvent = withSentryAsyncHandler(async (sessionToken) => {
17676
- trackEvent("url_session_event", { sessionToken }, "ObiWidget");
17677
- try {
17678
- if (!this.obiClient) {
17679
- const error = new Error("ObiClient not initialized");
17699
+ this.handleUrlSessionEvent = withSentryAsyncHandler(
17700
+ async (sessionToken) => {
17701
+ trackEvent("url_session_event", { sessionToken }, "ObiWidget");
17702
+ try {
17703
+ if (!this.obiClient) {
17704
+ const error = new Error("ObiClient not initialized");
17705
+ captureException(error, {
17706
+ componentName: "ObiWidget",
17707
+ handlerName: "handleUrlSessionEvent",
17708
+ sessionToken
17709
+ });
17710
+ console.error("ObiClient not initialized");
17711
+ return;
17712
+ }
17713
+ const sessionsResponse = await this.obiClient.startSession(sessionToken, this.apiKey);
17714
+ if (sessionsResponse.data) {
17715
+ const { session } = sessionsResponse.data;
17716
+ console.log("[obi-sdk] session:", session);
17717
+ trackEvent(
17718
+ "session_started",
17719
+ {
17720
+ sessionId: session?.id,
17721
+ sessionToken
17722
+ },
17723
+ "ObiWidget"
17724
+ );
17725
+ if (session) {
17726
+ const sessionWithPlan = session;
17727
+ this.selectedCourse = {
17728
+ id: sessionToken,
17729
+ name: sessionWithPlan.onboarding_plan?.name || "",
17730
+ description: sessionWithPlan.onboarding_plan?.description || ""
17731
+ };
17732
+ this.state = SDKState.LOADING;
17733
+ this.showSessionStartModal = true;
17734
+ trackEvent(
17735
+ "matching_session_found",
17736
+ {
17737
+ sessionToken,
17738
+ hasOnboardingPlan: !!sessionWithPlan.onboarding_plan
17739
+ },
17740
+ "ObiWidget"
17741
+ );
17742
+ } else {
17743
+ console.log("[obi-sdk] no session found with token:", sessionToken);
17744
+ trackEvent("no_matching_session", { sessionToken }, "ObiWidget");
17745
+ }
17746
+ }
17747
+ } catch (error) {
17748
+ console.error("Failed to fetch session details:", error);
17680
17749
  captureException(error, {
17681
17750
  componentName: "ObiWidget",
17682
17751
  handlerName: "handleUrlSessionEvent",
17683
17752
  sessionToken
17684
17753
  });
17685
- console.error("ObiClient not initialized");
17754
+ }
17755
+ },
17756
+ "handleUrlSessionEvent",
17757
+ "ObiWidget"
17758
+ );
17759
+ this.handleSessionStart = withSentryAsyncHandler(
17760
+ async (sessionToken) => {
17761
+ trackEvent("session_start_requested", { sessionToken }, "ObiWidget");
17762
+ if (this.activeSession) {
17763
+ trackEvent("session_start_blocked", { sessionToken }, "ObiWidget");
17764
+ console.log("Connection already in progress or active session exists");
17686
17765
  return;
17687
17766
  }
17688
- const sessionsResponse = await this.obiClient.listSessions(this.apiKey);
17689
- if (sessionsResponse.data) {
17690
- const sessions = sessionsResponse.data.sessions;
17691
- console.log("[obi-sdk] sessions:", sessions);
17692
- trackEvent("sessions_fetched", {
17693
- sessionCount: sessions?.length || 0,
17694
- sessionToken
17695
- }, "ObiWidget");
17696
- const matchingSession = sessions?.find((session) => session.uuid === sessionToken);
17697
- if (matchingSession) {
17698
- const sessionWithPlan = matchingSession;
17699
- this.selectedCourse = {
17700
- id: sessionToken,
17701
- name: sessionWithPlan.onboarding_plan?.name || "",
17702
- description: sessionWithPlan.onboarding_plan?.description || ""
17703
- };
17704
- this.state = SDKState.LOADING;
17705
- this.showSessionStartModal = true;
17706
- trackEvent("matching_session_found", {
17767
+ this.showSessionStartModal = false;
17768
+ this.state = SDKState.LOADING;
17769
+ setGlobalContext({ widgetState: this.state.toString() });
17770
+ await this.connectObi(sessionToken);
17771
+ },
17772
+ "handleSessionStart",
17773
+ "ObiWidget"
17774
+ );
17775
+ this.checkExistingSession = withSentryAsyncHandler(
17776
+ async () => {
17777
+ trackEvent("checking_existing_session", {}, "ObiWidget");
17778
+ try {
17779
+ const sessionData = JSON.parse(
17780
+ storage.getItem(STORAGE_KEYS.SESSION_DATA) || "{}"
17781
+ );
17782
+ const { sessionToken, roomToken, roomUrl, sessionExpiry, obiState } = sessionData;
17783
+ if (!sessionToken || !roomToken || !roomUrl) {
17784
+ trackEvent("no_existing_session_data", {}, "ObiWidget");
17785
+ return;
17786
+ }
17787
+ console.log("[obi-sdk] using existing session");
17788
+ trackEvent(
17789
+ "existing_session_data_found",
17790
+ {
17707
17791
  sessionToken,
17708
- hasOnboardingPlan: !!sessionWithPlan.onboarding_plan
17709
- }, "ObiWidget");
17710
- } else {
17711
- console.log("[obi-sdk] no session found with token:", sessionToken);
17712
- trackEvent("no_matching_session", { sessionToken }, "ObiWidget");
17792
+ hasExpiry: !!sessionExpiry,
17793
+ obiState
17794
+ },
17795
+ "ObiWidget"
17796
+ );
17797
+ if (sessionExpiry) {
17798
+ const expiryDate = new Date(sessionExpiry);
17799
+ if (expiryDate < /* @__PURE__ */ new Date()) {
17800
+ this.clearSessionStorage();
17801
+ trackEvent("session_expired", { sessionToken }, "ObiWidget");
17802
+ return;
17803
+ }
17713
17804
  }
17714
- }
17715
- } catch (error) {
17716
- console.error("Failed to fetch session details:", error);
17717
- captureException(error, {
17718
- componentName: "ObiWidget",
17719
- handlerName: "handleUrlSessionEvent",
17720
- sessionToken
17721
- });
17722
- }
17723
- }, "handleUrlSessionEvent", "ObiWidget");
17724
- this.handleSessionStart = withSentryAsyncHandler(async (sessionToken) => {
17725
- trackEvent("session_start_requested", { sessionToken }, "ObiWidget");
17726
- if (this.activeSession) {
17727
- trackEvent("session_start_blocked", { sessionToken }, "ObiWidget");
17728
- console.log("Connection already in progress or active session exists");
17729
- return;
17730
- }
17731
- this.showSessionStartModal = false;
17732
- this.state = SDKState.LOADING;
17733
- setGlobalContext({ widgetState: this.state.toString() });
17734
- await this.connectObi(sessionToken);
17735
- }, "handleSessionStart", "ObiWidget");
17736
- this.checkExistingSession = withSentryAsyncHandler(async () => {
17737
- trackEvent("checking_existing_session", {}, "ObiWidget");
17738
- try {
17739
- const sessionData = JSON.parse(
17740
- storage.getItem(STORAGE_KEYS.SESSION_DATA) || "{}"
17741
- );
17742
- const { sessionToken, roomToken, roomUrl, sessionExpiry, obiState } = sessionData;
17743
- if (!sessionToken || !roomToken || !roomUrl) {
17744
- trackEvent("no_existing_session_data", {}, "ObiWidget");
17745
- return;
17746
- }
17747
- console.log("[obi-sdk] using existing session");
17748
- trackEvent("existing_session_data_found", {
17749
- sessionToken,
17750
- hasExpiry: !!sessionExpiry,
17751
- obiState
17752
- }, "ObiWidget");
17753
- if (sessionExpiry) {
17754
- const expiryDate = new Date(sessionExpiry);
17755
- if (expiryDate < /* @__PURE__ */ new Date()) {
17756
- this.clearSessionStorage();
17757
- trackEvent("session_expired", { sessionToken }, "ObiWidget");
17805
+ this.state = SDKState.LOADING;
17806
+ setGlobalContext({
17807
+ sessionId: sessionToken,
17808
+ widgetState: this.state.toString()
17809
+ });
17810
+ const session = this.createSession(sessionToken);
17811
+ if (!session) {
17812
+ this.handleSessionCreationFailure(() => this.clearSessionStorage());
17758
17813
  return;
17759
17814
  }
17760
- }
17761
- this.state = SDKState.LOADING;
17762
- setGlobalContext({
17763
- sessionId: sessionToken,
17764
- widgetState: this.state.toString()
17765
- });
17766
- const session = this.createSession(sessionToken);
17767
- if (!session) {
17815
+ this.setupSessionEventListeners(session, () => this.clearSessionStorage());
17816
+ const reconnected = await session.reconnect(roomUrl, roomToken, obiState);
17817
+ if (reconnected) {
17818
+ this.activeSession = session;
17819
+ this.sessionToken = sessionToken;
17820
+ this.roomToken = roomToken;
17821
+ this.roomUrl = roomUrl;
17822
+ this.state = obiState;
17823
+ this.storedActiveState = obiState;
17824
+ trackEvent(
17825
+ "session_reconnected",
17826
+ {
17827
+ sessionToken,
17828
+ obiState
17829
+ },
17830
+ "ObiWidget"
17831
+ );
17832
+ } else {
17833
+ this.clearSessionStorage();
17834
+ trackEvent("session_reconnection_failed", { sessionToken }, "ObiWidget");
17835
+ }
17836
+ } catch (error) {
17837
+ console.error("Error reconnecting to session:", error);
17838
+ captureException(error, {
17839
+ componentName: "ObiWidget",
17840
+ handlerName: "checkExistingSession"
17841
+ });
17768
17842
  this.handleSessionCreationFailure(() => this.clearSessionStorage());
17769
- return;
17770
- }
17771
- this.setupSessionEventListeners(session, () => this.clearSessionStorage());
17772
- const reconnected = await session.reconnect(roomUrl, roomToken, obiState);
17773
- if (reconnected) {
17774
- this.activeSession = session;
17775
- this.sessionToken = sessionToken;
17776
- this.roomToken = roomToken;
17777
- this.roomUrl = roomUrl;
17778
- this.state = obiState;
17779
- this.storedActiveState = obiState;
17780
- trackEvent("session_reconnected", {
17781
- sessionToken,
17782
- obiState
17783
- }, "ObiWidget");
17784
- } else {
17785
- this.clearSessionStorage();
17786
- trackEvent("session_reconnection_failed", { sessionToken }, "ObiWidget");
17787
17843
  }
17788
- } catch (error) {
17789
- console.error("Error reconnecting to session:", error);
17790
- captureException(error, {
17791
- componentName: "ObiWidget",
17792
- handlerName: "checkExistingSession"
17793
- });
17794
- this.handleSessionCreationFailure(() => this.clearSessionStorage());
17795
- }
17796
- }, "checkExistingSession", "ObiWidget");
17844
+ },
17845
+ "checkExistingSession",
17846
+ "ObiWidget"
17847
+ );
17797
17848
  try {
17798
17849
  const errorTracker = withComponentErrorTracking("ObiWidget");
17799
17850
  errorTracker.setContext();
@@ -18355,4 +18406,4 @@ export {
18355
18406
  withSentryAsyncHandler as w,
18356
18407
  x
18357
18408
  };
18358
- //# sourceMappingURL=obi-widget-9e8ccac7.js.map
18409
+ //# sourceMappingURL=obi-widget-94e8c026.js.map