@eshal-bot/chat-widget 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- export{S as default}from"./chat-widget-index-D45VhRbc.esm.js";import"react";import"react-dom/client";import"react-dom";import"react/jsx-runtime";
1
+ export{S as default}from"./chat-widget-index-C9e7Y35o.esm.js";import"react";import"react-dom/client";import"react/jsx-runtime";import"react-dom";
@@ -14560,59 +14560,45 @@
14560
14560
  return typeof u === 'string' && /^https?:\/\//i.test(u) ? u : undefined;
14561
14561
  }
14562
14562
 
14563
- var jsxRuntime = {exports: {}};
14564
-
14565
- var reactJsxRuntime_production_min = {};
14566
-
14567
14563
  /**
14568
- * @license React
14569
- * react-jsx-runtime.production.min.js
14564
+ * WidgetCitationContext - the message's `sources` array + download handler,
14565
+ * supplied by `<MessageBubble>` and consumed by every `<CitationPill>` that
14566
+ * `rehypeCitations` renders inside the ReactMarkdown output.
14570
14567
  *
14571
- * Copyright (c) Facebook, Inc. and its affiliates.
14568
+ * EV-2904 - WHY THIS LIVES IN ITS OWN MODULE, BEHIND A GLOBAL SINGLETON
14569
+ * ---------------------------------------------------------------------
14570
+ * The vanilla/IIFE build (`chat-widget.min.js` - the `<script src=...>`
14571
+ * snippet customers actually install) ships the markdown pipeline as a
14572
+ * SEPARATE IIFE bundle, `chat-widget-markdown-chunk.min.js`, injected at
14573
+ * runtime by vanilla/lazyChunkLoader.js. Per rollup.config.js, `react` is
14574
+ * the ONLY module the two bundles share (via the `__eshalChatWidgetReact`
14575
+ * global) - every other module, including this one, is bundled a SECOND
14576
+ * time into the chunk.
14572
14577
  *
14573
- * This source code is licensed under the MIT license found in the
14574
- * LICENSE file in the root directory of this source tree.
14578
+ * The provider (`MessageBubble.jsx`) lives in the main bundle; the consumer
14579
+ * (`CitationPill.jsx`) is pulled in by `MarkdownRenderer.jsx` and therefore
14580
+ * lives in the chunk. With a plain `createContext(null)` in each bundle,
14581
+ * those are two DIFFERENT context objects: the pill's `useContext` finds no
14582
+ * matching Provider above it, falls back to the default `null`, and
14583
+ * `CitationPill` returns `null` (its "rendered outside a chat" guard). The
14584
+ * result is that citations silently vanish on the installed widget - no
14585
+ * error, no raw `[N]` leak - while the Testing Lab and the ESM/UMD builds
14586
+ * (single module graph) render them fine.
14587
+ *
14588
+ * Stashing the context object on a `window` key makes it a true
14589
+ * cross-bundle singleton: whichever bundle evaluates first creates it, the
14590
+ * other reuses it, so provider and consumer always agree. Safe for the
14591
+ * single-graph builds too - the second import just re-reads the same
14592
+ * object, which is exactly what a plain module-level `createContext` did.
14593
+ *
14594
+ * `createContext` must come from the one shared React instance for hooks to
14595
+ * work at all; rollup.config.js already guarantees that via the
14596
+ * `__eshalChatWidgetReact` global, so the object created here is valid in
14597
+ * both bundles.
14575
14598
  */
14576
- var f = reactExports,
14577
- k = Symbol.for("react.element"),
14578
- l = Symbol.for("react.fragment"),
14579
- m = Object.prototype.hasOwnProperty,
14580
- n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
14581
- p = {
14582
- key: true,
14583
- ref: true,
14584
- __self: true,
14585
- __source: true
14586
- };
14587
- function q(c, a, g) {
14588
- var b,
14589
- d = {},
14590
- e = null,
14591
- h = null;
14592
- void 0 !== g && (e = "" + g);
14593
- void 0 !== a.key && (e = "" + a.key);
14594
- void 0 !== a.ref && (h = a.ref);
14595
- for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
14596
- if (c && c.defaultProps) for (b in a = c.defaultProps, a) void 0 === d[b] && (d[b] = a[b]);
14597
- return {
14598
- $$typeof: k,
14599
- type: c,
14600
- key: e,
14601
- ref: h,
14602
- props: d,
14603
- _owner: n.current
14604
- };
14605
- }
14606
- reactJsxRuntime_production_min.Fragment = l;
14607
- reactJsxRuntime_production_min.jsx = q;
14608
- reactJsxRuntime_production_min.jsxs = q;
14609
-
14610
- {
14611
- jsxRuntime.exports = reactJsxRuntime_production_min;
14612
- }
14613
- var jsxRuntimeExports = jsxRuntime.exports;
14614
-
14615
- const WidgetCitationContext = /*#__PURE__*/reactExports.createContext(null);
14599
+ const GLOBAL_KEY = "__eshalChatWidgetCitationContext";
14600
+ const globalScope = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : undefined;
14601
+ const WidgetCitationContext = globalScope ? globalScope[GLOBAL_KEY] || (globalScope[GLOBAL_KEY] = /*#__PURE__*/reactExports.createContext(null)) : /*#__PURE__*/reactExports.createContext(null);
14616
14602
 
14617
14603
  var _document$currentScri;
14618
14604
  // Runtime loader for the lazy markdown/chart chunk in the vanilla/IIFE
@@ -14687,6 +14673,58 @@
14687
14673
  return loadMarkdownRendererChunk();
14688
14674
  }
14689
14675
 
14676
+ var jsxRuntime = {exports: {}};
14677
+
14678
+ var reactJsxRuntime_production_min = {};
14679
+
14680
+ /**
14681
+ * @license React
14682
+ * react-jsx-runtime.production.min.js
14683
+ *
14684
+ * Copyright (c) Facebook, Inc. and its affiliates.
14685
+ *
14686
+ * This source code is licensed under the MIT license found in the
14687
+ * LICENSE file in the root directory of this source tree.
14688
+ */
14689
+ var f = reactExports,
14690
+ k = Symbol.for("react.element"),
14691
+ l = Symbol.for("react.fragment"),
14692
+ m = Object.prototype.hasOwnProperty,
14693
+ n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
14694
+ p = {
14695
+ key: true,
14696
+ ref: true,
14697
+ __self: true,
14698
+ __source: true
14699
+ };
14700
+ function q(c, a, g) {
14701
+ var b,
14702
+ d = {},
14703
+ e = null,
14704
+ h = null;
14705
+ void 0 !== g && (e = "" + g);
14706
+ void 0 !== a.key && (e = "" + a.key);
14707
+ void 0 !== a.ref && (h = a.ref);
14708
+ for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
14709
+ if (c && c.defaultProps) for (b in a = c.defaultProps, a) void 0 === d[b] && (d[b] = a[b]);
14710
+ return {
14711
+ $$typeof: k,
14712
+ type: c,
14713
+ key: e,
14714
+ ref: h,
14715
+ props: d,
14716
+ _owner: n.current
14717
+ };
14718
+ }
14719
+ reactJsxRuntime_production_min.Fragment = l;
14720
+ reactJsxRuntime_production_min.jsx = q;
14721
+ reactJsxRuntime_production_min.jsxs = q;
14722
+
14723
+ {
14724
+ jsxRuntime.exports = reactJsxRuntime_production_min;
14725
+ }
14726
+ var jsxRuntimeExports = jsxRuntime.exports;
14727
+
14690
14728
  const MarkdownRenderer = /*#__PURE__*/reactExports.lazy(loadMarkdownRenderer);
14691
14729
 
14692
14730
  // The IIFE build's chunk loader does a real network fetch for a sibling
@@ -20406,6 +20444,25 @@
20406
20444
  });
20407
20445
  ToggleButton.displayName = "ToggleButton";
20408
20446
 
20447
+ /**
20448
+ * version.js - the widget's own version, reported to Eshal on mount.
20449
+ *
20450
+ * Deliberately a plain string literal rather than a build-time define
20451
+ * (`@rollup/plugin-replace` / Vite `define`). The widget ships as four
20452
+ * different bundles (ESM, UMD, IIFE embed, plus the Vite dev server) and is
20453
+ * also re-bundled by consumers who apply none of our build config - a define
20454
+ * would resolve to `undefined` in exactly those paths, and a bare reference
20455
+ * to an undeclared identifier is a hard ReferenceError that takes the whole
20456
+ * widget down. A literal survives every one of them.
20457
+ *
20458
+ * The cost is that this must be bumped alongside package.json. That drift is
20459
+ * not left to discipline: __tests__/version.test.js fails CI if the two ever
20460
+ * disagree, and packages/frontend's CDN_WIDGET_VERSION is held to the same
20461
+ * value by its own test (that constant sat at 0.1.113 while this package was
20462
+ * at 0.2.2 precisely because nothing enforced it - EV-2431).
20463
+ */
20464
+ const WIDGET_VERSION = '0.2.3';
20465
+
20409
20466
  const createSession = async config => {
20410
20467
  // Initialize chat session if needed
20411
20468
  if (config.sessionUrl) {
@@ -20449,7 +20506,7 @@
20449
20506
  }
20450
20507
  try {
20451
20508
  const base = apiBaseUrl.replace(/\/$/, '');
20452
- const url = "".concat(base, "/api/v1/deploy-agent");
20509
+ const url = WIDGET_VERSION ? "".concat(base, "/api/v1/deploy-agent?wv=").concat(encodeURIComponent(WIDGET_VERSION)) : "".concat(base, "/api/v1/deploy-agent");
20453
20510
  const headers = {
20454
20511
  "Content-Type": "application/json"
20455
20512
  };
@@ -21357,6 +21414,7 @@
21357
21414
  // Auto-initialize if config exists in window
21358
21415
  if (typeof window !== 'undefined') {
21359
21416
  window.ChatWidget = API;
21417
+ window.ChatWidget.version = WIDGET_VERSION;
21360
21418
 
21361
21419
  // Auto-init with window.ChatWidgetConfig
21362
21420
  if (window.ChatWidgetConfig) {