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,5 +1,530 @@
1
1
  import { css, LitElement, html, svg, nothing } from "lit";
2
2
  const API_BASE_URL = {}.VITE_API_BASE_URL;
3
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
4
+ function randomID() {
5
+ return Math.random().toString(36).slice(2, 11);
6
+ }
7
+ function createClient(clientOptions) {
8
+ let {
9
+ baseUrl = "",
10
+ Request: CustomRequest = globalThis.Request,
11
+ fetch: baseFetch = globalThis.fetch,
12
+ querySerializer: globalQuerySerializer,
13
+ bodySerializer: globalBodySerializer,
14
+ headers: baseHeaders,
15
+ ...baseOptions
16
+ } = { ...clientOptions };
17
+ baseUrl = removeTrailingSlash(baseUrl);
18
+ const middlewares = [];
19
+ async function coreFetch(schemaPath, fetchOptions) {
20
+ const {
21
+ baseUrl: localBaseUrl,
22
+ fetch: fetch2 = baseFetch,
23
+ Request = CustomRequest,
24
+ headers,
25
+ params = {},
26
+ parseAs = "json",
27
+ querySerializer: requestQuerySerializer,
28
+ bodySerializer = globalBodySerializer ?? defaultBodySerializer,
29
+ body,
30
+ ...init
31
+ } = fetchOptions || {};
32
+ if (localBaseUrl) {
33
+ baseUrl = removeTrailingSlash(localBaseUrl);
34
+ }
35
+ let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
36
+ if (requestQuerySerializer) {
37
+ querySerializer = typeof requestQuerySerializer === "function" ? requestQuerySerializer : createQuerySerializer({
38
+ ...typeof globalQuerySerializer === "object" ? globalQuerySerializer : {},
39
+ ...requestQuerySerializer
40
+ });
41
+ }
42
+ const serializedBody = body === void 0 ? void 0 : bodySerializer(body);
43
+ const defaultHeaders = (
44
+ // with no body, we should not to set Content-Type
45
+ serializedBody === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
46
+ serializedBody instanceof FormData ? {} : {
47
+ "Content-Type": "application/json"
48
+ }
49
+ );
50
+ const requestInit = {
51
+ redirect: "follow",
52
+ ...baseOptions,
53
+ ...init,
54
+ body: serializedBody,
55
+ headers: mergeHeaders(defaultHeaders, baseHeaders, headers, params.header)
56
+ };
57
+ let id;
58
+ let options;
59
+ let request = new CustomRequest(createFinalURL(schemaPath, { baseUrl, params, querySerializer }), requestInit);
60
+ for (const key in init) {
61
+ if (!(key in request)) {
62
+ request[key] = init[key];
63
+ }
64
+ }
65
+ if (middlewares.length) {
66
+ id = randomID();
67
+ options = Object.freeze({
68
+ baseUrl,
69
+ fetch: fetch2,
70
+ parseAs,
71
+ querySerializer,
72
+ bodySerializer
73
+ });
74
+ for (const m2 of middlewares) {
75
+ if (m2 && typeof m2 === "object" && typeof m2.onRequest === "function") {
76
+ const result = await m2.onRequest({
77
+ request,
78
+ schemaPath,
79
+ params,
80
+ options,
81
+ id
82
+ });
83
+ if (result) {
84
+ if (!(result instanceof CustomRequest)) {
85
+ throw new Error("onRequest: must return new Request() when modifying the request");
86
+ }
87
+ request = result;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ let response = await fetch2(request);
93
+ if (middlewares.length) {
94
+ for (let i2 = middlewares.length - 1; i2 >= 0; i2--) {
95
+ const m2 = middlewares[i2];
96
+ if (m2 && typeof m2 === "object" && typeof m2.onResponse === "function") {
97
+ const result = await m2.onResponse({
98
+ request,
99
+ response,
100
+ schemaPath,
101
+ params,
102
+ options,
103
+ id
104
+ });
105
+ if (result) {
106
+ if (!(result instanceof Response)) {
107
+ throw new Error("onResponse: must return new Response() when modifying the response");
108
+ }
109
+ response = result;
110
+ }
111
+ }
112
+ }
113
+ }
114
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
115
+ return response.ok ? { data: {}, response } : { error: {}, response };
116
+ }
117
+ if (response.ok) {
118
+ if (parseAs === "stream") {
119
+ return { data: response.body, response };
120
+ }
121
+ return { data: await response[parseAs](), response };
122
+ }
123
+ let error = await response.text();
124
+ try {
125
+ error = JSON.parse(error);
126
+ } catch {
127
+ }
128
+ return { error, response };
129
+ }
130
+ return {
131
+ /** Call a GET endpoint */
132
+ GET(url, init) {
133
+ return coreFetch(url, { ...init, method: "GET" });
134
+ },
135
+ /** Call a PUT endpoint */
136
+ PUT(url, init) {
137
+ return coreFetch(url, { ...init, method: "PUT" });
138
+ },
139
+ /** Call a POST endpoint */
140
+ POST(url, init) {
141
+ return coreFetch(url, { ...init, method: "POST" });
142
+ },
143
+ /** Call a DELETE endpoint */
144
+ DELETE(url, init) {
145
+ return coreFetch(url, { ...init, method: "DELETE" });
146
+ },
147
+ /** Call a OPTIONS endpoint */
148
+ OPTIONS(url, init) {
149
+ return coreFetch(url, { ...init, method: "OPTIONS" });
150
+ },
151
+ /** Call a HEAD endpoint */
152
+ HEAD(url, init) {
153
+ return coreFetch(url, { ...init, method: "HEAD" });
154
+ },
155
+ /** Call a PATCH endpoint */
156
+ PATCH(url, init) {
157
+ return coreFetch(url, { ...init, method: "PATCH" });
158
+ },
159
+ /** Call a TRACE endpoint */
160
+ TRACE(url, init) {
161
+ return coreFetch(url, { ...init, method: "TRACE" });
162
+ },
163
+ /** Register middleware */
164
+ use(...middleware) {
165
+ for (const m2 of middleware) {
166
+ if (!m2) {
167
+ continue;
168
+ }
169
+ if (typeof m2 !== "object" || !("onRequest" in m2 || "onResponse" in m2)) {
170
+ throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");
171
+ }
172
+ middlewares.push(m2);
173
+ }
174
+ },
175
+ /** Unregister middleware */
176
+ eject(...middleware) {
177
+ for (const m2 of middleware) {
178
+ const i2 = middlewares.indexOf(m2);
179
+ if (i2 !== -1) {
180
+ middlewares.splice(i2, 1);
181
+ }
182
+ }
183
+ }
184
+ };
185
+ }
186
+ function serializePrimitiveParam(name, value, options) {
187
+ if (value === void 0 || value === null) {
188
+ return "";
189
+ }
190
+ if (typeof value === "object") {
191
+ throw new Error(
192
+ "Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
193
+ );
194
+ }
195
+ return `${name}=${options?.allowReserved === true ? value : encodeURIComponent(value)}`;
196
+ }
197
+ function serializeObjectParam(name, value, options) {
198
+ if (!value || typeof value !== "object") {
199
+ return "";
200
+ }
201
+ const values = [];
202
+ const joiner = {
203
+ simple: ",",
204
+ label: ".",
205
+ matrix: ";"
206
+ }[options.style] || "&";
207
+ if (options.style !== "deepObject" && options.explode === false) {
208
+ for (const k2 in value) {
209
+ values.push(k2, options.allowReserved === true ? value[k2] : encodeURIComponent(value[k2]));
210
+ }
211
+ const final2 = values.join(",");
212
+ switch (options.style) {
213
+ case "form": {
214
+ return `${name}=${final2}`;
215
+ }
216
+ case "label": {
217
+ return `.${final2}`;
218
+ }
219
+ case "matrix": {
220
+ return `;${name}=${final2}`;
221
+ }
222
+ default: {
223
+ return final2;
224
+ }
225
+ }
226
+ }
227
+ for (const k2 in value) {
228
+ const finalName = options.style === "deepObject" ? `${name}[${k2}]` : k2;
229
+ values.push(serializePrimitiveParam(finalName, value[k2], options));
230
+ }
231
+ const final = values.join(joiner);
232
+ return options.style === "label" || options.style === "matrix" ? `${joiner}${final}` : final;
233
+ }
234
+ function serializeArrayParam(name, value, options) {
235
+ if (!Array.isArray(value)) {
236
+ return "";
237
+ }
238
+ if (options.explode === false) {
239
+ const joiner2 = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[options.style] || ",";
240
+ const final = (options.allowReserved === true ? value : value.map((v2) => encodeURIComponent(v2))).join(joiner2);
241
+ switch (options.style) {
242
+ case "simple": {
243
+ return final;
244
+ }
245
+ case "label": {
246
+ return `.${final}`;
247
+ }
248
+ case "matrix": {
249
+ return `;${name}=${final}`;
250
+ }
251
+ default: {
252
+ return `${name}=${final}`;
253
+ }
254
+ }
255
+ }
256
+ const joiner = { simple: ",", label: ".", matrix: ";" }[options.style] || "&";
257
+ const values = [];
258
+ for (const v2 of value) {
259
+ if (options.style === "simple" || options.style === "label") {
260
+ values.push(options.allowReserved === true ? v2 : encodeURIComponent(v2));
261
+ } else {
262
+ values.push(serializePrimitiveParam(name, v2, options));
263
+ }
264
+ }
265
+ return options.style === "label" || options.style === "matrix" ? `${joiner}${values.join(joiner)}` : values.join(joiner);
266
+ }
267
+ function createQuerySerializer(options) {
268
+ return function querySerializer(queryParams) {
269
+ const search = [];
270
+ if (queryParams && typeof queryParams === "object") {
271
+ for (const name in queryParams) {
272
+ const value = queryParams[name];
273
+ if (value === void 0 || value === null) {
274
+ continue;
275
+ }
276
+ if (Array.isArray(value)) {
277
+ if (value.length === 0) {
278
+ continue;
279
+ }
280
+ search.push(
281
+ serializeArrayParam(name, value, {
282
+ style: "form",
283
+ explode: true,
284
+ ...options?.array,
285
+ allowReserved: options?.allowReserved || false
286
+ })
287
+ );
288
+ continue;
289
+ }
290
+ if (typeof value === "object") {
291
+ search.push(
292
+ serializeObjectParam(name, value, {
293
+ style: "deepObject",
294
+ explode: true,
295
+ ...options?.object,
296
+ allowReserved: options?.allowReserved || false
297
+ })
298
+ );
299
+ continue;
300
+ }
301
+ search.push(serializePrimitiveParam(name, value, options));
302
+ }
303
+ }
304
+ return search.join("&");
305
+ };
306
+ }
307
+ function defaultPathSerializer(pathname, pathParams) {
308
+ let nextURL = pathname;
309
+ for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
310
+ let name = match.substring(1, match.length - 1);
311
+ let explode = false;
312
+ let style = "simple";
313
+ if (name.endsWith("*")) {
314
+ explode = true;
315
+ name = name.substring(0, name.length - 1);
316
+ }
317
+ if (name.startsWith(".")) {
318
+ style = "label";
319
+ name = name.substring(1);
320
+ } else if (name.startsWith(";")) {
321
+ style = "matrix";
322
+ name = name.substring(1);
323
+ }
324
+ if (!pathParams || pathParams[name] === void 0 || pathParams[name] === null) {
325
+ continue;
326
+ }
327
+ const value = pathParams[name];
328
+ if (Array.isArray(value)) {
329
+ nextURL = nextURL.replace(match, serializeArrayParam(name, value, { style, explode }));
330
+ continue;
331
+ }
332
+ if (typeof value === "object") {
333
+ nextURL = nextURL.replace(match, serializeObjectParam(name, value, { style, explode }));
334
+ continue;
335
+ }
336
+ if (style === "matrix") {
337
+ nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
338
+ continue;
339
+ }
340
+ nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
341
+ }
342
+ return nextURL;
343
+ }
344
+ function defaultBodySerializer(body) {
345
+ if (body instanceof FormData) {
346
+ return body;
347
+ }
348
+ return JSON.stringify(body);
349
+ }
350
+ function createFinalURL(pathname, options) {
351
+ let finalURL = `${options.baseUrl}${pathname}`;
352
+ if (options.params?.path) {
353
+ finalURL = defaultPathSerializer(finalURL, options.params.path);
354
+ }
355
+ let search = options.querySerializer(options.params.query ?? {});
356
+ if (search.startsWith("?")) {
357
+ search = search.substring(1);
358
+ }
359
+ if (search) {
360
+ finalURL += `?${search}`;
361
+ }
362
+ return finalURL;
363
+ }
364
+ function mergeHeaders(...allHeaders) {
365
+ const finalHeaders = new Headers();
366
+ for (const h2 of allHeaders) {
367
+ if (!h2 || typeof h2 !== "object") {
368
+ continue;
369
+ }
370
+ const iterator = h2 instanceof Headers ? h2.entries() : Object.entries(h2);
371
+ for (const [k2, v2] of iterator) {
372
+ if (v2 === null) {
373
+ finalHeaders.delete(k2);
374
+ } else if (Array.isArray(v2)) {
375
+ for (const v22 of v2) {
376
+ finalHeaders.append(k2, v22);
377
+ }
378
+ } else if (v2 !== void 0) {
379
+ finalHeaders.set(k2, v2);
380
+ }
381
+ }
382
+ }
383
+ return finalHeaders;
384
+ }
385
+ function removeTrailingSlash(url) {
386
+ if (url.endsWith("/")) {
387
+ return url.substring(0, url.length - 1);
388
+ }
389
+ return url;
390
+ }
391
+ class ObiClient {
392
+ constructor(config) {
393
+ this.client = createClient({
394
+ baseUrl: config.baseUrl,
395
+ headers: config.headers,
396
+ fetch: config.fetch
397
+ });
398
+ }
399
+ /**
400
+ * Set authorization header for authenticated requests
401
+ */
402
+ setAuthToken(token) {
403
+ this.client.use({
404
+ onRequest({ request }) {
405
+ request.headers.set("Authorization", `Bearer ${token}`);
406
+ return request;
407
+ }
408
+ });
409
+ }
410
+ /**
411
+ * Set API token for tool calls and notifications
412
+ */
413
+ setApiToken(token) {
414
+ this.client.use({
415
+ onRequest({ request }) {
416
+ request.headers.set("Authorization", `Token ${token}`);
417
+ return request;
418
+ }
419
+ });
420
+ }
421
+ // Auth endpoints
422
+ async getAuthUrl(type) {
423
+ return await this.client.GET("/auth/{type}", {
424
+ params: { path: { type } }
425
+ });
426
+ }
427
+ async getConnectUrl(type) {
428
+ return await this.client.GET("/connect/{type}", {
429
+ params: { path: { type } }
430
+ });
431
+ }
432
+ async logout() {
433
+ return await this.client.POST("/logout");
434
+ }
435
+ async getCurrentUser() {
436
+ return await this.client.GET("/me");
437
+ }
438
+ // Files
439
+ async createPresignedUploadUrl(data) {
440
+ return await this.client.POST("/files", {
441
+ body: data
442
+ });
443
+ }
444
+ // Knowledge blocks
445
+ async createKnowledgeBlock(data) {
446
+ return await this.client.POST("/knowledge", {
447
+ body: data
448
+ });
449
+ }
450
+ // Onboardees
451
+ async listOnboardees() {
452
+ return await this.client.GET("/onboardees");
453
+ }
454
+ async getOnboardeeWhitelistedDomains(id) {
455
+ return await this.client.GET("/onboardees/{id}/whitelisted-domains", {
456
+ params: { path: { id } }
457
+ });
458
+ }
459
+ // Plans
460
+ async listPlans() {
461
+ return await this.client.GET("/plans");
462
+ }
463
+ async createPlan(data) {
464
+ return await this.client.POST("/plans", {
465
+ body: data
466
+ });
467
+ }
468
+ async getPlan(id) {
469
+ return await this.client.GET("/plans/{id}", {
470
+ params: { path: { id } }
471
+ });
472
+ }
473
+ async replacePlan(id, data) {
474
+ return await this.client.PUT("/plans/{id}", {
475
+ params: { path: { id } },
476
+ body: data
477
+ });
478
+ }
479
+ async updatePlan(id, data) {
480
+ return await this.client.PATCH("/plans/{id}", {
481
+ params: { path: { id } },
482
+ body: data
483
+ });
484
+ }
485
+ // Sessions
486
+ async listSessions(token) {
487
+ return await this.client.GET("/sessions", {
488
+ params: { query: token ? { token } : {} }
489
+ });
490
+ }
491
+ async createSession(data) {
492
+ return await this.client.POST("/sessions", {
493
+ body: data
494
+ });
495
+ }
496
+ async getSession(id) {
497
+ return await this.client.GET("/sessions/{id}", {
498
+ params: { path: { id } }
499
+ });
500
+ }
501
+ async getSessionRecording(id) {
502
+ return await this.client.GET("/sessions/{id}/recording", {
503
+ params: { path: { id } }
504
+ });
505
+ }
506
+ async getSessionProductUrl(id) {
507
+ return await this.client.GET("/sessions/{id}/product-url", {
508
+ params: { path: { id } }
509
+ });
510
+ }
511
+ async getJoinToken(token, { skipIntro } = {}) {
512
+ return await this.client.GET("/join-token", {
513
+ params: {
514
+ query: {
515
+ token,
516
+ ...skipIntro && { skip_intro: "true" }
517
+ }
518
+ }
519
+ });
520
+ }
521
+ /**
522
+ * Get the underlying openapi-fetch client for advanced usage
523
+ */
524
+ getClient() {
525
+ return this.client;
526
+ }
527
+ }
3
528
  function getDefaultExportFromCjs$1(x2) {
4
529
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
5
530
  }
@@ -22768,6 +23293,8 @@ class ObiSession {
22768
23293
  }
22769
23294
  }
22770
23295
  }
23296
+ const SESSION_URL_PARAM = "49206C6F7665204F6269_session";
23297
+ const API_KEY_URL_PARAM = "49206C6F7665204F6269_client";
22771
23298
  var extendStatics = function(d2, b2) {
22772
23299
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
22773
23300
  d3.__proto__ = b3;
@@ -31658,15 +32185,15 @@ const STORAGE_KEYS = {
31658
32185
  SESSION_DATA: "session_data"
31659
32186
  };
31660
32187
  const storage = new StorageManager("io.obi.widget");
31661
- var __defProp$6 = Object.defineProperty;
31662
- var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
31663
- var __decorateClass$6 = (decorators, target, key, kind) => {
31664
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
32188
+ var __defProp$7 = Object.defineProperty;
32189
+ var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
32190
+ var __decorateClass$7 = (decorators, target, key, kind) => {
32191
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
31665
32192
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
31666
32193
  if (decorator = decorators[i2])
31667
32194
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
31668
32195
  if (kind && result)
31669
- __defProp$6(target, key, result);
32196
+ __defProp$7(target, key, result);
31670
32197
  return result;
31671
32198
  };
31672
32199
  class NavIcon extends LitElement {
@@ -31759,16 +32286,16 @@ NavIcon.styles = css`
31759
32286
  height: 18px;
31760
32287
  }
31761
32288
  `;
31762
- __decorateClass$6([
32289
+ __decorateClass$7([
31763
32290
  n$3({ type: String })
31764
32291
  ], NavIcon.prototype, "id", 2);
31765
- __decorateClass$6([
32292
+ __decorateClass$7([
31766
32293
  n$3({ type: Boolean })
31767
32294
  ], NavIcon.prototype, "isActive", 2);
31768
- __decorateClass$6([
32295
+ __decorateClass$7([
31769
32296
  n$3({ type: Boolean })
31770
32297
  ], NavIcon.prototype, "isSpecial", 2);
31771
- __decorateClass$6([
32298
+ __decorateClass$7([
31772
32299
  n$3({ type: Function })
31773
32300
  ], NavIcon.prototype, "onClick", 2);
31774
32301
  if (!customElements.get("obi-nav-icon")) {
@@ -31817,15 +32344,15 @@ const obiIcon = html`
31817
32344
  alt="Obi Icon"
31818
32345
  />
31819
32346
  `;
31820
- var __defProp$5 = Object.defineProperty;
31821
- var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
31822
- var __decorateClass$5 = (decorators, target, key, kind) => {
31823
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
32347
+ var __defProp$6 = Object.defineProperty;
32348
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
32349
+ var __decorateClass$6 = (decorators, target, key, kind) => {
32350
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
31824
32351
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
31825
32352
  if (decorator = decorators[i2])
31826
32353
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
31827
32354
  if (kind && result)
31828
- __defProp$5(target, key, result);
32355
+ __defProp$6(target, key, result);
31829
32356
  return result;
31830
32357
  };
31831
32358
  class NavigationBar extends LitElement {
@@ -31899,36 +32426,36 @@ NavigationBar.styles = css`
31899
32426
  flex-direction: column;
31900
32427
  }
31901
32428
  `;
31902
- __decorateClass$5([
32429
+ __decorateClass$6([
31903
32430
  n$3({ type: Boolean })
31904
32431
  ], NavigationBar.prototype, "isActive", 2);
31905
- __decorateClass$5([
32432
+ __decorateClass$6([
31906
32433
  n$3({ type: Boolean })
31907
32434
  ], NavigationBar.prototype, "isScreenActive", 2);
31908
- __decorateClass$5([
32435
+ __decorateClass$6([
31909
32436
  n$3({ type: Object })
31910
32437
  ], NavigationBar.prototype, "position", 2);
31911
- __decorateClass$5([
32438
+ __decorateClass$6([
31912
32439
  n$3({ type: String })
31913
32440
  ], NavigationBar.prototype, "currentState", 2);
31914
- __decorateClass$5([
32441
+ __decorateClass$6([
31915
32442
  n$3({ type: String })
31916
32443
  ], NavigationBar.prototype, "direction", 2);
31917
- __decorateClass$5([
32444
+ __decorateClass$6([
31918
32445
  n$3({ type: Function })
31919
32446
  ], NavigationBar.prototype, "onItemSelect", 2);
31920
32447
  if (!customElements.get("obi-navigation-bar")) {
31921
32448
  customElements.define("obi-navigation-bar", NavigationBar);
31922
32449
  }
31923
- var __defProp$4 = Object.defineProperty;
31924
- var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
31925
- var __decorateClass$4 = (decorators, target, key, kind) => {
31926
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
32450
+ var __defProp$5 = Object.defineProperty;
32451
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
32452
+ var __decorateClass$5 = (decorators, target, key, kind) => {
32453
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
31927
32454
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
31928
32455
  if (decorator = decorators[i2])
31929
32456
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
31930
32457
  if (kind && result)
31931
- __defProp$4(target, key, result);
32458
+ __defProp$5(target, key, result);
31932
32459
  return result;
31933
32460
  };
31934
32461
  class Course extends LitElement {
@@ -31940,12 +32467,9 @@ class Course extends LitElement {
31940
32467
  this.imageSrc = "";
31941
32468
  }
31942
32469
  handleClick() {
31943
- if (this.onSelect) {
31944
- this.onSelect(this.id);
31945
- }
31946
32470
  this.dispatchEvent(
31947
32471
  new CustomEvent("course-select", {
31948
- detail: { id: this.id },
32472
+ detail: { id: this.id, name: this.name, description: this.description },
31949
32473
  bubbles: true,
31950
32474
  composed: true
31951
32475
  })
@@ -32007,21 +32531,18 @@ Course.styles = css`
32007
32531
  margin: 0;
32008
32532
  }
32009
32533
  `;
32010
- __decorateClass$4([
32534
+ __decorateClass$5([
32011
32535
  n$3({ type: String })
32012
32536
  ], Course.prototype, "id", 2);
32013
- __decorateClass$4([
32537
+ __decorateClass$5([
32014
32538
  n$3({ type: String })
32015
32539
  ], Course.prototype, "name", 2);
32016
- __decorateClass$4([
32540
+ __decorateClass$5([
32017
32541
  n$3({ type: String })
32018
32542
  ], Course.prototype, "description", 2);
32019
- __decorateClass$4([
32543
+ __decorateClass$5([
32020
32544
  n$3({ type: String })
32021
32545
  ], Course.prototype, "imageSrc", 2);
32022
- __decorateClass$4([
32023
- n$3({ type: Function })
32024
- ], Course.prototype, "onSelect", 2);
32025
32546
  class CourseList extends LitElement {
32026
32547
  constructor() {
32027
32548
  super(...arguments);
@@ -32029,11 +32550,6 @@ class CourseList extends LitElement {
32029
32550
  this.loading = false;
32030
32551
  this.error = "";
32031
32552
  }
32032
- handleCourseSelect(e2) {
32033
- if (this.onCourseSelect) {
32034
- this.onCourseSelect(e2.detail.id);
32035
- }
32036
- }
32037
32553
  render() {
32038
32554
  if (this.loading) {
32039
32555
  return html`<div class="loading">Loading...</div>`;
@@ -32054,7 +32570,6 @@ class CourseList extends LitElement {
32054
32570
  name=${course.name}
32055
32571
  description=${course.description || ""}
32056
32572
  imageSrc=${course.imageSrc}
32057
- @course-select=${this.handleCourseSelect}
32058
32573
  ></obi-course>
32059
32574
  `
32060
32575
  )}
@@ -32098,33 +32613,30 @@ CourseList.styles = css`
32098
32613
  color: #ef4444;
32099
32614
  }
32100
32615
  `;
32101
- __decorateClass$4([
32616
+ __decorateClass$5([
32102
32617
  n$3({ type: Array })
32103
32618
  ], CourseList.prototype, "courses", 2);
32104
- __decorateClass$4([
32619
+ __decorateClass$5([
32105
32620
  n$3({ type: Boolean })
32106
32621
  ], CourseList.prototype, "loading", 2);
32107
- __decorateClass$4([
32622
+ __decorateClass$5([
32108
32623
  n$3({ type: String })
32109
32624
  ], CourseList.prototype, "error", 2);
32110
- __decorateClass$4([
32111
- n$3({ type: Function })
32112
- ], CourseList.prototype, "onCourseSelect", 2);
32113
32625
  if (!customElements.get("obi-course")) {
32114
32626
  customElements.define("obi-course", Course);
32115
32627
  }
32116
32628
  if (!customElements.get("obi-course-list")) {
32117
32629
  customElements.define("obi-course-list", CourseList);
32118
32630
  }
32119
- var __defProp$3 = Object.defineProperty;
32120
- var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
32121
- var __decorateClass$3 = (decorators, target, key, kind) => {
32122
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
32631
+ var __defProp$4 = Object.defineProperty;
32632
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
32633
+ var __decorateClass$4 = (decorators, target, key, kind) => {
32634
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
32123
32635
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
32124
32636
  if (decorator = decorators[i2])
32125
32637
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
32126
32638
  if (kind && result)
32127
- __defProp$3(target, key, result);
32639
+ __defProp$4(target, key, result);
32128
32640
  return result;
32129
32641
  };
32130
32642
  class CourseModal extends LitElement {
@@ -32136,11 +32648,6 @@ class CourseModal extends LitElement {
32136
32648
  this.apiKey = "";
32137
32649
  this.apiBaseUrl = "";
32138
32650
  }
32139
- handleCourseSelect(e2) {
32140
- if (this.onCourseSelect) {
32141
- this.onCourseSelect(e2.detail.id);
32142
- }
32143
- }
32144
32651
  handleClose() {
32145
32652
  if (this.onClose) {
32146
32653
  this.onClose();
@@ -32195,7 +32702,6 @@ class CourseModal extends LitElement {
32195
32702
  .courses=${this.courses}
32196
32703
  .loading=${this.loading}
32197
32704
  .error=${this.error}
32198
- @course-select=${this.handleCourseSelect}
32199
32705
  ></obi-course-list>
32200
32706
  </div>
32201
32707
  `;
@@ -32285,25 +32791,22 @@ CourseModal.styles = css`
32285
32791
  color: #6b7280;
32286
32792
  }
32287
32793
  `;
32288
- __decorateClass$3([
32794
+ __decorateClass$4([
32289
32795
  n$3({ type: Array })
32290
32796
  ], CourseModal.prototype, "courses", 2);
32291
- __decorateClass$3([
32797
+ __decorateClass$4([
32292
32798
  n$3({ type: Boolean })
32293
32799
  ], CourseModal.prototype, "loading", 2);
32294
- __decorateClass$3([
32800
+ __decorateClass$4([
32295
32801
  n$3({ type: String })
32296
32802
  ], CourseModal.prototype, "error", 2);
32297
- __decorateClass$3([
32803
+ __decorateClass$4([
32298
32804
  n$3({ type: String })
32299
32805
  ], CourseModal.prototype, "apiKey", 2);
32300
- __decorateClass$3([
32301
- n$3({ type: Function })
32302
- ], CourseModal.prototype, "onCourseSelect", 2);
32303
- __decorateClass$3([
32806
+ __decorateClass$4([
32304
32807
  n$3({ type: Function })
32305
32808
  ], CourseModal.prototype, "onClose", 2);
32306
- __decorateClass$3([
32809
+ __decorateClass$4([
32307
32810
  r$2()
32308
32811
  ], CourseModal.prototype, "apiBaseUrl", 2);
32309
32812
  if (!customElements.get("obi-course-modal")) {
@@ -32652,15 +33155,15 @@ const o = /* @__PURE__ */ new WeakMap(), n2 = e$1(class extends f {
32652
33155
  this.rt(this.ct);
32653
33156
  }
32654
33157
  });
32655
- var __defProp$2 = Object.defineProperty;
32656
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
32657
- var __decorateClass$2 = (decorators, target, key, kind) => {
32658
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
33158
+ var __defProp$3 = Object.defineProperty;
33159
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
33160
+ var __decorateClass$3 = (decorators, target, key, kind) => {
33161
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
32659
33162
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
32660
33163
  if (decorator = decorators[i2])
32661
33164
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
32662
33165
  if (kind && result)
32663
- __defProp$2(target, key, result);
33166
+ __defProp$3(target, key, result);
32664
33167
  return result;
32665
33168
  };
32666
33169
  class AudioEqualizer extends LitElement {
@@ -32670,9 +33173,11 @@ class AudioEqualizer extends LitElement {
32670
33173
  this.canvasRef = e();
32671
33174
  this.barCount = 8;
32672
33175
  this.animationFrame = null;
33176
+ this.primaryColor = "#9500ff";
32673
33177
  }
32674
33178
  connectedCallback() {
32675
33179
  super.connectedCallback();
33180
+ this.primaryColor = getComputedStyle(this).getPropertyValue("--obi-primary").trim() || "#9500ff";
32676
33181
  this.startAnimation();
32677
33182
  }
32678
33183
  disconnectedCallback() {
@@ -32764,7 +33269,7 @@ class AudioEqualizer extends LitElement {
32764
33269
  const spectrumValue = processedSpectrum.length > 0 ? processedSpectrum[i2] !== void 0 ? processedSpectrum[i2] : currentVolume : currentVolume;
32765
33270
  if (this.volume.speaker === "USER") {
32766
33271
  const opacity2 = Math.floor((spectrumValue * 0.5 + 0.5) * 255).toString(16).padStart(2, "0");
32767
- ctx.fillStyle = `var(--obi-primary)${opacity2}`;
33272
+ ctx.fillStyle = `${this.primaryColor}${opacity2}`;
32768
33273
  } else {
32769
33274
  const opacity2 = Math.floor((spectrumValue * 0.5 + 0.5) * 255).toString(16).padStart(2, "0");
32770
33275
  ctx.fillStyle = `#FFFFFF${opacity2}`;
@@ -32829,24 +33334,24 @@ AudioEqualizer.styles = css`
32829
33334
  height: 100%;
32830
33335
  }
32831
33336
  `;
32832
- __decorateClass$2([
33337
+ __decorateClass$3([
32833
33338
  n$3({ type: Object })
32834
33339
  ], AudioEqualizer.prototype, "volume", 2);
32835
- __decorateClass$2([
33340
+ __decorateClass$3([
32836
33341
  r$2()
32837
33342
  ], AudioEqualizer.prototype, "canvasRef", 2);
32838
33343
  if (!customElements.get("obi-audio-equalizer")) {
32839
33344
  customElements.define("obi-audio-equalizer", AudioEqualizer);
32840
33345
  }
32841
- var __defProp$1 = Object.defineProperty;
32842
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
32843
- var __decorateClass$1 = (decorators, target, key, kind) => {
32844
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
33346
+ var __defProp$2 = Object.defineProperty;
33347
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
33348
+ var __decorateClass$2 = (decorators, target, key, kind) => {
33349
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
32845
33350
  for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
32846
33351
  if (decorator = decorators[i2])
32847
33352
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
32848
33353
  if (kind && result)
32849
- __defProp$1(target, key, result);
33354
+ __defProp$2(target, key, result);
32850
33355
  return result;
32851
33356
  };
32852
33357
  class DotLoader extends LitElement {
@@ -32947,7 +33452,7 @@ DotLoader.styles = css`
32947
33452
  opacity: 1;
32948
33453
  }
32949
33454
  `;
32950
- __decorateClass$1([
33455
+ __decorateClass$2([
32951
33456
  r$2()
32952
33457
  ], DotLoader.prototype, "activeDots", 2);
32953
33458
  if (!customElements.get("obi-dot-loader")) {
@@ -32980,6 +33485,205 @@ SearchingLoader.styles = css`
32980
33485
  if (!customElements.get("obi-searching-loader")) {
32981
33486
  customElements.define("obi-searching-loader", SearchingLoader);
32982
33487
  }
33488
+ var __defProp$1 = Object.defineProperty;
33489
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
33490
+ var __decorateClass$1 = (decorators, target, key, kind) => {
33491
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
33492
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
33493
+ if (decorator = decorators[i2])
33494
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33495
+ if (kind && result)
33496
+ __defProp$1(target, key, result);
33497
+ return result;
33498
+ };
33499
+ class SessionStartModal extends LitElement {
33500
+ handleStart() {
33501
+ if (this.onStart && this.session) {
33502
+ this.onStart(this.session.id);
33503
+ }
33504
+ }
33505
+ handleClose() {
33506
+ if (this.onClose) {
33507
+ this.onClose();
33508
+ }
33509
+ }
33510
+ handleBackdropClick(e2) {
33511
+ if (e2.target === e2.currentTarget) {
33512
+ this.handleClose();
33513
+ }
33514
+ }
33515
+ render() {
33516
+ return html`
33517
+ <div class="backdrop" @click=${this.handleBackdropClick}></div>
33518
+ <div class="container">
33519
+ <button class="close-button" @click=${this.handleClose}>×</button>
33520
+
33521
+ <div class="header">
33522
+ <div class="logo">${obiIcon}</div>
33523
+ <h1>${this.session.name}</h1>
33524
+ <p class="subtitle">${this.session.description}</p>
33525
+ </div>
33526
+
33527
+ <button class="button button-primary" @click=${this.handleStart}>Continue →</button>
33528
+ </div>
33529
+ `;
33530
+ }
33531
+ }
33532
+ SessionStartModal.styles = css`
33533
+ :host {
33534
+ display: block;
33535
+ font-family: "Inter", sans-serif;
33536
+ }
33537
+
33538
+ .backdrop {
33539
+ position: fixed;
33540
+ top: 0;
33541
+ right: 0;
33542
+ bottom: 0;
33543
+ left: 0;
33544
+ background-color: rgba(0, 0, 0, 0.5);
33545
+ z-index: 40;
33546
+ }
33547
+
33548
+ .container {
33549
+ position: fixed;
33550
+ top: 50%;
33551
+ left: 50%;
33552
+ transform: translate(-50%, -50%);
33553
+ z-index: 50;
33554
+
33555
+ /* Layout from user specifications */
33556
+ display: flex;
33557
+ width: 640px;
33558
+ height: 380px;
33559
+ padding: 48px 48px 32px 48px;
33560
+ flex-direction: column;
33561
+ justify-content: space-between;
33562
+ align-items: center;
33563
+ flex-shrink: 0;
33564
+
33565
+ /* Style from user specifications */
33566
+ border-radius: 12px;
33567
+ background: #fafafa;
33568
+ box-shadow:
33569
+ 0px 10px 15px -3px rgba(0, 0, 0, 0.1),
33570
+ 0px 4px 6px -2px rgba(0, 0, 0, 0.05);
33571
+ }
33572
+
33573
+ .header {
33574
+ display: flex;
33575
+ flex-direction: column;
33576
+ align-items: center;
33577
+ text-align: center;
33578
+ gap: 16px;
33579
+ }
33580
+
33581
+ .logo {
33582
+ display: flex;
33583
+ width: 96px;
33584
+ height: 96px;
33585
+ padding: 8px;
33586
+ justify-content: center;
33587
+ align-items: center;
33588
+ gap: 8px;
33589
+ aspect-ratio: 1/1;
33590
+ border-radius: var(--border-radius-lg, 8px);
33591
+ background: var(--tailwind-colors-violet-600, #7c3aed);
33592
+ box-shadow:
33593
+ 0px 0px 8px 0px rgba(168, 85, 247, 0.12),
33594
+ 0px 0px 8px 0px rgba(192, 132, 252, 0.24),
33595
+ 0px 0px 4px 0px rgba(192, 132, 252, 0.24),
33596
+ 0px 0px 4px 0px rgba(192, 132, 252, 0.24),
33597
+ 0px 0px 2px 0px rgba(192, 132, 252, 0.12),
33598
+ 0px 0px 1px 0px rgba(168, 85, 247, 0.24);
33599
+ }
33600
+
33601
+ .logo img {
33602
+ width: 48px;
33603
+ height: 48px;
33604
+ color: white;
33605
+ fill: #fff;
33606
+ }
33607
+
33608
+ h1 {
33609
+ font-family: "Syne", sans-serif;
33610
+ font-size: 32px;
33611
+ font-weight: 700;
33612
+ margin: 32px 0 0 0;
33613
+ color: #111827;
33614
+ }
33615
+
33616
+ .subtitle {
33617
+ font-size: 16px;
33618
+ color: #6b7280;
33619
+ margin: 16px 0 0 0;
33620
+ line-height: 1.5;
33621
+ }
33622
+
33623
+ .button {
33624
+ padding: 12px 24px;
33625
+ border-radius: 8px;
33626
+ border: none;
33627
+ font-size: 16px;
33628
+ font-weight: 500;
33629
+ cursor: pointer;
33630
+ transition: all 0.2s ease;
33631
+ display: flex;
33632
+ align-items: center;
33633
+ justify-content: center;
33634
+ gap: 8px;
33635
+ }
33636
+
33637
+ .button-primary {
33638
+ display: flex;
33639
+ width: 100%;
33640
+ height: var(--height-h-11, 44px);
33641
+ padding: var(--spacing-2, 8px) var(--spacing-4, 16px);
33642
+ justify-content: center;
33643
+ align-items: center;
33644
+ gap: var(--spacing-2, 8px);
33645
+ flex-shrink: 0;
33646
+ align-self: stretch;
33647
+ border-radius: var(--border-radius-default, 6px);
33648
+ background: var(--base-primary, #18181b);
33649
+ color: white;
33650
+ }
33651
+
33652
+ .button-primary:hover {
33653
+ background: color-mix(in srgb, var(--base-primary, #18181b) 90%, white);
33654
+ }
33655
+
33656
+ .close-button {
33657
+ position: absolute;
33658
+ top: 16px;
33659
+ right: 16px;
33660
+ background: none;
33661
+ border: none;
33662
+ cursor: pointer;
33663
+ font-size: 24px;
33664
+ color: #6b7280;
33665
+ padding: 4px;
33666
+ border-radius: 4px;
33667
+ transition: all 0.2s ease;
33668
+ }
33669
+
33670
+ .close-button:hover {
33671
+ color: #374151;
33672
+ background: #f3f4f6;
33673
+ }
33674
+ `;
33675
+ __decorateClass$1([
33676
+ n$3({ type: Object })
33677
+ ], SessionStartModal.prototype, "session", 2);
33678
+ __decorateClass$1([
33679
+ n$3({ type: Function })
33680
+ ], SessionStartModal.prototype, "onStart", 2);
33681
+ __decorateClass$1([
33682
+ n$3({ type: Function })
33683
+ ], SessionStartModal.prototype, "onClose", 2);
33684
+ if (!customElements.get("obi-session-start-modal")) {
33685
+ customElements.define("obi-session-start-modal", SessionStartModal);
33686
+ }
32983
33687
  var __defProp = Object.defineProperty;
32984
33688
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
32985
33689
  var __decorateClass = (decorators, target, key, kind) => {
@@ -32991,7 +33695,6 @@ var __decorateClass = (decorators, target, key, kind) => {
32991
33695
  __defProp(target, key, result);
32992
33696
  return result;
32993
33697
  };
32994
- const SESSION_URL_PARAM = "49206C6F7665204F6269_session";
32995
33698
  class ObiWidget extends LitElement {
32996
33699
  constructor() {
32997
33700
  super();
@@ -33002,6 +33705,8 @@ class ObiWidget extends LitElement {
33002
33705
  this.state = SDKState.READY;
33003
33706
  this.storedActiveState = void 0;
33004
33707
  this.showCourseModal = false;
33708
+ this.showSessionStartModal = false;
33709
+ this.selectedCourse = null;
33005
33710
  this.isHovering = false;
33006
33711
  this.navVisible = false;
33007
33712
  this.activeSession = null;
@@ -33014,7 +33719,41 @@ class ObiWidget extends LitElement {
33014
33719
  this.roomToken = null;
33015
33720
  this.roomUrl = null;
33016
33721
  this.boundSaveSessionData = null;
33722
+ this.obiClient = null;
33017
33723
  this.closeNavTimeoutRef = null;
33724
+ this.handleCourseSelectEvent = (event) => {
33725
+ const customEvent = event;
33726
+ this.selectedCourse = customEvent.detail;
33727
+ this.showCourseModal = false;
33728
+ this.showSessionStartModal = true;
33729
+ };
33730
+ this.handleUrlSessionEvent = async (sessionToken) => {
33731
+ try {
33732
+ if (!this.obiClient) {
33733
+ console.error("ObiClient not initialized");
33734
+ return;
33735
+ }
33736
+ const sessionsResponse = await this.obiClient.listSessions(this.apiKey);
33737
+ if (sessionsResponse.data) {
33738
+ const sessions = sessionsResponse.data.sessions;
33739
+ const matchingSession = sessions?.find((session) => session.uuid === sessionToken);
33740
+ if (matchingSession) {
33741
+ const sessionWithPlan = matchingSession;
33742
+ this.selectedCourse = {
33743
+ id: sessionToken,
33744
+ name: sessionWithPlan.onboarding_plan?.product?.name || "Session from URL",
33745
+ description: sessionWithPlan.onboarding_plan?.product?.description || "Continue your session"
33746
+ };
33747
+ this.showSessionStartModal = true;
33748
+ }
33749
+ }
33750
+ } catch (error) {
33751
+ console.error("Failed to fetch session details:", error);
33752
+ }
33753
+ };
33754
+ this.obiClient = new ObiClient({
33755
+ baseUrl: API_BASE_URL
33756
+ });
33018
33757
  const handleUnload = () => {
33019
33758
  if (this.activeSession && this.sessionToken && this.roomToken && this.roomUrl) {
33020
33759
  this.saveSessionData();
@@ -33039,13 +33778,13 @@ class ObiWidget extends LitElement {
33039
33778
  removeSessionFromUrl() {
33040
33779
  const url = new URL(window.location.href);
33041
33780
  url.searchParams.delete(SESSION_URL_PARAM);
33781
+ url.searchParams.delete(API_KEY_URL_PARAM);
33042
33782
  window.history.replaceState({}, "", url.toString());
33043
33783
  }
33044
- async connectObi(sessionToken) {
33045
- if (this.activeSession) {
33046
- console.log("Connection already exists");
33047
- return;
33048
- }
33784
+ /**
33785
+ * Create a new ObiSession instance with common configuration
33786
+ */
33787
+ createSession(sessionToken) {
33049
33788
  try {
33050
33789
  const session = new ObiSession({
33051
33790
  sessionId: sessionToken,
@@ -33053,20 +33792,58 @@ class ObiWidget extends LitElement {
33053
33792
  });
33054
33793
  if (!session) {
33055
33794
  console.error("Failed to create session");
33056
- this.state = SDKState.ERROR;
33057
- this.activeSession = null;
33058
- this.removeSessionFromUrl();
33795
+ return null;
33796
+ }
33797
+ return session;
33798
+ } catch (error) {
33799
+ console.error("Error creating session:", error);
33800
+ return null;
33801
+ }
33802
+ }
33803
+ /**
33804
+ * Set up common event listeners for a session
33805
+ */
33806
+ setupSessionEventListeners(session, onError) {
33807
+ session.on("stateChanged", (newState) => {
33808
+ this.state = newState;
33809
+ if (newState !== SDKState.READY) {
33810
+ this.storedActiveState = newState;
33811
+ }
33812
+ });
33813
+ session.on("volume", ({ speaker, spectrum, volume }) => {
33814
+ this.volume = { speaker, spectrum, volume };
33815
+ });
33816
+ session.on("error", (error) => {
33817
+ console.error("Session error:", error);
33818
+ this.state = SDKState.ERROR;
33819
+ this.activeSession = null;
33820
+ if (onError) {
33821
+ onError();
33822
+ }
33823
+ });
33824
+ }
33825
+ /**
33826
+ * Handle session creation failure
33827
+ */
33828
+ handleSessionCreationFailure(onFailure) {
33829
+ this.state = SDKState.ERROR;
33830
+ this.activeSession = null;
33831
+ if (onFailure) {
33832
+ onFailure();
33833
+ }
33834
+ }
33835
+ async connectObi(sessionToken) {
33836
+ if (this.activeSession) {
33837
+ console.log("Connection already exists");
33838
+ return;
33839
+ }
33840
+ try {
33841
+ const session = this.createSession(sessionToken);
33842
+ if (!session) {
33843
+ this.handleSessionCreationFailure(() => this.removeSessionFromUrl());
33059
33844
  return;
33060
33845
  }
33061
- session.on("stateChanged", (newState) => {
33062
- this.state = newState;
33063
- if (newState !== SDKState.READY) {
33064
- this.storedActiveState = newState;
33065
- }
33066
- });
33067
- session.on("volume", ({ speaker, spectrum, volume }) => {
33068
- this.volume = { speaker, spectrum, volume };
33069
- });
33846
+ this.setupSessionEventListeners(session, () => this.removeSessionFromUrl());
33070
33847
  session.on("screenCaptureRequested", async () => {
33071
33848
  try {
33072
33849
  const canvas = await html2canvas(document.documentElement, {
@@ -33081,12 +33858,6 @@ class ObiWidget extends LitElement {
33081
33858
  this.activeSession.emit("screenCaptureComplete", "error");
33082
33859
  }
33083
33860
  });
33084
- session.on("error", (error) => {
33085
- console.error("Session error:", error);
33086
- this.state = SDKState.ERROR;
33087
- this.activeSession = null;
33088
- this.removeSessionFromUrl();
33089
- });
33090
33861
  const connectionInfo = await session.connect();
33091
33862
  if (connectionInfo) {
33092
33863
  this.sessionToken = sessionToken;
@@ -33097,9 +33868,7 @@ class ObiWidget extends LitElement {
33097
33868
  this.activeSession = session;
33098
33869
  } catch (error) {
33099
33870
  console.error("Failed to start session:", error);
33100
- this.state = SDKState.ERROR;
33101
- this.activeSession = null;
33102
- this.removeSessionFromUrl();
33871
+ this.handleSessionCreationFailure(() => this.removeSessionFromUrl());
33103
33872
  }
33104
33873
  }
33105
33874
  async handleSessionStart(sessionToken) {
@@ -33107,7 +33876,7 @@ class ObiWidget extends LitElement {
33107
33876
  console.log("Connection already in progress or active session exists");
33108
33877
  return;
33109
33878
  }
33110
- this.showCourseModal = false;
33879
+ this.showSessionStartModal = false;
33111
33880
  this.state = SDKState.LOADING;
33112
33881
  await this.connectObi(sessionToken);
33113
33882
  }
@@ -33132,31 +33901,12 @@ class ObiWidget extends LitElement {
33132
33901
  }
33133
33902
  }
33134
33903
  this.state = SDKState.LOADING;
33135
- const session = new ObiSession({
33136
- sessionId: sessionToken,
33137
- apiBaseUrl: API_BASE_URL
33138
- });
33904
+ const session = this.createSession(sessionToken);
33139
33905
  if (!session) {
33140
- console.error("Failed to create session");
33141
- this.state = SDKState.ERROR;
33142
- this.clearSessionStorage();
33906
+ this.handleSessionCreationFailure(() => this.clearSessionStorage());
33143
33907
  return;
33144
33908
  }
33145
- session.on("stateChanged", (newState) => {
33146
- this.state = newState;
33147
- if (newState !== SDKState.READY) {
33148
- this.storedActiveState = newState;
33149
- }
33150
- });
33151
- session.on("volume", ({ speaker, spectrum, volume }) => {
33152
- this.volume = { speaker, spectrum, volume };
33153
- });
33154
- session.on("error", (error) => {
33155
- console.error("Session error:", error);
33156
- this.state = SDKState.ERROR;
33157
- this.activeSession = null;
33158
- this.clearSessionStorage();
33159
- });
33909
+ this.setupSessionEventListeners(session, () => this.clearSessionStorage());
33160
33910
  const reconnected = await session.reconnect(roomUrl, roomToken, obiState);
33161
33911
  if (reconnected) {
33162
33912
  this.activeSession = session;
@@ -33170,8 +33920,7 @@ class ObiWidget extends LitElement {
33170
33920
  }
33171
33921
  } catch (error) {
33172
33922
  console.error("Error reconnecting to session:", error);
33173
- this.state = SDKState.ERROR;
33174
- this.clearSessionStorage();
33923
+ this.handleSessionCreationFailure(() => this.clearSessionStorage());
33175
33924
  }
33176
33925
  }
33177
33926
  /**
@@ -33202,8 +33951,9 @@ class ObiWidget extends LitElement {
33202
33951
  if (!this.activeSession) {
33203
33952
  const urlParams = new URLSearchParams(window.location.search);
33204
33953
  const sessionId = urlParams.get(SESSION_URL_PARAM);
33205
- if (sessionId) {
33206
- this.handleSessionStart(sessionId);
33954
+ this.apiKey = urlParams.get(API_KEY_URL_PARAM) || this.apiKey;
33955
+ if (sessionId && this.apiKey) {
33956
+ await this.handleUrlSessionEvent(sessionId);
33207
33957
  }
33208
33958
  }
33209
33959
  }
@@ -33299,9 +34049,17 @@ class ObiWidget extends LitElement {
33299
34049
  </div>
33300
34050
  ${this.showCourseModal ? html`<obi-course-modal
33301
34051
  .onClose=${() => this.showCourseModal = false}
33302
- .onCourseSelect=${this.handleSessionStart.bind(this)}
34052
+ @course-select=${this.handleCourseSelectEvent}
33303
34053
  .apiKey=${this.apiKey}
33304
34054
  ></obi-course-modal>` : nothing}
34055
+ ${this.showSessionStartModal && this.selectedCourse ? html`<obi-session-start-modal
34056
+ .session=${this.selectedCourse}
34057
+ .onStart=${this.handleSessionStart.bind(this)}
34058
+ .onClose=${() => {
34059
+ this.showSessionStartModal = false;
34060
+ this.selectedCourse = null;
34061
+ }}
34062
+ ></obi-session-start-modal>` : nothing}
33305
34063
  `;
33306
34064
  }
33307
34065
  }
@@ -33458,6 +34216,12 @@ __decorateClass([
33458
34216
  __decorateClass([
33459
34217
  r$2()
33460
34218
  ], ObiWidget.prototype, "showCourseModal", 2);
34219
+ __decorateClass([
34220
+ r$2()
34221
+ ], ObiWidget.prototype, "showSessionStartModal", 2);
34222
+ __decorateClass([
34223
+ r$2()
34224
+ ], ObiWidget.prototype, "selectedCourse", 2);
33461
34225
  __decorateClass([
33462
34226
  r$2()
33463
34227
  ], ObiWidget.prototype, "isHovering", 2);