@omni-commerce/sdk 0.8.1 → 0.9.2

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.
package/dist/react.cjs CHANGED
@@ -4,6 +4,7 @@ var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
8
  var __export = (target, all) => {
8
9
  for (var name in all)
9
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,15 +18,17 @@ var __copyProps = (to, from, except, desc) => {
17
18
  return to;
18
19
  };
19
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
20
22
 
21
23
  // src/react.tsx
22
24
  var react_exports = {};
23
25
  __export(react_exports, {
24
26
  OmniChat: () => OmniChat,
27
+ OmniChatLayout: () => OmniChatLayout,
25
28
  OmniProvider: () => OmniProvider
26
29
  });
27
30
  module.exports = __toCommonJS(react_exports);
28
- var import_react = require("react");
31
+ var import_react2 = require("react");
29
32
 
30
33
  // src/application.ts
31
34
  function boundedJson(value, maximum) {
@@ -110,26 +113,24 @@ function createApplicationMessageHandler(input) {
110
113
  };
111
114
  }
112
115
 
113
- // src/embed.ts
114
- function getOmniChatEmbedUrl(options, parentOrigin) {
115
- if (!/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i.test(
116
- options.deploymentId
117
- ))
118
- throw new Error("A valid chat deployment ID is required.");
119
- const base = new URL(options.baseUrl ?? "https://omnicommerce.sg");
120
- if (base.protocol !== "https:" && !(base.protocol === "http:" && ["localhost", "127.0.0.1"].includes(base.hostname)) || base.username || base.password || base.pathname !== "/" || base.search || base.hash)
121
- throw new Error("Chat baseUrl must be an HTTPS origin, or HTTP localhost.");
122
- const url = new URL(`/embed/${options.deploymentId}`, base.origin);
123
- if (parentOrigin)
124
- url.searchParams.set("parentOrigin", new URL(parentOrigin).origin);
125
- return url.toString();
116
+ // ../../lib/assistant/application-chat/bridge-scope.ts
117
+ function matchesHostedChatScope(message, scope) {
118
+ return scope.deploymentId !== void 0 ? message?.deploymentId === scope.deploymentId && message.chatId === void 0 : message?.chatId === scope.chatId && message.deploymentId === void 0;
126
119
  }
127
- function createOmniChatEmbed(container, options) {
120
+
121
+ // src/hosted-chat.ts
122
+ var ChatSessionError = class extends Error {
123
+ constructor(message, status) {
124
+ super(message);
125
+ __publicField(this, "status", status);
126
+ }
127
+ };
128
+ function mountHostedChat(container, options, target) {
128
129
  const document = container.ownerDocument;
129
130
  const host = document.defaultView;
130
131
  if (!host) throw new Error("A browser document is required to mount chat.");
131
132
  const iframe = document.createElement("iframe");
132
- iframe.src = getOmniChatEmbedUrl(options, host.location.origin);
133
+ iframe.src = target.url;
133
134
  iframe.title = options.title ?? "OmniCommerce assistant";
134
135
  iframe.referrerPolicy = "strict-origin-when-cross-origin";
135
136
  iframe.setAttribute(
@@ -143,47 +144,24 @@ function createOmniChatEmbed(container, options) {
143
144
  border: "0",
144
145
  display: "block"
145
146
  });
146
- const chatOrigin = new URL(iframe.src).origin;
147
+ const chatOrigin2 = new URL(iframe.src).origin;
147
148
  let destroyed = false;
148
149
  let pending;
149
150
  let previousToken;
150
151
  const controller = new AbortController();
151
- const mint = async () => {
152
- if (options.getSession) return options.getSession();
153
- const response = await host.fetch(
154
- `${chatOrigin}/api/embed/${options.deploymentId}/session`,
155
- {
156
- method: "POST",
157
- credentials: "include",
158
- signal: controller.signal,
159
- headers: {
160
- "Content-Type": "application/json",
161
- ...previousToken ? { Authorization: `Bearer ${previousToken}` } : {}
162
- },
163
- body: "{}"
164
- }
165
- );
166
- const result = await response.json();
167
- if (!response.ok) {
168
- if (response.status === 401 || response.status === 403)
169
- previousToken = void 0;
170
- throw new Error(result.error ?? "Could not open the chat session.");
171
- }
172
- return result;
173
- };
174
152
  const applicationMessage = createApplicationMessageHandler({
175
153
  options,
176
154
  signal: controller.signal,
177
155
  reply: (message) => {
178
156
  if (!destroyed)
179
157
  iframe.contentWindow?.postMessage(
180
- { ...message, deploymentId: options.deploymentId },
181
- chatOrigin
158
+ { ...message, ...target.scope },
159
+ chatOrigin2
182
160
  );
183
161
  }
184
162
  });
185
163
  const receive = (event) => {
186
- if (destroyed || event.source !== iframe.contentWindow || event.origin !== chatOrigin || event.data?.deploymentId !== options.deploymentId)
164
+ if (destroyed || event.source !== iframe.contentWindow || event.origin !== chatOrigin2 || !matchesHostedChatScope(event.data, target.scope))
187
165
  return;
188
166
  if (event.data.type === "omni-chat:application-request" || event.data.type === "omni-chat:tool-request") {
189
167
  void applicationMessage(event.data);
@@ -193,8 +171,9 @@ function createOmniChatEmbed(container, options) {
193
171
  options.onRequestClose?.();
194
172
  return;
195
173
  }
196
- if (event.data.type !== "omni-chat:session-request") return;
197
- pending ?? (pending = mint());
174
+ if (event.data.type !== "omni-chat:session-request" || !target.mint) return;
175
+ const visitorId = typeof event.data.visitorId === "string" ? event.data.visitorId : void 0;
176
+ pending ?? (pending = target.mint(previousToken, visitorId, controller.signal));
198
177
  void pending.then((session) => {
199
178
  if (destroyed) return;
200
179
  if (typeof session?.token !== "string" || !session.token || session.token.length > 4096 || typeof session.threadId !== "string" || !session.threadId || !Number.isFinite(session.expiresIn) || session.expiresIn <= 0)
@@ -203,24 +182,26 @@ function createOmniChatEmbed(container, options) {
203
182
  iframe.contentWindow?.postMessage(
204
183
  {
205
184
  type: "omni-chat:session",
206
- deploymentId: options.deploymentId,
185
+ ...target.scope,
207
186
  session,
208
187
  ...options.application ? { applicationEnabled: true } : {}
209
188
  },
210
- chatOrigin
189
+ chatOrigin2
211
190
  );
212
191
  }).catch((error) => {
213
192
  if (destroyed) return;
214
193
  const failure = error instanceof Error ? error : new Error("Could not open chat.");
194
+ if (failure instanceof ChatSessionError && [401, 403].includes(failure.status))
195
+ previousToken = void 0;
215
196
  options.onError?.(failure);
216
197
  iframe.contentWindow?.postMessage(
217
198
  {
218
199
  type: "omni-chat:session-error",
219
- deploymentId: options.deploymentId,
200
+ ...target.scope,
220
201
  error: failure.message,
221
202
  ...options.application ? { applicationEnabled: true } : {}
222
203
  },
223
- chatOrigin
204
+ chatOrigin2
224
205
  );
225
206
  }).finally(() => {
226
207
  pending = void 0;
@@ -236,9 +217,9 @@ function createOmniChatEmbed(container, options) {
236
217
  iframe.contentWindow?.postMessage(
237
218
  {
238
219
  type: "omni-chat:focus-composer",
239
- deploymentId: options.deploymentId
220
+ ...target.scope
240
221
  },
241
- chatOrigin
222
+ chatOrigin2
242
223
  );
243
224
  },
244
225
  destroy() {
@@ -252,49 +233,366 @@ function createOmniChatEmbed(container, options) {
252
233
  };
253
234
  }
254
235
 
255
- // src/react.tsx
236
+ // ../../lib/assistant/hosted-chat-origin.ts
237
+ function normalizeHostedChatOrigin(value) {
238
+ const url = new URL(value);
239
+ const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname === "127.0.0.1";
240
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && local) || url.username || url.password || url.pathname !== "/" || url.search || url.hash)
241
+ throw new Error("Use an HTTPS origin, or HTTP localhost for development.");
242
+ return url.origin;
243
+ }
244
+
245
+ // src/chat-origin.ts
246
+ function chatOrigin(baseUrl) {
247
+ return normalizeHostedChatOrigin(baseUrl ?? "https://omnicommerce.sg");
248
+ }
249
+
250
+ // src/application-embed.ts
251
+ function getOmniApplicationChatUrl(options, parentOrigin, chatId) {
252
+ if (!/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i.test(chatId))
253
+ throw new Error("A valid application chat ID is required.");
254
+ const url = new URL("/sdk/application-chat", chatOrigin(options.baseUrl));
255
+ const parent = chatOrigin(parentOrigin);
256
+ url.searchParams.set("parentOrigin", parent);
257
+ url.searchParams.set("chatId", chatId);
258
+ const appId = options.appId?.trim() ?? parent;
259
+ if (!appId || appId.length > 200)
260
+ throw new Error("appId must contain 1\u2013200 characters.");
261
+ url.searchParams.set("appId", appId);
262
+ for (const key of ["organizationId", "agentId"]) {
263
+ if (options[key] === void 0) continue;
264
+ const value = options[key].trim();
265
+ if (!value || value.length > 120)
266
+ throw new Error(`${key} must contain 1\u2013120 characters.`);
267
+ url.searchParams.set(key, value);
268
+ }
269
+ return url.toString();
270
+ }
271
+ function createOmniApplicationChatEmbed(container, options) {
272
+ const host = container.ownerDocument.defaultView;
273
+ if (!host) throw new Error("A browser document is required to mount chat.");
274
+ const chatId = host.crypto.randomUUID();
275
+ return mountHostedChat(container, options, {
276
+ url: getOmniApplicationChatUrl(options, host.location.origin, chatId),
277
+ scope: { chatId }
278
+ });
279
+ }
280
+
281
+ // src/embed.ts
282
+ function getOmniChatEmbedUrl(options, parentOrigin) {
283
+ if (!/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i.test(
284
+ options.deploymentId
285
+ ))
286
+ throw new Error("A valid chat deployment ID is required.");
287
+ const base = chatOrigin(options.baseUrl);
288
+ const url = new URL(`/embed/${options.deploymentId}`, base);
289
+ if (parentOrigin)
290
+ url.searchParams.set("parentOrigin", new URL(parentOrigin).origin);
291
+ return url.toString();
292
+ }
293
+ function createOmniChatEmbed(container, options) {
294
+ const host = container.ownerDocument.defaultView;
295
+ if (!host) throw new Error("A browser document is required to mount chat.");
296
+ const url = getOmniChatEmbedUrl(options, host.location.origin);
297
+ const chatOrigin2 = new URL(url).origin;
298
+ return mountHostedChat(container, options, {
299
+ url,
300
+ scope: { deploymentId: options.deploymentId },
301
+ mint: async (previousToken, visitorId, signal) => {
302
+ if (options.getSession) return options.getSession();
303
+ const response = await host.fetch(
304
+ `${chatOrigin2}/api/embed/${options.deploymentId}/session`,
305
+ {
306
+ method: "POST",
307
+ credentials: "include",
308
+ signal,
309
+ headers: {
310
+ "Content-Type": "application/json",
311
+ ...previousToken ? { Authorization: `Bearer ${previousToken}` } : {}
312
+ },
313
+ body: JSON.stringify(
314
+ visitorId && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
315
+ visitorId
316
+ ) ? { visitorId } : {}
317
+ )
318
+ }
319
+ );
320
+ const result = await response.json();
321
+ if (!response.ok)
322
+ throw new ChatSessionError(
323
+ result.error ?? "Could not open the chat session.",
324
+ response.status
325
+ );
326
+ return result;
327
+ }
328
+ });
329
+ }
330
+
331
+ // src/chat-layout.tsx
332
+ var import_react = require("react");
333
+
334
+ // src/chat-layout-styles.ts
335
+ var chatLayoutQuery = "(max-width: 959px)";
336
+ var chatLayoutStyles = `
337
+ .omni-chat-layout {
338
+ display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);
339
+ height: 100dvh; min-height: 0; min-width: 0; overflow: hidden;
340
+ }
341
+ .omni-chat-layout-content { min-height: 0; min-width: 0; overflow: auto; }
342
+ .omni-chat-layout-panel {
343
+ position: relative; inset: auto; margin: 0; padding: 0; width: 100%; height: 100%;
344
+ max-width: none; max-height: none; min-width: 0; min-height: 0; overflow: hidden;
345
+ box-sizing: border-box; border: 0; border-inline-start: 1px solid #e4e4e7;
346
+ background: white; color: #18181b;
347
+ }
348
+ .omni-chat-layout-panel[open] { display: flex; flex-direction: column; }
349
+ .omni-chat-layout-panel:not([open]) { display: none; }
350
+ .omni-chat-layout-frame { flex: 1; min-height: 0; min-width: 0; overflow: hidden; }
351
+ .omni-chat-layout-launcher, .omni-chat-layout-toolbar { display: none; }
352
+ .omni-chat-layout-launcher, .omni-chat-layout-toolbar button {
353
+ font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
354
+ }
355
+ .omni-chat-layout-launcher:focus-visible, .omni-chat-layout-toolbar button:focus-visible {
356
+ outline: 3px solid #2563eb; outline-offset: 3px;
357
+ }
358
+ @media ${chatLayoutQuery} {
359
+ .omni-chat-layout { grid-template-columns: minmax(0, 1fr); }
360
+ .omni-chat-layout-launcher {
361
+ display: flex; align-items: center; justify-content: center;
362
+ position: fixed; right: calc(20px + env(safe-area-inset-right, 0px));
363
+ bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50;
364
+ width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;
365
+ background: #18181b; color: white; box-shadow: 0 4px 16px #0003;
366
+ }
367
+ .omni-chat-layout-launcher svg { width: 24px; height: 24px; }
368
+ .omni-chat-layout-launcher[aria-expanded="true"] { visibility: hidden; }
369
+ .omni-chat-layout-panel {
370
+ position: fixed; top: var(--omni-chat-viewport-top, 0px); left: 0; right: 0;
371
+ width: 100%; height: var(--omni-chat-viewport-height, 100dvh); border: 0;
372
+ padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
373
+ env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
374
+ }
375
+ .omni-chat-layout-panel::backdrop { background: #0005; }
376
+ .omni-chat-layout-toolbar { display: flex; flex-shrink: 0; border-bottom: 1px solid #e4e4e7; }
377
+ .omni-chat-layout-toolbar button {
378
+ min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: inherit;
379
+ font-size: 14px;
380
+ }
381
+ }
382
+ `;
383
+
384
+ // src/chat-layout.tsx
256
385
  var import_jsx_runtime = require("react/jsx-runtime");
257
- var OmniChatContext = (0, import_react.createContext)(null);
386
+ var ChatLayoutCloseContext = (0, import_react.createContext)(
387
+ void 0
388
+ );
389
+ function ChatLayout({
390
+ children,
391
+ chat,
392
+ className
393
+ }) {
394
+ const panel = (0, import_react.useRef)(null);
395
+ const launcher = (0, import_react.useRef)(null);
396
+ const restoreFocus = (0, import_react.useRef)(false);
397
+ const [compact, setCompact] = (0, import_react.useState)(null);
398
+ const [open, setOpen] = (0, import_react.useState)(false);
399
+ const id = (0, import_react.useId)();
400
+ (0, import_react.useEffect)(() => {
401
+ const media = window.matchMedia(chatLayoutQuery);
402
+ const update = () => {
403
+ setCompact(media.matches);
404
+ setOpen(false);
405
+ };
406
+ update();
407
+ media.addEventListener("change", update);
408
+ return () => media.removeEventListener("change", update);
409
+ }, []);
410
+ (0, import_react.useEffect)(() => {
411
+ const dialog = panel.current;
412
+ if (!dialog || compact === null) return;
413
+ if (dialog.open) dialog.close();
414
+ if (!compact) dialog.show();
415
+ else if (open) dialog.showModal();
416
+ else if (restoreFocus.current) launcher.current?.focus();
417
+ restoreFocus.current = false;
418
+ }, [compact, open]);
419
+ (0, import_react.useEffect)(() => {
420
+ const viewport = window.visualViewport;
421
+ const dialog = panel.current;
422
+ const resize = () => {
423
+ if (compact && open && viewport?.scale === 1) {
424
+ dialog.style.setProperty(
425
+ "--omni-chat-viewport-top",
426
+ `${viewport.offsetTop}px`
427
+ );
428
+ dialog.style.setProperty(
429
+ "--omni-chat-viewport-height",
430
+ `${viewport.height}px`
431
+ );
432
+ } else {
433
+ dialog.style.removeProperty("--omni-chat-viewport-top");
434
+ dialog.style.removeProperty("--omni-chat-viewport-height");
435
+ }
436
+ };
437
+ resize();
438
+ viewport?.addEventListener("resize", resize);
439
+ viewport?.addEventListener("scroll", resize);
440
+ return () => {
441
+ viewport?.removeEventListener("resize", resize);
442
+ viewport?.removeEventListener("scroll", resize);
443
+ };
444
+ }, [compact, open]);
445
+ const close = () => {
446
+ if (!compact) return;
447
+ restoreFocus.current = true;
448
+ setOpen(false);
449
+ };
450
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: ["omni-chat-layout", className].filter(Boolean).join(" "), children: [
451
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: chatLayoutStyles }),
452
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "omni-chat-layout-content", children }),
453
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
454
+ "button",
455
+ {
456
+ ref: launcher,
457
+ type: "button",
458
+ className: "omni-chat-layout-launcher",
459
+ "aria-label": "Open assistant",
460
+ "aria-controls": id,
461
+ "aria-expanded": compact === true && open,
462
+ onClick: () => setOpen(true),
463
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
464
+ "svg",
465
+ {
466
+ viewBox: "0 0 24 24",
467
+ fill: "none",
468
+ stroke: "currentColor",
469
+ strokeWidth: "1.8",
470
+ "aria-hidden": "true",
471
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
472
+ "path",
473
+ {
474
+ strokeLinecap: "round",
475
+ strokeLinejoin: "round",
476
+ d: "M21 11.5a8.5 8.5 0 0 1-12.3 7.6L3 21l1.9-5.7A8.5 8.5 0 1 1 21 11.5Z"
477
+ }
478
+ )
479
+ }
480
+ )
481
+ }
482
+ ),
483
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
484
+ "dialog",
485
+ {
486
+ ref: panel,
487
+ id,
488
+ className: "omni-chat-layout-panel",
489
+ "aria-label": "Application assistant",
490
+ onCancel: (event) => {
491
+ event.preventDefault();
492
+ close();
493
+ },
494
+ children: [
495
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "omni-chat-layout-toolbar", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: close, children: "\u2190 Back to application" }) }),
496
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "omni-chat-layout-frame", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChatLayoutCloseContext.Provider, { value: close, children: chat }) })
497
+ ]
498
+ }
499
+ )
500
+ ] });
501
+ }
502
+
503
+ // src/react.tsx
504
+ var import_jsx_runtime2 = require("react/jsx-runtime");
505
+ var OmniChatContext = (0, import_react2.createContext)(null);
258
506
  function OmniProvider({ children, ...options }) {
259
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OmniChatContext.Provider, { value: options, children });
507
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OmniChatContext.Provider, { value: options, children });
260
508
  }
261
- function OmniChat({ className, style, title }) {
262
- const options = (0, import_react.useContext)(OmniChatContext);
509
+ function OmniChatLayout({
510
+ children,
511
+ className,
512
+ title
513
+ }) {
514
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
515
+ ChatLayout,
516
+ {
517
+ className,
518
+ chat: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OmniChat, { title, style: { minHeight: 0 } }),
519
+ children
520
+ }
521
+ );
522
+ }
523
+ function OmniChat({
524
+ className,
525
+ style,
526
+ title,
527
+ onRequestClose
528
+ }) {
529
+ const options = (0, import_react2.useContext)(OmniChatContext);
530
+ const closeLayout = (0, import_react2.useContext)(ChatLayoutCloseContext);
263
531
  if (!options)
264
532
  throw new Error("OmniChat must be rendered inside OmniProvider.");
265
- const container = (0, import_react.useRef)(null);
266
- const {
267
- baseUrl,
268
- deploymentId,
533
+ const container = (0, import_react2.useRef)(null);
534
+ const frame = (0, import_react2.useRef)(null);
535
+ const { baseUrl, deploymentId, onError, application, frontendTools } = options;
536
+ const getSession = "getSession" in options ? options.getSession : void 0;
537
+ const { organizationId, agentId, appId } = options;
538
+ const requestClose = onRequestClose ?? closeLayout ?? options.onRequestClose;
539
+ const callbacks = (0, import_react2.useRef)({
269
540
  getSession,
270
541
  onError,
271
542
  application,
272
- frontendTools
273
- } = options;
274
- const callbacks = (0, import_react.useRef)({ getSession, onError, application, frontendTools });
275
- (0, import_react.useEffect)(() => {
276
- callbacks.current = { getSession, onError, application, frontendTools };
277
- }, [getSession, onError, application, frontendTools]);
543
+ frontendTools,
544
+ requestClose
545
+ });
546
+ (0, import_react2.useEffect)(() => {
547
+ callbacks.current = {
548
+ getSession,
549
+ onError,
550
+ application,
551
+ frontendTools,
552
+ requestClose
553
+ };
554
+ }, [getSession, onError, application, frontendTools, requestClose]);
278
555
  const hasSessionBroker = Boolean(getSession);
279
556
  const frameTitle = title ?? options.title;
280
- (0, import_react.useEffect)(() => {
557
+ (0, import_react2.useEffect)(() => {
281
558
  if (!container.current) return;
282
- const embed = createOmniChatEmbed(container.current, {
559
+ const hostedOptions = {
283
560
  baseUrl,
284
- deploymentId,
285
- getSession: hasSessionBroker ? () => callbacks.current.getSession() : void 0,
286
561
  onError: (error) => callbacks.current.onError?.(error),
562
+ onRequestClose: () => callbacks.current.requestClose?.(),
287
563
  title: frameTitle,
564
+ ...deploymentId ? {
565
+ deploymentId,
566
+ getSession: hasSessionBroker ? () => callbacks.current.getSession() : void 0
567
+ } : { organizationId, agentId, appId },
288
568
  get application() {
289
569
  return callbacks.current.application;
290
570
  },
291
571
  get frontendTools() {
292
572
  return callbacks.current.frontendTools;
293
573
  }
294
- });
295
- return () => embed.destroy();
296
- }, [baseUrl, deploymentId, frameTitle, hasSessionBroker]);
297
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
574
+ };
575
+ const embed = "deploymentId" in hostedOptions ? createOmniChatEmbed(container.current, hostedOptions) : createOmniApplicationChatEmbed(container.current, hostedOptions);
576
+ frame.current = embed.iframe;
577
+ return () => {
578
+ frame.current = null;
579
+ embed.destroy();
580
+ };
581
+ }, [
582
+ baseUrl,
583
+ deploymentId,
584
+ organizationId,
585
+ agentId,
586
+ appId,
587
+ frameTitle,
588
+ hasSessionBroker
589
+ ]);
590
+ (0, import_react2.useEffect)(() => {
591
+ const minimum = style?.minHeight ?? 320;
592
+ if (frame.current)
593
+ frame.current.style.minHeight = typeof minimum === "number" ? `${minimum}px` : minimum;
594
+ });
595
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
298
596
  "div",
299
597
  {
300
598
  ref: container,
@@ -306,6 +604,7 @@ function OmniChat({ className, style, title }) {
306
604
  // Annotate the CommonJS export names for ESM import in node:
307
605
  0 && (module.exports = {
308
606
  OmniChat,
607
+ OmniChatLayout,
309
608
  OmniProvider
310
609
  });
311
610
  //# sourceMappingURL=react.cjs.map