@matterfact/embed 0.16.0 → 0.17.0

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.d.cts CHANGED
@@ -295,6 +295,15 @@ interface MatterfactAgentProps {
295
295
  widgetOrigin?: string;
296
296
  /** Label for THIS embedding, for per-surface usage/history attribution. */
297
297
  surface?: string;
298
+ /**
299
+ * Host-site share-link template. When set, "Share chat" links are minted in this
300
+ * format (`{share_token}` is replaced), and when this page is loaded at a URL
301
+ * matching the template the widget auto-opens that shared conversation.
302
+ * Exactly one `{share_token}`, as a whole path segment or whole query value,
303
+ * e.g. "https://portal.acme.com/assistant?mf_share={share_token}".
304
+ * Read at mount; change requires a remount.
305
+ */
306
+ shareDeeplinkFormat?: string;
298
307
  /** Resolved as `prop ?? MatterfactAuthProvider's theme ?? 'auto'`. */
299
308
  theme?: 'light' | 'dark' | 'auto';
300
309
  /**
@@ -409,7 +418,7 @@ interface MatterfactAgentProps {
409
418
  */
410
419
  onEvent?: (e: MatterfactEvent) => void;
411
420
  }
412
- declare function MatterfactAgent({ publishableKey: publishableKeyProp, widgetOrigin: widgetOriginProp, surface, theme: themeProp, getAuthToken: getAuthTokenProp, getPageContext, inline, className, style, pageContext, dev, actions, sitemap, artifacts, resolve, tools, onToolEvent, onEvent, }: MatterfactAgentProps): react_jsx_runtime.JSX.Element | null;
421
+ declare function MatterfactAgent({ publishableKey: publishableKeyProp, widgetOrigin: widgetOriginProp, surface, shareDeeplinkFormat, theme: themeProp, getAuthToken: getAuthTokenProp, getPageContext, inline, className, style, pageContext, dev, actions, sitemap, artifacts, resolve, tools, onToolEvent, onEvent, }: MatterfactAgentProps): react_jsx_runtime.JSX.Element | null;
413
422
  interface MatterfactArtifactProps {
414
423
  /** The artifact's name (its slug). */
415
424
  name?: string;
@@ -476,12 +485,15 @@ interface MatterfactArtifactProps {
476
485
  * MatterfactAgent is embedded on the same page, the loader sees this iframe and both
477
486
  * makes the agent aware of it and (via its token) lets the agent read its data.
478
487
  *
479
- * Two auth modes, `token` wins when both are available:
480
- * - TOKEN mode (`token` given): a standalone share link, `?t=`. This is the LIVE
481
- * third-party embed path its `src` format must stay byte-identical.
482
- * - SESSION mode (no `token`, an ancestor `MatterfactAuthProvider` is present):
483
- * tokenless, `?k=<publishableKey>&o=<host origin>`, the same authentication
484
- * `MatterfactAgent` uses.
488
+ * Two auth modes; a provider wins when both are available:
489
+ * - SESSION mode (an ancestor `MatterfactAuthProvider` is present): tokenless,
490
+ * `?k=<publishableKey>&o=<host origin>`, the same authentication
491
+ * `MatterfactAgent` uses. Chosen even when a `token` is ALSO given — with an
492
+ * identity the embed should read as the signed-in user, and it spares the
493
+ * host from stripping a legacy token to get session auth.
494
+ * - TOKEN mode (`token` given, no provider): a standalone share link, `?t=`.
495
+ * This is the LIVE third-party embed path — its `src` format must stay
496
+ * byte-identical.
485
497
  * With neither, there is no way for the iframe to authenticate, so no iframe is
486
498
  * built at all — matching the "incomplete link" placeholder the embed artifact
487
499
  * page itself renders for a missing owner/token.
package/dist/react.d.ts CHANGED
@@ -295,6 +295,15 @@ interface MatterfactAgentProps {
295
295
  widgetOrigin?: string;
296
296
  /** Label for THIS embedding, for per-surface usage/history attribution. */
297
297
  surface?: string;
298
+ /**
299
+ * Host-site share-link template. When set, "Share chat" links are minted in this
300
+ * format (`{share_token}` is replaced), and when this page is loaded at a URL
301
+ * matching the template the widget auto-opens that shared conversation.
302
+ * Exactly one `{share_token}`, as a whole path segment or whole query value,
303
+ * e.g. "https://portal.acme.com/assistant?mf_share={share_token}".
304
+ * Read at mount; change requires a remount.
305
+ */
306
+ shareDeeplinkFormat?: string;
298
307
  /** Resolved as `prop ?? MatterfactAuthProvider's theme ?? 'auto'`. */
299
308
  theme?: 'light' | 'dark' | 'auto';
300
309
  /**
@@ -409,7 +418,7 @@ interface MatterfactAgentProps {
409
418
  */
410
419
  onEvent?: (e: MatterfactEvent) => void;
411
420
  }
412
- declare function MatterfactAgent({ publishableKey: publishableKeyProp, widgetOrigin: widgetOriginProp, surface, theme: themeProp, getAuthToken: getAuthTokenProp, getPageContext, inline, className, style, pageContext, dev, actions, sitemap, artifacts, resolve, tools, onToolEvent, onEvent, }: MatterfactAgentProps): react_jsx_runtime.JSX.Element | null;
421
+ declare function MatterfactAgent({ publishableKey: publishableKeyProp, widgetOrigin: widgetOriginProp, surface, shareDeeplinkFormat, theme: themeProp, getAuthToken: getAuthTokenProp, getPageContext, inline, className, style, pageContext, dev, actions, sitemap, artifacts, resolve, tools, onToolEvent, onEvent, }: MatterfactAgentProps): react_jsx_runtime.JSX.Element | null;
413
422
  interface MatterfactArtifactProps {
414
423
  /** The artifact's name (its slug). */
415
424
  name?: string;
@@ -476,12 +485,15 @@ interface MatterfactArtifactProps {
476
485
  * MatterfactAgent is embedded on the same page, the loader sees this iframe and both
477
486
  * makes the agent aware of it and (via its token) lets the agent read its data.
478
487
  *
479
- * Two auth modes, `token` wins when both are available:
480
- * - TOKEN mode (`token` given): a standalone share link, `?t=`. This is the LIVE
481
- * third-party embed path its `src` format must stay byte-identical.
482
- * - SESSION mode (no `token`, an ancestor `MatterfactAuthProvider` is present):
483
- * tokenless, `?k=<publishableKey>&o=<host origin>`, the same authentication
484
- * `MatterfactAgent` uses.
488
+ * Two auth modes; a provider wins when both are available:
489
+ * - SESSION mode (an ancestor `MatterfactAuthProvider` is present): tokenless,
490
+ * `?k=<publishableKey>&o=<host origin>`, the same authentication
491
+ * `MatterfactAgent` uses. Chosen even when a `token` is ALSO given — with an
492
+ * identity the embed should read as the signed-in user, and it spares the
493
+ * host from stripping a legacy token to get session auth.
494
+ * - TOKEN mode (`token` given, no provider): a standalone share link, `?t=`.
495
+ * This is the LIVE third-party embed path — its `src` format must stay
496
+ * byte-identical.
485
497
  * With neither, there is no way for the iframe to authenticate, so no iframe is
486
498
  * built at all — matching the "incomplete link" placeholder the embed artifact
487
499
  * page itself renders for a missing owner/token.
package/dist/react.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import { useCallback, useEffect as useEffect2, useRef } from "react";
6
6
 
7
7
  // src/protocol.ts
8
- var PROTOCOL_VERSION = 3;
8
+ var PROTOCOL_VERSION = 4;
9
9
  var CHANNEL = "mf-embed";
10
10
  function envelope(payload, id) {
11
11
  return {
@@ -227,6 +227,7 @@ function dockBox(g, vw, _vh) {
227
227
  }
228
228
 
229
229
  // src/loader.ts
230
+ var EMBED_VERSION = "0.17.0";
230
231
  function devRequested() {
231
232
  try {
232
233
  if (new URLSearchParams(location.search).get("mfdev") === "1") return true;
@@ -314,6 +315,8 @@ var EmbedHost = class {
314
315
  this.inline = !!config.container;
315
316
  }
316
317
  mount() {
318
+ const w = window;
319
+ (w.matterfact ?? (w.matterfact = {})).embedVersion = EMBED_VERSION;
317
320
  const host = document.createElement("div");
318
321
  this.hostEl = host;
319
322
  host.id = "matterfact-embed";
@@ -357,7 +360,7 @@ var EmbedHost = class {
357
360
  "sandbox",
358
361
  "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-downloads"
359
362
  );
360
- iframe.setAttribute("allow", "microphone; clipboard-write");
363
+ iframe.setAttribute("allow", "microphone; clipboard-write; web-share");
361
364
  iframe.src = `${this.config.origin}/embed/chat?k=${encodeURIComponent(
362
365
  this.config.publishableKey
363
366
  )}&o=${encodeURIComponent(location.origin)}` + (this.config.surface ? `&s=${encodeURIComponent(this.config.surface)}` : "") + // Either trigger works: the URL param (no redeploy needed) OR the config's
@@ -370,6 +373,17 @@ var EmbedHost = class {
370
373
  window.addEventListener("resize", this.onViewportResize);
371
374
  this.place();
372
375
  }
376
+ const fmt = this.config.shareDeeplinkFormat;
377
+ if (fmt) {
378
+ this.send({ type: "host.deeplinkFormat", format: fmt });
379
+ void import("./deeplink-IBFUWANV.js").then((m) => {
380
+ if (this.destroyed) return;
381
+ this.deeplinkStop = m.installDeeplinkWatch(fmt, (token) => {
382
+ this.send({ type: "host.openShare", token });
383
+ });
384
+ }).catch(() => {
385
+ });
386
+ }
373
387
  }
374
388
  /**
375
389
  * Test seam. The shadow root is CLOSED, so a test cannot reach the iframe to forge a
@@ -793,6 +807,9 @@ var EmbedHost = class {
793
807
  this.iframe = null;
794
808
  this.shadow = null;
795
809
  this.ready = false;
810
+ this.destroyed = true;
811
+ this.deeplinkStop?.();
812
+ this.deeplinkStop = null;
796
813
  void this.context?.then((m) => m.stop());
797
814
  }
798
815
  };
@@ -909,6 +926,7 @@ function MatterfactAgent({
909
926
  publishableKey: publishableKeyProp,
910
927
  widgetOrigin: widgetOriginProp,
911
928
  surface = "",
929
+ shareDeeplinkFormat,
912
930
  theme: themeProp,
913
931
  getAuthToken: getAuthTokenProp,
914
932
  getPageContext,
@@ -970,7 +988,8 @@ function MatterfactAgent({
970
988
  pageContextProvider: async () => await pageContextRef.current?.() ?? null,
971
989
  container: inline ? slot.current : null,
972
990
  pageContext,
973
- dev
991
+ dev,
992
+ shareDeeplinkFormat
974
993
  };
975
994
  let host = null;
976
995
  try {
@@ -990,6 +1009,7 @@ function MatterfactAgent({
990
1009
  publishableKey,
991
1010
  widgetOrigin,
992
1011
  surface,
1012
+ shareDeeplinkFormat,
993
1013
  theme,
994
1014
  inline,
995
1015
  pageContext,
@@ -1100,11 +1120,11 @@ function MatterfactArtifact({
1100
1120
  post(changed);
1101
1121
  }, [paramsKey, post]);
1102
1122
  let src;
1103
- if (token) {
1104
- src = `${origin}/embed/artifacts/${encodeURIComponent(artifactName)}?owner=${encodeURIComponent(owner)}&t=${encodeURIComponent(token)}&theme=${theme}`;
1105
- } else if (ctx) {
1123
+ if (ctx) {
1106
1124
  const hostOrigin = typeof window === "undefined" ? "" : window.location.origin;
1107
1125
  src = `${origin}/embed/artifacts/${encodeURIComponent(artifactName)}?owner=${encodeURIComponent(owner)}&k=${encodeURIComponent(ctx.publishableKey)}&o=${encodeURIComponent(hostOrigin)}&theme=${theme}`;
1126
+ } else if (token) {
1127
+ src = `${origin}/embed/artifacts/${encodeURIComponent(artifactName)}?owner=${encodeURIComponent(owner)}&t=${encodeURIComponent(token)}&theme=${theme}`;
1108
1128
  } else {
1109
1129
  return /* @__PURE__ */ jsx2(
1110
1130
  "div",