obi-sdk 0.3.11 → 0.3.13

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.
@@ -1,4 +1,529 @@
1
1
  import { S as SDKState, E as EventEmitter, R as RoomEvent, T as Track, z as z$2, a as Room, A as API_BASE_URL, N as N$1 } from "./types-82772f00.js";
2
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
3
+ function randomID() {
4
+ return Math.random().toString(36).slice(2, 11);
5
+ }
6
+ function createClient(clientOptions) {
7
+ let {
8
+ baseUrl = "",
9
+ Request: CustomRequest = globalThis.Request,
10
+ fetch: baseFetch = globalThis.fetch,
11
+ querySerializer: globalQuerySerializer,
12
+ bodySerializer: globalBodySerializer,
13
+ headers: baseHeaders,
14
+ ...baseOptions
15
+ } = { ...clientOptions };
16
+ baseUrl = removeTrailingSlash(baseUrl);
17
+ const middlewares = [];
18
+ async function coreFetch(schemaPath, fetchOptions) {
19
+ const {
20
+ baseUrl: localBaseUrl,
21
+ fetch: fetch2 = baseFetch,
22
+ Request = CustomRequest,
23
+ headers,
24
+ params = {},
25
+ parseAs = "json",
26
+ querySerializer: requestQuerySerializer,
27
+ bodySerializer = globalBodySerializer ?? defaultBodySerializer,
28
+ body,
29
+ ...init
30
+ } = fetchOptions || {};
31
+ if (localBaseUrl) {
32
+ baseUrl = removeTrailingSlash(localBaseUrl);
33
+ }
34
+ let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
35
+ if (requestQuerySerializer) {
36
+ querySerializer = typeof requestQuerySerializer === "function" ? requestQuerySerializer : createQuerySerializer({
37
+ ...typeof globalQuerySerializer === "object" ? globalQuerySerializer : {},
38
+ ...requestQuerySerializer
39
+ });
40
+ }
41
+ const serializedBody = body === void 0 ? void 0 : bodySerializer(body);
42
+ const defaultHeaders = (
43
+ // with no body, we should not to set Content-Type
44
+ serializedBody === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
45
+ serializedBody instanceof FormData ? {} : {
46
+ "Content-Type": "application/json"
47
+ }
48
+ );
49
+ const requestInit = {
50
+ redirect: "follow",
51
+ ...baseOptions,
52
+ ...init,
53
+ body: serializedBody,
54
+ headers: mergeHeaders(defaultHeaders, baseHeaders, headers, params.header)
55
+ };
56
+ let id;
57
+ let options;
58
+ let request = new CustomRequest(createFinalURL(schemaPath, { baseUrl, params, querySerializer }), requestInit);
59
+ for (const key in init) {
60
+ if (!(key in request)) {
61
+ request[key] = init[key];
62
+ }
63
+ }
64
+ if (middlewares.length) {
65
+ id = randomID();
66
+ options = Object.freeze({
67
+ baseUrl,
68
+ fetch: fetch2,
69
+ parseAs,
70
+ querySerializer,
71
+ bodySerializer
72
+ });
73
+ for (const m2 of middlewares) {
74
+ if (m2 && typeof m2 === "object" && typeof m2.onRequest === "function") {
75
+ const result = await m2.onRequest({
76
+ request,
77
+ schemaPath,
78
+ params,
79
+ options,
80
+ id
81
+ });
82
+ if (result) {
83
+ if (!(result instanceof CustomRequest)) {
84
+ throw new Error("onRequest: must return new Request() when modifying the request");
85
+ }
86
+ request = result;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ let response = await fetch2(request);
92
+ if (middlewares.length) {
93
+ for (let i3 = middlewares.length - 1; i3 >= 0; i3--) {
94
+ const m2 = middlewares[i3];
95
+ if (m2 && typeof m2 === "object" && typeof m2.onResponse === "function") {
96
+ const result = await m2.onResponse({
97
+ request,
98
+ response,
99
+ schemaPath,
100
+ params,
101
+ options,
102
+ id
103
+ });
104
+ if (result) {
105
+ if (!(result instanceof Response)) {
106
+ throw new Error("onResponse: must return new Response() when modifying the response");
107
+ }
108
+ response = result;
109
+ }
110
+ }
111
+ }
112
+ }
113
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
114
+ return response.ok ? { data: {}, response } : { error: {}, response };
115
+ }
116
+ if (response.ok) {
117
+ if (parseAs === "stream") {
118
+ return { data: response.body, response };
119
+ }
120
+ return { data: await response[parseAs](), response };
121
+ }
122
+ let error = await response.text();
123
+ try {
124
+ error = JSON.parse(error);
125
+ } catch {
126
+ }
127
+ return { error, response };
128
+ }
129
+ return {
130
+ /** Call a GET endpoint */
131
+ GET(url, init) {
132
+ return coreFetch(url, { ...init, method: "GET" });
133
+ },
134
+ /** Call a PUT endpoint */
135
+ PUT(url, init) {
136
+ return coreFetch(url, { ...init, method: "PUT" });
137
+ },
138
+ /** Call a POST endpoint */
139
+ POST(url, init) {
140
+ return coreFetch(url, { ...init, method: "POST" });
141
+ },
142
+ /** Call a DELETE endpoint */
143
+ DELETE(url, init) {
144
+ return coreFetch(url, { ...init, method: "DELETE" });
145
+ },
146
+ /** Call a OPTIONS endpoint */
147
+ OPTIONS(url, init) {
148
+ return coreFetch(url, { ...init, method: "OPTIONS" });
149
+ },
150
+ /** Call a HEAD endpoint */
151
+ HEAD(url, init) {
152
+ return coreFetch(url, { ...init, method: "HEAD" });
153
+ },
154
+ /** Call a PATCH endpoint */
155
+ PATCH(url, init) {
156
+ return coreFetch(url, { ...init, method: "PATCH" });
157
+ },
158
+ /** Call a TRACE endpoint */
159
+ TRACE(url, init) {
160
+ return coreFetch(url, { ...init, method: "TRACE" });
161
+ },
162
+ /** Register middleware */
163
+ use(...middleware) {
164
+ for (const m2 of middleware) {
165
+ if (!m2) {
166
+ continue;
167
+ }
168
+ if (typeof m2 !== "object" || !("onRequest" in m2 || "onResponse" in m2)) {
169
+ throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");
170
+ }
171
+ middlewares.push(m2);
172
+ }
173
+ },
174
+ /** Unregister middleware */
175
+ eject(...middleware) {
176
+ for (const m2 of middleware) {
177
+ const i3 = middlewares.indexOf(m2);
178
+ if (i3 !== -1) {
179
+ middlewares.splice(i3, 1);
180
+ }
181
+ }
182
+ }
183
+ };
184
+ }
185
+ function serializePrimitiveParam(name, value, options) {
186
+ if (value === void 0 || value === null) {
187
+ return "";
188
+ }
189
+ if (typeof value === "object") {
190
+ throw new Error(
191
+ "Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
192
+ );
193
+ }
194
+ return `${name}=${options?.allowReserved === true ? value : encodeURIComponent(value)}`;
195
+ }
196
+ function serializeObjectParam(name, value, options) {
197
+ if (!value || typeof value !== "object") {
198
+ return "";
199
+ }
200
+ const values = [];
201
+ const joiner = {
202
+ simple: ",",
203
+ label: ".",
204
+ matrix: ";"
205
+ }[options.style] || "&";
206
+ if (options.style !== "deepObject" && options.explode === false) {
207
+ for (const k2 in value) {
208
+ values.push(k2, options.allowReserved === true ? value[k2] : encodeURIComponent(value[k2]));
209
+ }
210
+ const final2 = values.join(",");
211
+ switch (options.style) {
212
+ case "form": {
213
+ return `${name}=${final2}`;
214
+ }
215
+ case "label": {
216
+ return `.${final2}`;
217
+ }
218
+ case "matrix": {
219
+ return `;${name}=${final2}`;
220
+ }
221
+ default: {
222
+ return final2;
223
+ }
224
+ }
225
+ }
226
+ for (const k2 in value) {
227
+ const finalName = options.style === "deepObject" ? `${name}[${k2}]` : k2;
228
+ values.push(serializePrimitiveParam(finalName, value[k2], options));
229
+ }
230
+ const final = values.join(joiner);
231
+ return options.style === "label" || options.style === "matrix" ? `${joiner}${final}` : final;
232
+ }
233
+ function serializeArrayParam(name, value, options) {
234
+ if (!Array.isArray(value)) {
235
+ return "";
236
+ }
237
+ if (options.explode === false) {
238
+ const joiner2 = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[options.style] || ",";
239
+ const final = (options.allowReserved === true ? value : value.map((v2) => encodeURIComponent(v2))).join(joiner2);
240
+ switch (options.style) {
241
+ case "simple": {
242
+ return final;
243
+ }
244
+ case "label": {
245
+ return `.${final}`;
246
+ }
247
+ case "matrix": {
248
+ return `;${name}=${final}`;
249
+ }
250
+ default: {
251
+ return `${name}=${final}`;
252
+ }
253
+ }
254
+ }
255
+ const joiner = { simple: ",", label: ".", matrix: ";" }[options.style] || "&";
256
+ const values = [];
257
+ for (const v2 of value) {
258
+ if (options.style === "simple" || options.style === "label") {
259
+ values.push(options.allowReserved === true ? v2 : encodeURIComponent(v2));
260
+ } else {
261
+ values.push(serializePrimitiveParam(name, v2, options));
262
+ }
263
+ }
264
+ return options.style === "label" || options.style === "matrix" ? `${joiner}${values.join(joiner)}` : values.join(joiner);
265
+ }
266
+ function createQuerySerializer(options) {
267
+ return function querySerializer(queryParams) {
268
+ const search = [];
269
+ if (queryParams && typeof queryParams === "object") {
270
+ for (const name in queryParams) {
271
+ const value = queryParams[name];
272
+ if (value === void 0 || value === null) {
273
+ continue;
274
+ }
275
+ if (Array.isArray(value)) {
276
+ if (value.length === 0) {
277
+ continue;
278
+ }
279
+ search.push(
280
+ serializeArrayParam(name, value, {
281
+ style: "form",
282
+ explode: true,
283
+ ...options?.array,
284
+ allowReserved: options?.allowReserved || false
285
+ })
286
+ );
287
+ continue;
288
+ }
289
+ if (typeof value === "object") {
290
+ search.push(
291
+ serializeObjectParam(name, value, {
292
+ style: "deepObject",
293
+ explode: true,
294
+ ...options?.object,
295
+ allowReserved: options?.allowReserved || false
296
+ })
297
+ );
298
+ continue;
299
+ }
300
+ search.push(serializePrimitiveParam(name, value, options));
301
+ }
302
+ }
303
+ return search.join("&");
304
+ };
305
+ }
306
+ function defaultPathSerializer(pathname, pathParams) {
307
+ let nextURL = pathname;
308
+ for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
309
+ let name = match.substring(1, match.length - 1);
310
+ let explode = false;
311
+ let style = "simple";
312
+ if (name.endsWith("*")) {
313
+ explode = true;
314
+ name = name.substring(0, name.length - 1);
315
+ }
316
+ if (name.startsWith(".")) {
317
+ style = "label";
318
+ name = name.substring(1);
319
+ } else if (name.startsWith(";")) {
320
+ style = "matrix";
321
+ name = name.substring(1);
322
+ }
323
+ if (!pathParams || pathParams[name] === void 0 || pathParams[name] === null) {
324
+ continue;
325
+ }
326
+ const value = pathParams[name];
327
+ if (Array.isArray(value)) {
328
+ nextURL = nextURL.replace(match, serializeArrayParam(name, value, { style, explode }));
329
+ continue;
330
+ }
331
+ if (typeof value === "object") {
332
+ nextURL = nextURL.replace(match, serializeObjectParam(name, value, { style, explode }));
333
+ continue;
334
+ }
335
+ if (style === "matrix") {
336
+ nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
337
+ continue;
338
+ }
339
+ nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
340
+ }
341
+ return nextURL;
342
+ }
343
+ function defaultBodySerializer(body) {
344
+ if (body instanceof FormData) {
345
+ return body;
346
+ }
347
+ return JSON.stringify(body);
348
+ }
349
+ function createFinalURL(pathname, options) {
350
+ let finalURL = `${options.baseUrl}${pathname}`;
351
+ if (options.params?.path) {
352
+ finalURL = defaultPathSerializer(finalURL, options.params.path);
353
+ }
354
+ let search = options.querySerializer(options.params.query ?? {});
355
+ if (search.startsWith("?")) {
356
+ search = search.substring(1);
357
+ }
358
+ if (search) {
359
+ finalURL += `?${search}`;
360
+ }
361
+ return finalURL;
362
+ }
363
+ function mergeHeaders(...allHeaders) {
364
+ const finalHeaders = new Headers();
365
+ for (const h2 of allHeaders) {
366
+ if (!h2 || typeof h2 !== "object") {
367
+ continue;
368
+ }
369
+ const iterator = h2 instanceof Headers ? h2.entries() : Object.entries(h2);
370
+ for (const [k2, v2] of iterator) {
371
+ if (v2 === null) {
372
+ finalHeaders.delete(k2);
373
+ } else if (Array.isArray(v2)) {
374
+ for (const v22 of v2) {
375
+ finalHeaders.append(k2, v22);
376
+ }
377
+ } else if (v2 !== void 0) {
378
+ finalHeaders.set(k2, v2);
379
+ }
380
+ }
381
+ }
382
+ return finalHeaders;
383
+ }
384
+ function removeTrailingSlash(url) {
385
+ if (url.endsWith("/")) {
386
+ return url.substring(0, url.length - 1);
387
+ }
388
+ return url;
389
+ }
390
+ class ObiClient {
391
+ constructor(config) {
392
+ this.client = createClient({
393
+ baseUrl: config.baseUrl,
394
+ headers: config.headers,
395
+ fetch: config.fetch
396
+ });
397
+ }
398
+ /**
399
+ * Set authorization header for authenticated requests
400
+ */
401
+ setAuthToken(token) {
402
+ this.client.use({
403
+ onRequest({ request }) {
404
+ request.headers.set("Authorization", `Bearer ${token}`);
405
+ return request;
406
+ }
407
+ });
408
+ }
409
+ /**
410
+ * Set API token for tool calls and notifications
411
+ */
412
+ setApiToken(token) {
413
+ this.client.use({
414
+ onRequest({ request }) {
415
+ request.headers.set("Authorization", `Token ${token}`);
416
+ return request;
417
+ }
418
+ });
419
+ }
420
+ // Auth endpoints
421
+ async getAuthUrl(type) {
422
+ return await this.client.GET("/auth/{type}", {
423
+ params: { path: { type } }
424
+ });
425
+ }
426
+ async getConnectUrl(type) {
427
+ return await this.client.GET("/connect/{type}", {
428
+ params: { path: { type } }
429
+ });
430
+ }
431
+ async logout() {
432
+ return await this.client.POST("/logout");
433
+ }
434
+ async getCurrentUser() {
435
+ return await this.client.GET("/me");
436
+ }
437
+ // Files
438
+ async createPresignedUploadUrl(data) {
439
+ return await this.client.POST("/files", {
440
+ body: data
441
+ });
442
+ }
443
+ // Knowledge blocks
444
+ async createKnowledgeBlock(data) {
445
+ return await this.client.POST("/knowledge", {
446
+ body: data
447
+ });
448
+ }
449
+ // Onboardees
450
+ async listOnboardees() {
451
+ return await this.client.GET("/onboardees");
452
+ }
453
+ async getOnboardeeWhitelistedDomains(id) {
454
+ return await this.client.GET("/onboardees/{id}/whitelisted-domains", {
455
+ params: { path: { id } }
456
+ });
457
+ }
458
+ // Plans
459
+ async listPlans() {
460
+ return await this.client.GET("/plans");
461
+ }
462
+ async createPlan(data) {
463
+ return await this.client.POST("/plans", {
464
+ body: data
465
+ });
466
+ }
467
+ async getPlan(id) {
468
+ return await this.client.GET("/plans/{id}", {
469
+ params: { path: { id } }
470
+ });
471
+ }
472
+ async replacePlan(id, data) {
473
+ return await this.client.PUT("/plans/{id}", {
474
+ params: { path: { id } },
475
+ body: data
476
+ });
477
+ }
478
+ async updatePlan(id, data) {
479
+ return await this.client.PATCH("/plans/{id}", {
480
+ params: { path: { id } },
481
+ body: data
482
+ });
483
+ }
484
+ // Sessions
485
+ async listSessions(token) {
486
+ return await this.client.GET("/sessions", {
487
+ params: { query: token ? { token } : {} }
488
+ });
489
+ }
490
+ async createSession(data) {
491
+ return await this.client.POST("/sessions", {
492
+ body: data
493
+ });
494
+ }
495
+ async getSession(id) {
496
+ return await this.client.GET("/sessions/{id}", {
497
+ params: { path: { id } }
498
+ });
499
+ }
500
+ async getSessionRecording(id) {
501
+ return await this.client.GET("/sessions/{id}/recording", {
502
+ params: { path: { id } }
503
+ });
504
+ }
505
+ async getSessionProductUrl(id) {
506
+ return await this.client.GET("/sessions/{id}/product-url", {
507
+ params: { path: { id } }
508
+ });
509
+ }
510
+ async getJoinToken(token, { skipIntro } = {}) {
511
+ return await this.client.GET("/join-token", {
512
+ params: {
513
+ query: {
514
+ token,
515
+ ...skipIntro && { skip_intro: "true" }
516
+ }
517
+ }
518
+ });
519
+ }
520
+ /**
521
+ * Get the underlying openapi-fetch client for advanced usage
522
+ */
523
+ getClient() {
524
+ return this.client;
525
+ }
526
+ }
2
527
  const DEFAULT_API_BASE_URL = "https://obi.getcor.io/api";
3
528
  class ObiSession {
4
529
  constructor({ sessionId, apiBaseUrl }) {
@@ -348,6 +873,8 @@ class ObiSession {
348
873
  }
349
874
  }
350
875
  }
876
+ const SESSION_URL_PARAM = "49206C6F7665204F6269_session";
877
+ const API_KEY_URL_PARAM = "49206C6F7665204F6269_client";
351
878
  var extendStatics = function(d2, b2) {
352
879
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
353
880
  d3.__proto__ = b3;
@@ -9515,15 +10042,15 @@ const STORAGE_KEYS = {
9515
10042
  SESSION_DATA: "session_data"
9516
10043
  };
9517
10044
  const storage = new StorageManager("io.obi.widget");
9518
- var __defProp$6 = Object.defineProperty;
9519
- var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
9520
- var __decorateClass$6 = (decorators, target, key, kind) => {
9521
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
10045
+ var __defProp$7 = Object.defineProperty;
10046
+ var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
10047
+ var __decorateClass$7 = (decorators, target, key, kind) => {
10048
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
9522
10049
  for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
9523
10050
  if (decorator = decorators[i3])
9524
10051
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9525
10052
  if (kind && result)
9526
- __defProp$6(target, key, result);
10053
+ __defProp$7(target, key, result);
9527
10054
  return result;
9528
10055
  };
9529
10056
  class NavIcon extends i$1 {
@@ -9616,16 +10143,16 @@ NavIcon.styles = i$4`
9616
10143
  height: 18px;
9617
10144
  }
9618
10145
  `;
9619
- __decorateClass$6([
10146
+ __decorateClass$7([
9620
10147
  n$2({ type: String })
9621
10148
  ], NavIcon.prototype, "id", 2);
9622
- __decorateClass$6([
10149
+ __decorateClass$7([
9623
10150
  n$2({ type: Boolean })
9624
10151
  ], NavIcon.prototype, "isActive", 2);
9625
- __decorateClass$6([
10152
+ __decorateClass$7([
9626
10153
  n$2({ type: Boolean })
9627
10154
  ], NavIcon.prototype, "isSpecial", 2);
9628
- __decorateClass$6([
10155
+ __decorateClass$7([
9629
10156
  n$2({ type: Function })
9630
10157
  ], NavIcon.prototype, "onClick", 2);
9631
10158
  if (!customElements.get("obi-nav-icon")) {
@@ -9675,15 +10202,15 @@ const obiIcon = x`
9675
10202
  alt="Obi Icon"
9676
10203
  />
9677
10204
  `;
9678
- var __defProp$5 = Object.defineProperty;
9679
- var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
9680
- var __decorateClass$5 = (decorators, target, key, kind) => {
9681
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
10205
+ var __defProp$6 = Object.defineProperty;
10206
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
10207
+ var __decorateClass$6 = (decorators, target, key, kind) => {
10208
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
9682
10209
  for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
9683
10210
  if (decorator = decorators[i3])
9684
10211
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9685
10212
  if (kind && result)
9686
- __defProp$5(target, key, result);
10213
+ __defProp$6(target, key, result);
9687
10214
  return result;
9688
10215
  };
9689
10216
  class NavigationBar extends i$1 {
@@ -9757,37 +10284,37 @@ NavigationBar.styles = i$4`
9757
10284
  flex-direction: column;
9758
10285
  }
9759
10286
  `;
9760
- __decorateClass$5([
10287
+ __decorateClass$6([
9761
10288
  n$2({ type: Boolean })
9762
10289
  ], NavigationBar.prototype, "isActive", 2);
9763
- __decorateClass$5([
10290
+ __decorateClass$6([
9764
10291
  n$2({ type: Boolean })
9765
10292
  ], NavigationBar.prototype, "isScreenActive", 2);
9766
- __decorateClass$5([
10293
+ __decorateClass$6([
9767
10294
  n$2({ type: Object })
9768
10295
  ], NavigationBar.prototype, "position", 2);
9769
- __decorateClass$5([
10296
+ __decorateClass$6([
9770
10297
  n$2({ type: String })
9771
10298
  ], NavigationBar.prototype, "currentState", 2);
9772
- __decorateClass$5([
10299
+ __decorateClass$6([
9773
10300
  n$2({ type: String })
9774
10301
  ], NavigationBar.prototype, "direction", 2);
9775
- __decorateClass$5([
10302
+ __decorateClass$6([
9776
10303
  n$2({ type: Function })
9777
10304
  ], NavigationBar.prototype, "onItemSelect", 2);
9778
10305
  if (!customElements.get("obi-navigation-bar")) {
9779
10306
  customElements.define("obi-navigation-bar", NavigationBar);
9780
10307
  }
9781
10308
  const navigationBar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, NavigationBar }, Symbol.toStringTag, { value: "Module" }));
9782
- var __defProp$4 = Object.defineProperty;
9783
- var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
9784
- var __decorateClass$4 = (decorators, target, key, kind) => {
9785
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
10309
+ var __defProp$5 = Object.defineProperty;
10310
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
10311
+ var __decorateClass$5 = (decorators, target, key, kind) => {
10312
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
9786
10313
  for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
9787
10314
  if (decorator = decorators[i3])
9788
10315
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9789
10316
  if (kind && result)
9790
- __defProp$4(target, key, result);
10317
+ __defProp$5(target, key, result);
9791
10318
  return result;
9792
10319
  };
9793
10320
  class Course extends i$1 {
@@ -9799,12 +10326,9 @@ class Course extends i$1 {
9799
10326
  this.imageSrc = "";
9800
10327
  }
9801
10328
  handleClick() {
9802
- if (this.onSelect) {
9803
- this.onSelect(this.id);
9804
- }
9805
10329
  this.dispatchEvent(
9806
10330
  new CustomEvent("course-select", {
9807
- detail: { id: this.id },
10331
+ detail: { id: this.id, name: this.name, description: this.description },
9808
10332
  bubbles: true,
9809
10333
  composed: true
9810
10334
  })
@@ -9866,21 +10390,18 @@ Course.styles = i$4`
9866
10390
  margin: 0;
9867
10391
  }
9868
10392
  `;
9869
- __decorateClass$4([
10393
+ __decorateClass$5([
9870
10394
  n$2({ type: String })
9871
10395
  ], Course.prototype, "id", 2);
9872
- __decorateClass$4([
10396
+ __decorateClass$5([
9873
10397
  n$2({ type: String })
9874
10398
  ], Course.prototype, "name", 2);
9875
- __decorateClass$4([
10399
+ __decorateClass$5([
9876
10400
  n$2({ type: String })
9877
10401
  ], Course.prototype, "description", 2);
9878
- __decorateClass$4([
10402
+ __decorateClass$5([
9879
10403
  n$2({ type: String })
9880
10404
  ], Course.prototype, "imageSrc", 2);
9881
- __decorateClass$4([
9882
- n$2({ type: Function })
9883
- ], Course.prototype, "onSelect", 2);
9884
10405
  class CourseList extends i$1 {
9885
10406
  constructor() {
9886
10407
  super(...arguments);
@@ -9888,11 +10409,6 @@ class CourseList extends i$1 {
9888
10409
  this.loading = false;
9889
10410
  this.error = "";
9890
10411
  }
9891
- handleCourseSelect(e2) {
9892
- if (this.onCourseSelect) {
9893
- this.onCourseSelect(e2.detail.id);
9894
- }
9895
- }
9896
10412
  render() {
9897
10413
  if (this.loading) {
9898
10414
  return x`<div class="loading">Loading...</div>`;
@@ -9913,7 +10429,6 @@ class CourseList extends i$1 {
9913
10429
  name=${course.name}
9914
10430
  description=${course.description || ""}
9915
10431
  imageSrc=${course.imageSrc}
9916
- @course-select=${this.handleCourseSelect}
9917
10432
  ></obi-course>
9918
10433
  `
9919
10434
  )}
@@ -9957,18 +10472,15 @@ CourseList.styles = i$4`
9957
10472
  color: #ef4444;
9958
10473
  }
9959
10474
  `;
9960
- __decorateClass$4([
10475
+ __decorateClass$5([
9961
10476
  n$2({ type: Array })
9962
10477
  ], CourseList.prototype, "courses", 2);
9963
- __decorateClass$4([
10478
+ __decorateClass$5([
9964
10479
  n$2({ type: Boolean })
9965
10480
  ], CourseList.prototype, "loading", 2);
9966
- __decorateClass$4([
10481
+ __decorateClass$5([
9967
10482
  n$2({ type: String })
9968
10483
  ], CourseList.prototype, "error", 2);
9969
- __decorateClass$4([
9970
- n$2({ type: Function })
9971
- ], CourseList.prototype, "onCourseSelect", 2);
9972
10484
  if (!customElements.get("obi-course")) {
9973
10485
  customElements.define("obi-course", Course);
9974
10486
  }
@@ -9976,15 +10488,15 @@ if (!customElements.get("obi-course-list")) {
9976
10488
  customElements.define("obi-course-list", CourseList);
9977
10489
  }
9978
10490
  const courses = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, Course, CourseList }, Symbol.toStringTag, { value: "Module" }));
9979
- var __defProp$3 = Object.defineProperty;
9980
- var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
9981
- var __decorateClass$3 = (decorators, target, key, kind) => {
9982
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
10491
+ var __defProp$4 = Object.defineProperty;
10492
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
10493
+ var __decorateClass$4 = (decorators, target, key, kind) => {
10494
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
9983
10495
  for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
9984
10496
  if (decorator = decorators[i3])
9985
10497
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9986
10498
  if (kind && result)
9987
- __defProp$3(target, key, result);
10499
+ __defProp$4(target, key, result);
9988
10500
  return result;
9989
10501
  };
9990
10502
  class CourseModal extends i$1 {
@@ -9996,11 +10508,6 @@ class CourseModal extends i$1 {
9996
10508
  this.apiKey = "";
9997
10509
  this.apiBaseUrl = "";
9998
10510
  }
9999
- handleCourseSelect(e2) {
10000
- if (this.onCourseSelect) {
10001
- this.onCourseSelect(e2.detail.id);
10002
- }
10003
- }
10004
10511
  handleClose() {
10005
10512
  if (this.onClose) {
10006
10513
  this.onClose();
@@ -10055,7 +10562,6 @@ class CourseModal extends i$1 {
10055
10562
  .courses=${this.courses}
10056
10563
  .loading=${this.loading}
10057
10564
  .error=${this.error}
10058
- @course-select=${this.handleCourseSelect}
10059
10565
  ></obi-course-list>
10060
10566
  </div>
10061
10567
  `;
@@ -10145,25 +10651,22 @@ CourseModal.styles = i$4`
10145
10651
  color: #6b7280;
10146
10652
  }
10147
10653
  `;
10148
- __decorateClass$3([
10654
+ __decorateClass$4([
10149
10655
  n$2({ type: Array })
10150
10656
  ], CourseModal.prototype, "courses", 2);
10151
- __decorateClass$3([
10657
+ __decorateClass$4([
10152
10658
  n$2({ type: Boolean })
10153
10659
  ], CourseModal.prototype, "loading", 2);
10154
- __decorateClass$3([
10660
+ __decorateClass$4([
10155
10661
  n$2({ type: String })
10156
10662
  ], CourseModal.prototype, "error", 2);
10157
- __decorateClass$3([
10663
+ __decorateClass$4([
10158
10664
  n$2({ type: String })
10159
10665
  ], CourseModal.prototype, "apiKey", 2);
10160
- __decorateClass$3([
10161
- n$2({ type: Function })
10162
- ], CourseModal.prototype, "onCourseSelect", 2);
10163
- __decorateClass$3([
10666
+ __decorateClass$4([
10164
10667
  n$2({ type: Function })
10165
10668
  ], CourseModal.prototype, "onClose", 2);
10166
- __decorateClass$3([
10669
+ __decorateClass$4([
10167
10670
  r$1()
10168
10671
  ], CourseModal.prototype, "apiBaseUrl", 2);
10169
10672
  if (!customElements.get("obi-course-modal")) {
@@ -10282,15 +10785,15 @@ const o = /* @__PURE__ */ new WeakMap(), n2 = e$1(class extends f {
10282
10785
  this.rt(this.ct);
10283
10786
  }
10284
10787
  });
10285
- var __defProp$2 = Object.defineProperty;
10286
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
10287
- var __decorateClass$2 = (decorators, target, key, kind) => {
10288
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
10788
+ var __defProp$3 = Object.defineProperty;
10789
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
10790
+ var __decorateClass$3 = (decorators, target, key, kind) => {
10791
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
10289
10792
  for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
10290
10793
  if (decorator = decorators[i3])
10291
10794
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10292
10795
  if (kind && result)
10293
- __defProp$2(target, key, result);
10796
+ __defProp$3(target, key, result);
10294
10797
  return result;
10295
10798
  };
10296
10799
  class AudioEqualizer extends i$1 {
@@ -10300,9 +10803,11 @@ class AudioEqualizer extends i$1 {
10300
10803
  this.canvasRef = e();
10301
10804
  this.barCount = 8;
10302
10805
  this.animationFrame = null;
10806
+ this.primaryColor = "#9500ff";
10303
10807
  }
10304
10808
  connectedCallback() {
10305
10809
  super.connectedCallback();
10810
+ this.primaryColor = getComputedStyle(this).getPropertyValue("--obi-primary").trim() || "#9500ff";
10306
10811
  this.startAnimation();
10307
10812
  }
10308
10813
  disconnectedCallback() {
@@ -10394,7 +10899,7 @@ class AudioEqualizer extends i$1 {
10394
10899
  const spectrumValue = processedSpectrum.length > 0 ? processedSpectrum[i3] !== void 0 ? processedSpectrum[i3] : currentVolume : currentVolume;
10395
10900
  if (this.volume.speaker === "USER") {
10396
10901
  const opacity2 = Math.floor((spectrumValue * 0.5 + 0.5) * 255).toString(16).padStart(2, "0");
10397
- ctx.fillStyle = `var(--obi-primary)${opacity2}`;
10902
+ ctx.fillStyle = `${this.primaryColor}${opacity2}`;
10398
10903
  } else {
10399
10904
  const opacity2 = Math.floor((spectrumValue * 0.5 + 0.5) * 255).toString(16).padStart(2, "0");
10400
10905
  ctx.fillStyle = `#FFFFFF${opacity2}`;
@@ -10459,25 +10964,25 @@ AudioEqualizer.styles = i$4`
10459
10964
  height: 100%;
10460
10965
  }
10461
10966
  `;
10462
- __decorateClass$2([
10967
+ __decorateClass$3([
10463
10968
  n$2({ type: Object })
10464
10969
  ], AudioEqualizer.prototype, "volume", 2);
10465
- __decorateClass$2([
10970
+ __decorateClass$3([
10466
10971
  r$1()
10467
10972
  ], AudioEqualizer.prototype, "canvasRef", 2);
10468
10973
  if (!customElements.get("obi-audio-equalizer")) {
10469
10974
  customElements.define("obi-audio-equalizer", AudioEqualizer);
10470
10975
  }
10471
10976
  const audioEqualizer = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, AudioEqualizer }, Symbol.toStringTag, { value: "Module" }));
10472
- var __defProp$1 = Object.defineProperty;
10473
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
10474
- var __decorateClass$1 = (decorators, target, key, kind) => {
10475
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
10977
+ var __defProp$2 = Object.defineProperty;
10978
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
10979
+ var __decorateClass$2 = (decorators, target, key, kind) => {
10980
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
10476
10981
  for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
10477
10982
  if (decorator = decorators[i3])
10478
10983
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10479
10984
  if (kind && result)
10480
- __defProp$1(target, key, result);
10985
+ __defProp$2(target, key, result);
10481
10986
  return result;
10482
10987
  };
10483
10988
  class DotLoader extends i$1 {
@@ -10578,7 +11083,7 @@ DotLoader.styles = i$4`
10578
11083
  opacity: 1;
10579
11084
  }
10580
11085
  `;
10581
- __decorateClass$1([
11086
+ __decorateClass$2([
10582
11087
  r$1()
10583
11088
  ], DotLoader.prototype, "activeDots", 2);
10584
11089
  if (!customElements.get("obi-dot-loader")) {
@@ -10613,6 +11118,205 @@ if (!customElements.get("obi-searching-loader")) {
10613
11118
  customElements.define("obi-searching-loader", SearchingLoader);
10614
11119
  }
10615
11120
  const searchingLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, SearchingLoader }, Symbol.toStringTag, { value: "Module" }));
11121
+ var __defProp$1 = Object.defineProperty;
11122
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
11123
+ var __decorateClass$1 = (decorators, target, key, kind) => {
11124
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
11125
+ for (var i3 = decorators.length - 1, decorator; i3 >= 0; i3--)
11126
+ if (decorator = decorators[i3])
11127
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11128
+ if (kind && result)
11129
+ __defProp$1(target, key, result);
11130
+ return result;
11131
+ };
11132
+ class SessionStartModal extends i$1 {
11133
+ handleStart() {
11134
+ if (this.onStart && this.session) {
11135
+ this.onStart(this.session.id);
11136
+ }
11137
+ }
11138
+ handleClose() {
11139
+ if (this.onClose) {
11140
+ this.onClose();
11141
+ }
11142
+ }
11143
+ handleBackdropClick(e2) {
11144
+ if (e2.target === e2.currentTarget) {
11145
+ this.handleClose();
11146
+ }
11147
+ }
11148
+ render() {
11149
+ return x`
11150
+ <div class="backdrop" @click=${this.handleBackdropClick}></div>
11151
+ <div class="container">
11152
+ <button class="close-button" @click=${this.handleClose}>×</button>
11153
+
11154
+ <div class="header">
11155
+ <div class="logo">${obiIcon}</div>
11156
+ <h1>${this.session.name}</h1>
11157
+ <p class="subtitle">${this.session.description}</p>
11158
+ </div>
11159
+
11160
+ <button class="button button-primary" @click=${this.handleStart}>Continue →</button>
11161
+ </div>
11162
+ `;
11163
+ }
11164
+ }
11165
+ SessionStartModal.styles = i$4`
11166
+ :host {
11167
+ display: block;
11168
+ font-family: "Inter", sans-serif;
11169
+ }
11170
+
11171
+ .backdrop {
11172
+ position: fixed;
11173
+ top: 0;
11174
+ right: 0;
11175
+ bottom: 0;
11176
+ left: 0;
11177
+ background-color: rgba(0, 0, 0, 0.5);
11178
+ z-index: 40;
11179
+ }
11180
+
11181
+ .container {
11182
+ position: fixed;
11183
+ top: 50%;
11184
+ left: 50%;
11185
+ transform: translate(-50%, -50%);
11186
+ z-index: 50;
11187
+
11188
+ /* Layout from user specifications */
11189
+ display: flex;
11190
+ width: 640px;
11191
+ height: 380px;
11192
+ padding: 48px 48px 32px 48px;
11193
+ flex-direction: column;
11194
+ justify-content: space-between;
11195
+ align-items: center;
11196
+ flex-shrink: 0;
11197
+
11198
+ /* Style from user specifications */
11199
+ border-radius: 12px;
11200
+ background: #fafafa;
11201
+ box-shadow:
11202
+ 0px 10px 15px -3px rgba(0, 0, 0, 0.1),
11203
+ 0px 4px 6px -2px rgba(0, 0, 0, 0.05);
11204
+ }
11205
+
11206
+ .header {
11207
+ display: flex;
11208
+ flex-direction: column;
11209
+ align-items: center;
11210
+ text-align: center;
11211
+ gap: 16px;
11212
+ }
11213
+
11214
+ .logo {
11215
+ display: flex;
11216
+ width: 96px;
11217
+ height: 96px;
11218
+ padding: 8px;
11219
+ justify-content: center;
11220
+ align-items: center;
11221
+ gap: 8px;
11222
+ aspect-ratio: 1/1;
11223
+ border-radius: var(--border-radius-lg, 8px);
11224
+ background: var(--tailwind-colors-violet-600, #7c3aed);
11225
+ box-shadow:
11226
+ 0px 0px 8px 0px rgba(168, 85, 247, 0.12),
11227
+ 0px 0px 8px 0px rgba(192, 132, 252, 0.24),
11228
+ 0px 0px 4px 0px rgba(192, 132, 252, 0.24),
11229
+ 0px 0px 4px 0px rgba(192, 132, 252, 0.24),
11230
+ 0px 0px 2px 0px rgba(192, 132, 252, 0.12),
11231
+ 0px 0px 1px 0px rgba(168, 85, 247, 0.24);
11232
+ }
11233
+
11234
+ .logo img {
11235
+ width: 48px;
11236
+ height: 48px;
11237
+ color: white;
11238
+ fill: #fff;
11239
+ }
11240
+
11241
+ h1 {
11242
+ font-family: "Syne", sans-serif;
11243
+ font-size: 32px;
11244
+ font-weight: 700;
11245
+ margin: 32px 0 0 0;
11246
+ color: #111827;
11247
+ }
11248
+
11249
+ .subtitle {
11250
+ font-size: 16px;
11251
+ color: #6b7280;
11252
+ margin: 16px 0 0 0;
11253
+ line-height: 1.5;
11254
+ }
11255
+
11256
+ .button {
11257
+ padding: 12px 24px;
11258
+ border-radius: 8px;
11259
+ border: none;
11260
+ font-size: 16px;
11261
+ font-weight: 500;
11262
+ cursor: pointer;
11263
+ transition: all 0.2s ease;
11264
+ display: flex;
11265
+ align-items: center;
11266
+ justify-content: center;
11267
+ gap: 8px;
11268
+ }
11269
+
11270
+ .button-primary {
11271
+ display: flex;
11272
+ width: 100%;
11273
+ height: var(--height-h-11, 44px);
11274
+ padding: var(--spacing-2, 8px) var(--spacing-4, 16px);
11275
+ justify-content: center;
11276
+ align-items: center;
11277
+ gap: var(--spacing-2, 8px);
11278
+ flex-shrink: 0;
11279
+ align-self: stretch;
11280
+ border-radius: var(--border-radius-default, 6px);
11281
+ background: var(--base-primary, #18181b);
11282
+ color: white;
11283
+ }
11284
+
11285
+ .button-primary:hover {
11286
+ background: color-mix(in srgb, var(--base-primary, #18181b) 90%, white);
11287
+ }
11288
+
11289
+ .close-button {
11290
+ position: absolute;
11291
+ top: 16px;
11292
+ right: 16px;
11293
+ background: none;
11294
+ border: none;
11295
+ cursor: pointer;
11296
+ font-size: 24px;
11297
+ color: #6b7280;
11298
+ padding: 4px;
11299
+ border-radius: 4px;
11300
+ transition: all 0.2s ease;
11301
+ }
11302
+
11303
+ .close-button:hover {
11304
+ color: #374151;
11305
+ background: #f3f4f6;
11306
+ }
11307
+ `;
11308
+ __decorateClass$1([
11309
+ n$2({ type: Object })
11310
+ ], SessionStartModal.prototype, "session", 2);
11311
+ __decorateClass$1([
11312
+ n$2({ type: Function })
11313
+ ], SessionStartModal.prototype, "onStart", 2);
11314
+ __decorateClass$1([
11315
+ n$2({ type: Function })
11316
+ ], SessionStartModal.prototype, "onClose", 2);
11317
+ if (!customElements.get("obi-session-start-modal")) {
11318
+ customElements.define("obi-session-start-modal", SessionStartModal);
11319
+ }
10616
11320
  var __defProp = Object.defineProperty;
10617
11321
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10618
11322
  var __decorateClass = (decorators, target, key, kind) => {
@@ -10624,7 +11328,6 @@ var __decorateClass = (decorators, target, key, kind) => {
10624
11328
  __defProp(target, key, result);
10625
11329
  return result;
10626
11330
  };
10627
- const SESSION_URL_PARAM = "49206C6F7665204F6269_session";
10628
11331
  class ObiWidget extends i$1 {
10629
11332
  constructor() {
10630
11333
  super();
@@ -10635,6 +11338,8 @@ class ObiWidget extends i$1 {
10635
11338
  this.state = SDKState.READY;
10636
11339
  this.storedActiveState = void 0;
10637
11340
  this.showCourseModal = false;
11341
+ this.showSessionStartModal = false;
11342
+ this.selectedCourse = null;
10638
11343
  this.isHovering = false;
10639
11344
  this.navVisible = false;
10640
11345
  this.activeSession = null;
@@ -10647,7 +11352,41 @@ class ObiWidget extends i$1 {
10647
11352
  this.roomToken = null;
10648
11353
  this.roomUrl = null;
10649
11354
  this.boundSaveSessionData = null;
11355
+ this.obiClient = null;
10650
11356
  this.closeNavTimeoutRef = null;
11357
+ this.handleCourseSelectEvent = (event) => {
11358
+ const customEvent = event;
11359
+ this.selectedCourse = customEvent.detail;
11360
+ this.showCourseModal = false;
11361
+ this.showSessionStartModal = true;
11362
+ };
11363
+ this.handleUrlSessionEvent = async (sessionToken) => {
11364
+ try {
11365
+ if (!this.obiClient) {
11366
+ console.error("ObiClient not initialized");
11367
+ return;
11368
+ }
11369
+ const sessionsResponse = await this.obiClient.listSessions(this.apiKey);
11370
+ if (sessionsResponse.data) {
11371
+ const sessions = sessionsResponse.data.sessions;
11372
+ const matchingSession = sessions?.find((session) => session.uuid === sessionToken);
11373
+ if (matchingSession) {
11374
+ const sessionWithPlan = matchingSession;
11375
+ this.selectedCourse = {
11376
+ id: sessionToken,
11377
+ name: sessionWithPlan.onboarding_plan?.product?.name || "Session from URL",
11378
+ description: sessionWithPlan.onboarding_plan?.product?.description || "Continue your session"
11379
+ };
11380
+ this.showSessionStartModal = true;
11381
+ }
11382
+ }
11383
+ } catch (error) {
11384
+ console.error("Failed to fetch session details:", error);
11385
+ }
11386
+ };
11387
+ this.obiClient = new ObiClient({
11388
+ baseUrl: API_BASE_URL
11389
+ });
10651
11390
  const handleUnload = () => {
10652
11391
  if (this.activeSession && this.sessionToken && this.roomToken && this.roomUrl) {
10653
11392
  this.saveSessionData();
@@ -10672,13 +11411,13 @@ class ObiWidget extends i$1 {
10672
11411
  removeSessionFromUrl() {
10673
11412
  const url = new URL(window.location.href);
10674
11413
  url.searchParams.delete(SESSION_URL_PARAM);
11414
+ url.searchParams.delete(API_KEY_URL_PARAM);
10675
11415
  window.history.replaceState({}, "", url.toString());
10676
11416
  }
10677
- async connectObi(sessionToken) {
10678
- if (this.activeSession) {
10679
- console.log("Connection already exists");
10680
- return;
10681
- }
11417
+ /**
11418
+ * Create a new ObiSession instance with common configuration
11419
+ */
11420
+ createSession(sessionToken) {
10682
11421
  try {
10683
11422
  const session = new ObiSession({
10684
11423
  sessionId: sessionToken,
@@ -10686,20 +11425,58 @@ class ObiWidget extends i$1 {
10686
11425
  });
10687
11426
  if (!session) {
10688
11427
  console.error("Failed to create session");
10689
- this.state = SDKState.ERROR;
10690
- this.activeSession = null;
10691
- this.removeSessionFromUrl();
11428
+ return null;
11429
+ }
11430
+ return session;
11431
+ } catch (error) {
11432
+ console.error("Error creating session:", error);
11433
+ return null;
11434
+ }
11435
+ }
11436
+ /**
11437
+ * Set up common event listeners for a session
11438
+ */
11439
+ setupSessionEventListeners(session, onError) {
11440
+ session.on("stateChanged", (newState) => {
11441
+ this.state = newState;
11442
+ if (newState !== SDKState.READY) {
11443
+ this.storedActiveState = newState;
11444
+ }
11445
+ });
11446
+ session.on("volume", ({ speaker, spectrum, volume }) => {
11447
+ this.volume = { speaker, spectrum, volume };
11448
+ });
11449
+ session.on("error", (error) => {
11450
+ console.error("Session error:", error);
11451
+ this.state = SDKState.ERROR;
11452
+ this.activeSession = null;
11453
+ if (onError) {
11454
+ onError();
11455
+ }
11456
+ });
11457
+ }
11458
+ /**
11459
+ * Handle session creation failure
11460
+ */
11461
+ handleSessionCreationFailure(onFailure) {
11462
+ this.state = SDKState.ERROR;
11463
+ this.activeSession = null;
11464
+ if (onFailure) {
11465
+ onFailure();
11466
+ }
11467
+ }
11468
+ async connectObi(sessionToken) {
11469
+ if (this.activeSession) {
11470
+ console.log("Connection already exists");
11471
+ return;
11472
+ }
11473
+ try {
11474
+ const session = this.createSession(sessionToken);
11475
+ if (!session) {
11476
+ this.handleSessionCreationFailure(() => this.removeSessionFromUrl());
10692
11477
  return;
10693
11478
  }
10694
- session.on("stateChanged", (newState) => {
10695
- this.state = newState;
10696
- if (newState !== SDKState.READY) {
10697
- this.storedActiveState = newState;
10698
- }
10699
- });
10700
- session.on("volume", ({ speaker, spectrum, volume }) => {
10701
- this.volume = { speaker, spectrum, volume };
10702
- });
11479
+ this.setupSessionEventListeners(session, () => this.removeSessionFromUrl());
10703
11480
  session.on("screenCaptureRequested", async () => {
10704
11481
  try {
10705
11482
  const canvas = await html2canvas(document.documentElement, {
@@ -10714,12 +11491,6 @@ class ObiWidget extends i$1 {
10714
11491
  this.activeSession.emit("screenCaptureComplete", "error");
10715
11492
  }
10716
11493
  });
10717
- session.on("error", (error) => {
10718
- console.error("Session error:", error);
10719
- this.state = SDKState.ERROR;
10720
- this.activeSession = null;
10721
- this.removeSessionFromUrl();
10722
- });
10723
11494
  const connectionInfo = await session.connect();
10724
11495
  if (connectionInfo) {
10725
11496
  this.sessionToken = sessionToken;
@@ -10730,9 +11501,7 @@ class ObiWidget extends i$1 {
10730
11501
  this.activeSession = session;
10731
11502
  } catch (error) {
10732
11503
  console.error("Failed to start session:", error);
10733
- this.state = SDKState.ERROR;
10734
- this.activeSession = null;
10735
- this.removeSessionFromUrl();
11504
+ this.handleSessionCreationFailure(() => this.removeSessionFromUrl());
10736
11505
  }
10737
11506
  }
10738
11507
  async handleSessionStart(sessionToken) {
@@ -10740,7 +11509,7 @@ class ObiWidget extends i$1 {
10740
11509
  console.log("Connection already in progress or active session exists");
10741
11510
  return;
10742
11511
  }
10743
- this.showCourseModal = false;
11512
+ this.showSessionStartModal = false;
10744
11513
  this.state = SDKState.LOADING;
10745
11514
  await this.connectObi(sessionToken);
10746
11515
  }
@@ -10765,31 +11534,12 @@ class ObiWidget extends i$1 {
10765
11534
  }
10766
11535
  }
10767
11536
  this.state = SDKState.LOADING;
10768
- const session = new ObiSession({
10769
- sessionId: sessionToken,
10770
- apiBaseUrl: API_BASE_URL
10771
- });
11537
+ const session = this.createSession(sessionToken);
10772
11538
  if (!session) {
10773
- console.error("Failed to create session");
10774
- this.state = SDKState.ERROR;
10775
- this.clearSessionStorage();
11539
+ this.handleSessionCreationFailure(() => this.clearSessionStorage());
10776
11540
  return;
10777
11541
  }
10778
- session.on("stateChanged", (newState) => {
10779
- this.state = newState;
10780
- if (newState !== SDKState.READY) {
10781
- this.storedActiveState = newState;
10782
- }
10783
- });
10784
- session.on("volume", ({ speaker, spectrum, volume }) => {
10785
- this.volume = { speaker, spectrum, volume };
10786
- });
10787
- session.on("error", (error) => {
10788
- console.error("Session error:", error);
10789
- this.state = SDKState.ERROR;
10790
- this.activeSession = null;
10791
- this.clearSessionStorage();
10792
- });
11542
+ this.setupSessionEventListeners(session, () => this.clearSessionStorage());
10793
11543
  const reconnected = await session.reconnect(roomUrl, roomToken, obiState);
10794
11544
  if (reconnected) {
10795
11545
  this.activeSession = session;
@@ -10803,8 +11553,7 @@ class ObiWidget extends i$1 {
10803
11553
  }
10804
11554
  } catch (error) {
10805
11555
  console.error("Error reconnecting to session:", error);
10806
- this.state = SDKState.ERROR;
10807
- this.clearSessionStorage();
11556
+ this.handleSessionCreationFailure(() => this.clearSessionStorage());
10808
11557
  }
10809
11558
  }
10810
11559
  /**
@@ -10835,8 +11584,9 @@ class ObiWidget extends i$1 {
10835
11584
  if (!this.activeSession) {
10836
11585
  const urlParams = new URLSearchParams(window.location.search);
10837
11586
  const sessionId = urlParams.get(SESSION_URL_PARAM);
10838
- if (sessionId) {
10839
- this.handleSessionStart(sessionId);
11587
+ this.apiKey = urlParams.get(API_KEY_URL_PARAM) || this.apiKey;
11588
+ if (sessionId && this.apiKey) {
11589
+ await this.handleUrlSessionEvent(sessionId);
10840
11590
  }
10841
11591
  }
10842
11592
  }
@@ -10932,9 +11682,17 @@ class ObiWidget extends i$1 {
10932
11682
  </div>
10933
11683
  ${this.showCourseModal ? x`<obi-course-modal
10934
11684
  .onClose=${() => this.showCourseModal = false}
10935
- .onCourseSelect=${this.handleSessionStart.bind(this)}
11685
+ @course-select=${this.handleCourseSelectEvent}
10936
11686
  .apiKey=${this.apiKey}
10937
11687
  ></obi-course-modal>` : E}
11688
+ ${this.showSessionStartModal && this.selectedCourse ? x`<obi-session-start-modal
11689
+ .session=${this.selectedCourse}
11690
+ .onStart=${this.handleSessionStart.bind(this)}
11691
+ .onClose=${() => {
11692
+ this.showSessionStartModal = false;
11693
+ this.selectedCourse = null;
11694
+ }}
11695
+ ></obi-session-start-modal>` : E}
10938
11696
  `;
10939
11697
  }
10940
11698
  }
@@ -11091,6 +11849,12 @@ __decorateClass([
11091
11849
  __decorateClass([
11092
11850
  r$1()
11093
11851
  ], ObiWidget.prototype, "showCourseModal", 2);
11852
+ __decorateClass([
11853
+ r$1()
11854
+ ], ObiWidget.prototype, "showSessionStartModal", 2);
11855
+ __decorateClass([
11856
+ r$1()
11857
+ ], ObiWidget.prototype, "selectedCourse", 2);
11094
11858
  __decorateClass([
11095
11859
  r$1()
11096
11860
  ], ObiWidget.prototype, "isHovering", 2);
@@ -11130,4 +11894,4 @@ export {
11130
11894
  searchingLoader as s,
11131
11895
  x
11132
11896
  };
11133
- //# sourceMappingURL=obi-widget-dffef845.js.map
11897
+ //# sourceMappingURL=obi-widget-d7e7c6bf.js.map