obi-sdk 0.12.1 → 0.12.3

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.
@@ -0,0 +1,30 @@
1
+ import { ObiAssistantConfig } from "../types/sdk";
2
+ export interface ConfigLogEntry {
3
+ timestamp: number;
4
+ source: 'initial' | 'update';
5
+ previousConfig: ObiAssistantConfig | null;
6
+ newConfig: ObiAssistantConfig;
7
+ diff: ConfigDiff;
8
+ }
9
+ export interface ConfigDiff {
10
+ added: Record<string, any>;
11
+ modified: Record<string, {
12
+ from: any;
13
+ to: any;
14
+ }>;
15
+ removed: Record<string, any>;
16
+ }
17
+ export declare class ConfigLogger {
18
+ private history;
19
+ private currentConfig;
20
+ logInitialConfig(config: ObiAssistantConfig): void;
21
+ logConfigUpdate(newConfig: ObiAssistantConfig): void;
22
+ getHistory(): ConfigLogEntry[];
23
+ getLatest(): ObiAssistantConfig | null;
24
+ getDiff(index: number): ConfigDiff | null;
25
+ clear(): void;
26
+ getFormattedHistory(): string;
27
+ private deepClone;
28
+ private calculateDiff;
29
+ private isEqual;
30
+ }
@@ -0,0 +1,6 @@
1
+ import { O } from "./obi-widget-fa809230.js";
2
+ import "./types-e0297e7b.js";
3
+ export {
4
+ O as ObiWidget
5
+ };
6
+ //# sourceMappingURL=index-dfc59383.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-dfc59383.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -609,6 +609,12 @@ class ObiClient {
609
609
  params: { path: { id } }
610
610
  });
611
611
  }
612
+ async updateSession(id, data) {
613
+ return await this.client.PATCH("/sessions/{id}", {
614
+ params: { path: { id } },
615
+ body: data
616
+ });
617
+ }
612
618
  async getJoinToken(token, { skipIntro, user } = {}) {
613
619
  return await this.client.GET("/join-token", {
614
620
  params: {
@@ -632,6 +638,7 @@ class ObiSession {
632
638
  constructor({ sessionId, apiBaseUrl, user }) {
633
639
  this.currentState = SDKState.READY;
634
640
  this.livekitState = "speaking";
641
+ this.agentHasSpoken = false;
635
642
  this.assistantAudioContext = null;
636
643
  this.userAudioContext = null;
637
644
  this._assistantAudioTimer = null;
@@ -699,6 +706,12 @@ class ObiSession {
699
706
  if (this.currentState === SDKState.RESEARCHING || this.currentState === SDKState.PAUSED)
700
707
  return;
701
708
  const state = attributes["lk.agent.state"];
709
+ if (state === "speaking") {
710
+ this.agentHasSpoken = true;
711
+ }
712
+ if (!this.agentHasSpoken) {
713
+ return;
714
+ }
702
715
  const newState = z$2(state).with("listening", () => SDKState.USER_SPEAKING).with("speaking", () => SDKState.AGENT_SPEAKING).with("thinking", () => SDKState.THINKING).otherwise(() => void 0);
703
716
  if (!newState)
704
717
  return;
@@ -961,6 +974,7 @@ class ObiSession {
961
974
  this.emitter.emit("error", new Error("Missing room URL or token for reconnection"));
962
975
  return false;
963
976
  }
977
+ this.agentHasSpoken = true;
964
978
  await this.requestMicrophone();
965
979
  this.room = new Room({
966
980
  adaptiveStream: true,
@@ -987,6 +1001,41 @@ class ObiSession {
987
1001
  return false;
988
1002
  }
989
1003
  }
1004
+ /**
1005
+ * Update user information for the current session.
1006
+ * This method updates the user data and notifies the agent if connected.
1007
+ * @param user The new user information or undefined to clear user data
1008
+ * @throws Error if there is no running session
1009
+ */
1010
+ async updateUser(user) {
1011
+ if (!this.room) {
1012
+ throw new Error("Cannot update user: No active session");
1013
+ }
1014
+ const oldUser = this.user;
1015
+ this.user = user;
1016
+ try {
1017
+ await this.client.updateSession(this.sessionId, {
1018
+ user: user ? JSON.stringify(user) : void 0
1019
+ });
1020
+ if (this.room && this.room.localParticipant) {
1021
+ const userData = {
1022
+ type: "user_updated",
1023
+ user,
1024
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
1025
+ };
1026
+ const jsonData = JSON.stringify(userData);
1027
+ const encoder = new TextEncoder();
1028
+ const data = encoder.encode(jsonData);
1029
+ await this.room.localParticipant.publishData(data, { reliable: true });
1030
+ }
1031
+ this.emitter.emit("userUpdated", user);
1032
+ } catch (error) {
1033
+ this.user = oldUser;
1034
+ console.error("Failed to update user:", error);
1035
+ this.emitter.emit("error", error instanceof Error ? error : new Error(String(error)));
1036
+ throw error;
1037
+ }
1038
+ }
990
1039
  }
991
1040
  const OBI_PRIMARY_COLOR = "#a10fff";
992
1041
  function hexToHsl(hex) {
@@ -15938,7 +15987,7 @@ function createSentryScope() {
15938
15987
  return event;
15939
15988
  },
15940
15989
  // Set release version if available
15941
- release: process.env.npm_package_version || "0.6.2"
15990
+ release: {}.VITE_NPM_PACKAGE_VERSION || "0.6.2"
15942
15991
  });
15943
15992
  const scope2 = new Scope();
15944
15993
  scope2.setClient(client);
@@ -16429,6 +16478,7 @@ class Course extends i$1 {
16429
16478
  this.name = "";
16430
16479
  this.description = "";
16431
16480
  this.duration = 10;
16481
+ this.order = 0;
16432
16482
  this.selected = false;
16433
16483
  this.handleClick = withSentryHandler(
16434
16484
  () => {
@@ -16587,6 +16637,9 @@ __decorateClass$5([
16587
16637
  __decorateClass$5([
16588
16638
  n$2({ type: Number })
16589
16639
  ], Course.prototype, "duration", 2);
16640
+ __decorateClass$5([
16641
+ n$2({ type: Number })
16642
+ ], Course.prototype, "order", 2);
16590
16643
  __decorateClass$5([
16591
16644
  n$2({ type: Boolean })
16592
16645
  ], Course.prototype, "selected", 2);
@@ -16610,17 +16663,18 @@ class CourseList extends i$1 {
16610
16663
  }
16611
16664
  return x`
16612
16665
  <div class="course-grid">
16613
- ${this.courses.map((course) => {
16666
+ ${this.courses.sort((a2, b2) => (a2.order || 0) - (b2.order || 0)).map((course) => {
16614
16667
  const isSelected = course.id === this.selectedCourseId;
16615
16668
  return x`
16616
- <obi-course
16617
- id=${course.id}
16618
- name=${course.name}
16619
- description=${course.description || ""}
16620
- duration=${course.duration}
16621
- ?selected=${isSelected}
16622
- ></obi-course>
16623
- `;
16669
+ <obi-course
16670
+ id=${course.id}
16671
+ name=${course.name}
16672
+ description=${course.description || ""}
16673
+ duration=${course.duration}
16674
+ order=${course.order || 0}
16675
+ ?selected=${isSelected}
16676
+ ></obi-course>
16677
+ `;
16624
16678
  })}
16625
16679
  </div>
16626
16680
  `;
@@ -16739,7 +16793,8 @@ class CourseModal extends i$1 {
16739
16793
  id: session.uuid,
16740
16794
  name: session.onboarding_plan.name,
16741
16795
  description: session.onboarding_plan.description,
16742
- duration: session.onboarding_plan.duration
16796
+ duration: session.onboarding_plan.duration,
16797
+ order: session.onboarding_plan.order
16743
16798
  };
16744
16799
  });
16745
16800
  const filteredCourses = mappedCourses.filter((course) => !!course.name);
@@ -16849,6 +16904,25 @@ class CourseModal extends i$1 {
16849
16904
  Sessions are securely recorded for quality improvement purposes.
16850
16905
  </p>
16851
16906
  </div>
16907
+ <div class="powered-by-container">
16908
+ <a href="https://getcor.ai/" target="_blank" class="powered-by-link">
16909
+ <div style="display: flex; align-items: end; gap: 4px;">
16910
+ <p class="powered-by">Powered by</p>
16911
+ <svg
16912
+ xmlns="http://www.w3.org/2000/svg"
16913
+ width="59"
16914
+ height="16"
16915
+ viewBox="0 0 59 16"
16916
+ fill="none"
16917
+ >
16918
+ <path
16919
+ d="M43.1777 3.86914C46.7404 3.86914 48.9042 6.57952 48.9043 9.77051C48.9043 13.4206 46.7624 16 43.1777 16C39.5498 15.9998 37.4299 13.268 37.4297 9.90234C37.4297 6.40537 39.5714 3.86928 43.1777 3.86914ZM28.8398 0C30.7196 0 32.1619 0.852712 33.1455 1.98926L33.2988 1.07129C33.4518 0.481159 33.8017 0.28418 34.2607 0.28418C35.0036 0.284203 35.1345 0.459008 35.2656 1.11426L35.9658 4.93945C36.097 5.5733 35.9869 5.83598 35.4404 6.12012C34.8287 6.42584 34.4137 6.40382 34.0859 5.90137C32.4466 3.08185 30.9818 2.22949 29.0146 2.22949C25.9547 2.22959 24.2285 4.93988 24.2285 7.95605C24.2286 11.9994 26.6979 13.748 29.4082 13.748C31.5502 13.748 33.517 12.6986 34.5225 10.4912C34.8284 9.90123 35.2877 9.79169 35.834 10.0537C36.4241 10.316 36.4898 10.8626 36.2275 11.4746C35.2002 14.0974 32.7523 15.999 28.8398 15.999C24.0969 15.999 21.3428 12.4584 21.3428 8.30566C21.3428 3.49723 24.4684 5.99482e-05 28.8398 0ZM9.93945 0.0927734C10.9259 0.142615 11.7099 0.956225 11.71 1.95215C11.7098 2.97999 10.8746 3.81329 9.84375 3.81348H6.13086C4.88502 3.9007 3.88179 4.86388 3.73535 6.08887L3.73438 6.10059V9.94141L3.73535 9.9541C3.88896 11.2389 4.98549 12.2353 6.31543 12.2354H9.53613C10.971 12.2352 12.1338 11.0752 12.1338 9.64453V6.09766L12.1367 6.00195C12.1867 5.01847 13.0022 4.23648 14.001 4.23633C15.032 4.23637 15.8681 5.06962 15.8682 6.09766V9.95117L15.8662 10.043C15.8203 10.984 15.073 11.7415 14.1348 11.8076V11.8184C12.8383 11.9038 11.8024 12.9378 11.7168 14.2305H11.7051C11.6364 15.1959 10.8295 15.9578 9.84375 15.958H5.97852C4.94743 15.958 4.11137 15.1247 4.11133 14.0967C4.11133 14.0783 4.11177 14.0595 4.1123 14.041H4.10938C3.92516 12.8594 2.94081 11.9037 1.72559 11.8193V11.8076C0.76079 11.7355 3.38938e-05 10.9317 0 9.95117V6.09766L0.00195312 6.00488C0.0487124 5.05403 0.811457 4.29096 1.76367 4.23926C2.96095 4.13852 3.92677 3.20977 4.10938 2.04102L4.1123 2.02148V2.00293C4.11188 1.9871 4.11133 1.97019 4.11133 1.95215C4.11137 0.924114 4.94744 0.0908305 5.97852 0.0908203H9.84375L9.93945 0.0927734ZM57.3926 4.00684C58.0264 4.00684 58.4639 4.42303 58.4639 5.10059C58.4636 6.17112 57.6773 6.54308 56.541 7.00195C55.2296 7.54837 54.4202 8.26929 54.0049 9.14355V12.8809C54.0049 13.5803 54.2454 13.887 55.6006 14.2148C56.2126 14.4116 56.3438 14.5862 56.3438 15.0889C56.3437 15.5696 56.1687 15.7881 55.666 15.7881H50.5518C50.071 15.7881 49.8956 15.5914 49.8955 15.0889C49.8955 14.6299 50.0055 14.433 50.4863 14.2363C51.2949 13.9085 51.5566 13.5805 51.5566 12.8594V7.72266C51.5566 6.82676 51.4256 6.62971 50.3984 6.23633C49.9834 6.06155 49.8955 5.95228 49.8955 5.53711C49.8955 5.16578 50.0051 5.01258 50.3545 4.90332L52.5625 4.13867C53.4805 3.85454 53.9395 4.02928 53.9395 4.94727V7.02344C54.901 5.23148 56.4308 4.00723 57.3926 4.00684ZM42.8506 5.94629C40.9053 5.94629 39.8994 7.38883 39.8994 9.44336C39.8996 11.6725 41.1016 13.9236 43.5273 13.9238C45.1011 13.9238 46.457 12.7867 46.457 10.4043C46.4569 8.17514 45.189 5.94655 42.8506 5.94629Z"
16920
+ fill="#18181B"
16921
+ />
16922
+ </svg>
16923
+ </div>
16924
+ </a>
16925
+ </div>
16852
16926
  </div>
16853
16927
  `;
16854
16928
  }
@@ -17072,6 +17146,34 @@ CourseModal.styles = i$4`
17072
17146
  height: 20px;
17073
17147
  width: 80%;
17074
17148
  }
17149
+
17150
+ .powered-by-container {
17151
+ position: absolute;
17152
+ bottom: 32px;
17153
+ right: 32px;
17154
+ display: flex;
17155
+ flex-direction: row;
17156
+ align-items: end;
17157
+ justify-content: center;
17158
+ gap: 4px;
17159
+ z-index: 10;
17160
+ }
17161
+
17162
+ .powered-by-link {
17163
+ text-decoration: none;
17164
+ }
17165
+
17166
+ .powered-by {
17167
+ color: #18181b;
17168
+ text-align: center;
17169
+ font-family: "Satoshi", sans-serif;
17170
+ font-size: 12px;
17171
+ font-style: normal;
17172
+ font-weight: 400;
17173
+ line-height: 100%;
17174
+ letter-spacing: -0.12px;
17175
+ margin: 0;
17176
+ }
17075
17177
  `;
17076
17178
  __decorateClass$4([
17077
17179
  n$2({ type: Array })
@@ -17563,6 +17665,16 @@ class SessionStartModal extends i$1 {
17563
17665
  this.error = null;
17564
17666
  this.startAttempts = 0;
17565
17667
  }
17668
+ disconnectedCallback() {
17669
+ super.disconnectedCallback();
17670
+ this._resetState();
17671
+ console.log("[SessionStartModal] Disconnected and state reset.");
17672
+ }
17673
+ _resetState() {
17674
+ this.isLoading = false;
17675
+ this.error = null;
17676
+ this.startAttempts = 0;
17677
+ }
17566
17678
  async handleStart() {
17567
17679
  console.log("[SessionStartModal] Start button clicked", {
17568
17680
  sessionId: this.session?.id,
@@ -17642,14 +17754,18 @@ class SessionStartModal extends i$1 {
17642
17754
  setTimeout(() => {
17643
17755
  if (this.isConnected) {
17644
17756
  captureException(
17645
- new Error("Session start modal did not close after Continue was clicked"),
17757
+ new Error("Session start modal did not close after 'Continue' was clicked"),
17646
17758
  {
17647
17759
  componentName: "SessionStartModal",
17648
17760
  handlerName: "handleStart_timeout",
17649
17761
  sessionId: this.session?.id,
17650
- modalStillVisible: true
17762
+ modalIsStillConnected: true
17651
17763
  }
17652
17764
  );
17765
+ this.isLoading = false;
17766
+ this.showError(
17767
+ "Something went wrong starting the session. Please refresh the window and try again."
17768
+ );
17653
17769
  }
17654
17770
  }, 2e3);
17655
17771
  } catch (error) {
@@ -18477,7 +18593,6 @@ class ObiWidget extends i$1 {
18477
18593
  storedParams[key] = value;
18478
18594
  });
18479
18595
  }
18480
- localStorage.removeItem("obi-url-params");
18481
18596
  return storedParams[SESSION_URL_PARAM];
18482
18597
  }();
18483
18598
  if (!sessionId) {
@@ -18534,12 +18649,23 @@ class ObiWidget extends i$1 {
18534
18649
  }
18535
18650
  this.removeSessionUrlParams();
18536
18651
  }
18537
- handleConfigUpdate(event) {
18652
+ async handleConfigUpdate(event) {
18538
18653
  const customEvent = event;
18539
18654
  const updatedConfig = customEvent.detail;
18540
18655
  const needsInit = updatedConfig.isActive && !this.isActive;
18656
+ const oldUser = this.user;
18541
18657
  this.updateFromConfig();
18542
- if (needsInit && !isCurrentUrlBlacklisted(this.urlBlacklist)) {
18658
+ if (this.activeSession && updatedConfig.user !== void 0) {
18659
+ const newUser = updatedConfig.user;
18660
+ if (JSON.stringify(oldUser) !== JSON.stringify(newUser)) {
18661
+ try {
18662
+ await this.activeSession.updateUser(newUser);
18663
+ } catch (error) {
18664
+ console.error("Failed to update session user data:", error);
18665
+ }
18666
+ }
18667
+ }
18668
+ if (needsInit && !isCurrentUrlBlacklisted(this.urlBlacklist) && !this.activeSession) {
18543
18669
  this.sessionConnectionCheck();
18544
18670
  }
18545
18671
  this.requestUpdate();
@@ -18671,7 +18797,7 @@ class ObiWidget extends i$1 {
18671
18797
  const primaryColor = windowConfig?.primaryColor || dbConfig?.primaryColor || OBI_PRIMARY_COLOR;
18672
18798
  this.style.setProperty("--obi-primary", primaryColor);
18673
18799
  this.generateColorVariables(primaryColor);
18674
- if (this.isActive && !isCurrentUrlBlacklisted(this.urlBlacklist)) {
18800
+ if (this.isActive && !isCurrentUrlBlacklisted(this.urlBlacklist) && !this.activeSession) {
18675
18801
  this.sessionConnectionCheck();
18676
18802
  }
18677
18803
  }
@@ -18972,4 +19098,4 @@ export {
18972
19098
  withSentryAsyncHandler as w,
18973
19099
  x
18974
19100
  };
18975
- //# sourceMappingURL=obi-widget-b64f0c73.js.map
19101
+ //# sourceMappingURL=obi-widget-fa809230.js.map