@matterfact/embed 0.11.2 → 0.12.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/README.md +7 -4
- package/dist/{chunk-AANODHBV.js → chunk-C4XGE6BO.js} +71 -42
- package/dist/chunk-C4XGE6BO.js.map +1 -0
- package/dist/chunk-M5TS546Z.js +2 -0
- package/dist/chunk-SR4ZNUAN.js +3 -0
- package/dist/chunk-SR4ZNUAN.js.map +7 -0
- package/dist/{chunk-JO3GWFMJ.js → chunk-WAUSVV7Y.js} +2 -2
- package/dist/{chunk-CTZEDOH7.js → chunk-ZXMJWCQV.js} +72 -44
- package/dist/chunk-ZXMJWCQV.js.map +1 -0
- package/dist/{context-FR7VFENN.js → context-4LP3EDXL.js} +3 -3
- package/dist/{context-FR7VFENN.js.map → context-4LP3EDXL.js.map} +1 -1
- package/dist/{context-IK5MECUW.js → context-ZSPDZWIB.js} +4 -2
- package/dist/embed.js +1 -1
- package/dist/embed.js.map +3 -3
- package/dist/index.cjs +110 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +35 -6
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +102 -45
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +26 -5
- package/dist/react.js.map +1 -1
- package/dist/{snapshot-2V5SDSH2.js → snapshot-OR5SVEUD.js} +2 -2
- package/dist/{snapshot-Y5BF2UJR.js → snapshot-X6FPP3HF.js} +3 -3
- package/dist/{snapshot-Y5BF2UJR.js.map → snapshot-X6FPP3HF.js.map} +1 -1
- package/examples/embed-demo/.env.example +7 -3
- package/examples/embed-demo/README.md +25 -4
- package/examples/embed-demo/src/App.tsx +67 -7
- package/examples/embed-demo/src/styles.css +52 -0
- package/examples/embed-demo/vite.config.ts +3 -2
- package/package.json +1 -1
- package/dist/chunk-AANODHBV.js.map +0 -1
- package/dist/chunk-CTZEDOH7.js.map +0 -1
- package/dist/chunk-SKJFF7RD.js +0 -2
- package/dist/chunk-Y7I25VHL.js +0 -3
- package/dist/chunk-Y7I25VHL.js.map +0 -7
- /package/dist/{chunk-SKJFF7RD.js.map → chunk-M5TS546Z.js.map} +0 -0
- /package/dist/{chunk-JO3GWFMJ.js.map → chunk-WAUSVV7Y.js.map} +0 -0
- /package/dist/{context-IK5MECUW.js.map → context-ZSPDZWIB.js.map} +0 -0
- /package/dist/{snapshot-2V5SDSH2.js.map → snapshot-OR5SVEUD.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -370,6 +370,13 @@ type WidgetToHost = {
|
|
|
370
370
|
| {
|
|
371
371
|
type: 'widget.requestContext';
|
|
372
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Admin max page-context mode from bootstrap — host clamps observation to this.
|
|
375
|
+
*/
|
|
376
|
+
| {
|
|
377
|
+
type: 'widget.pageContextMax';
|
|
378
|
+
mode: 'full' | 'declared' | 'off';
|
|
379
|
+
}
|
|
373
380
|
/** Zoom in: the a11y sub-tree under one ref (a table, a form, a card the agent cares about). */
|
|
374
381
|
| {
|
|
375
382
|
type: 'widget.readRegion';
|
|
@@ -523,9 +530,9 @@ type PageContextProvider = () => PageContext | null | undefined | Promise<PageCo
|
|
|
523
530
|
/**
|
|
524
531
|
* The matterfact embed loader.
|
|
525
532
|
*
|
|
526
|
-
* <script src="https://
|
|
533
|
+
* <script type="module" src="https://app.matterfact.com/embed/embed.js"
|
|
527
534
|
* data-key="pk_live_acme_..."
|
|
528
|
-
*
|
|
535
|
+
* data-origin="https://app.matterfact.com"></script>
|
|
529
536
|
*
|
|
530
537
|
* This file runs on EVERY page load of a customer's site, so it is deliberately
|
|
531
538
|
* tiny and deliberately dumb:
|
|
@@ -590,15 +597,10 @@ interface LoaderConfig {
|
|
|
590
597
|
*/
|
|
591
598
|
container?: HTMLElement | null;
|
|
592
599
|
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
* gets sent: when this is false the loader never installs the DOM/nav/focus/activity
|
|
596
|
-
* observers in the first place, and an inbound `widget.requestSnapshot` is ignored
|
|
597
|
-
* rather than answered. Default `true` — seeing the page is the widget's whole value
|
|
598
|
-
* proposition; this is the escape hatch for a host that wants agent chat with nothing
|
|
599
|
-
* about the page ever reaching it.
|
|
600
|
+
* Page observation mode: `full` (default / `true`), `declared` (getPageContext +
|
|
601
|
+
* host sitemap only), or `off` (`false`). Auto DOM/focus/activity require `full`.
|
|
600
602
|
*/
|
|
601
|
-
pageContext?: boolean;
|
|
603
|
+
pageContext?: boolean | 'full' | 'declared' | 'off';
|
|
602
604
|
/**
|
|
603
605
|
* Force dev mode (see `devRequested()` below) without needing `?mfdev=1` on the host
|
|
604
606
|
* URL. This is the programmatic equivalent of that trigger, not a replacement for it —
|
package/dist/index.d.ts
CHANGED
|
@@ -370,6 +370,13 @@ type WidgetToHost = {
|
|
|
370
370
|
| {
|
|
371
371
|
type: 'widget.requestContext';
|
|
372
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Admin max page-context mode from bootstrap — host clamps observation to this.
|
|
375
|
+
*/
|
|
376
|
+
| {
|
|
377
|
+
type: 'widget.pageContextMax';
|
|
378
|
+
mode: 'full' | 'declared' | 'off';
|
|
379
|
+
}
|
|
373
380
|
/** Zoom in: the a11y sub-tree under one ref (a table, a form, a card the agent cares about). */
|
|
374
381
|
| {
|
|
375
382
|
type: 'widget.readRegion';
|
|
@@ -523,9 +530,9 @@ type PageContextProvider = () => PageContext | null | undefined | Promise<PageCo
|
|
|
523
530
|
/**
|
|
524
531
|
* The matterfact embed loader.
|
|
525
532
|
*
|
|
526
|
-
* <script src="https://
|
|
533
|
+
* <script type="module" src="https://app.matterfact.com/embed/embed.js"
|
|
527
534
|
* data-key="pk_live_acme_..."
|
|
528
|
-
*
|
|
535
|
+
* data-origin="https://app.matterfact.com"></script>
|
|
529
536
|
*
|
|
530
537
|
* This file runs on EVERY page load of a customer's site, so it is deliberately
|
|
531
538
|
* tiny and deliberately dumb:
|
|
@@ -590,15 +597,10 @@ interface LoaderConfig {
|
|
|
590
597
|
*/
|
|
591
598
|
container?: HTMLElement | null;
|
|
592
599
|
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
* gets sent: when this is false the loader never installs the DOM/nav/focus/activity
|
|
596
|
-
* observers in the first place, and an inbound `widget.requestSnapshot` is ignored
|
|
597
|
-
* rather than answered. Default `true` — seeing the page is the widget's whole value
|
|
598
|
-
* proposition; this is the escape hatch for a host that wants agent chat with nothing
|
|
599
|
-
* about the page ever reaching it.
|
|
600
|
+
* Page observation mode: `full` (default / `true`), `declared` (getPageContext +
|
|
601
|
+
* host sitemap only), or `off` (`false`). Auto DOM/focus/activity require `full`.
|
|
600
602
|
*/
|
|
601
|
-
pageContext?: boolean;
|
|
603
|
+
pageContext?: boolean | 'full' | 'declared' | 'off';
|
|
602
604
|
/**
|
|
603
605
|
* Force dev mode (see `devRequested()` below) without needing `?mfdev=1` on the host
|
|
604
606
|
* URL. This is the programmatic equivalent of that trigger, not a replacement for it —
|
package/dist/index.js
CHANGED
|
@@ -224,11 +224,19 @@ function dockBox(g, vw, _vh) {
|
|
|
224
224
|
var DEFAULT_ORIGIN = "https://app.matterfact.com";
|
|
225
225
|
function devRequested() {
|
|
226
226
|
try {
|
|
227
|
-
|
|
227
|
+
if (new URLSearchParams(location.search).get("mfdev") === "1") return true;
|
|
228
|
+
try {
|
|
229
|
+
return localStorage.getItem("mfdev") === "1";
|
|
230
|
+
} catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
228
233
|
} catch {
|
|
229
234
|
return false;
|
|
230
235
|
}
|
|
231
236
|
}
|
|
237
|
+
function alog(m, x) {
|
|
238
|
+
if (devRequested()) console.info("[embed auth] host: " + m, x ?? "");
|
|
239
|
+
}
|
|
232
240
|
function readConfig() {
|
|
233
241
|
const el = document.currentScript ?? document.querySelector('script[data-key][src*="embed"]');
|
|
234
242
|
const publishableKey = el?.dataset.key;
|
|
@@ -244,13 +252,21 @@ function readConfig() {
|
|
|
244
252
|
);
|
|
245
253
|
}
|
|
246
254
|
const pageContextAttr = el?.dataset.pageContext?.toLowerCase();
|
|
255
|
+
let pageContext = true;
|
|
256
|
+
if (pageContextAttr === "off" || pageContextAttr === "false" || pageContextAttr === "0") {
|
|
257
|
+
pageContext = false;
|
|
258
|
+
} else if (pageContextAttr === "declared") {
|
|
259
|
+
pageContext = "declared";
|
|
260
|
+
} else if (pageContextAttr === "full" || pageContextAttr === "on" || pageContextAttr === "true" || pageContextAttr === "1") {
|
|
261
|
+
pageContext = true;
|
|
262
|
+
}
|
|
247
263
|
return {
|
|
248
264
|
publishableKey,
|
|
249
265
|
origin: el?.dataset.origin || DEFAULT_ORIGIN,
|
|
250
266
|
theme: el?.dataset.theme || "auto",
|
|
251
267
|
surface: el?.dataset.surface || "",
|
|
252
268
|
container,
|
|
253
|
-
pageContext
|
|
269
|
+
pageContext
|
|
254
270
|
// No `data-dev` — see the `dev` field's doc comment: the URL trigger is the
|
|
255
271
|
// point for the script-tag path, so there is deliberately no script-tag knob here.
|
|
256
272
|
// No `data-actions` either: the action policy lives entirely in the lazy chunk,
|
|
@@ -520,6 +536,11 @@ var EmbedHost = class {
|
|
|
520
536
|
case "widget.requestContext":
|
|
521
537
|
void this.loadContext().then((m) => m.provideContext());
|
|
522
538
|
break;
|
|
539
|
+
case "widget.pageContextMax":
|
|
540
|
+
void this.loadContext().then((m) => {
|
|
541
|
+
m.setPageContextMax(msg.mode);
|
|
542
|
+
});
|
|
543
|
+
break;
|
|
523
544
|
case "widget.requestSnapshot":
|
|
524
545
|
void this.loadContext().then((m) => m.sendSnapshot(this.send));
|
|
525
546
|
break;
|
|
@@ -731,18 +752,26 @@ var EmbedHost = class {
|
|
|
731
752
|
*/
|
|
732
753
|
async provideAuth() {
|
|
733
754
|
const provider = this.config.authTokenProvider ?? globalThis.matterfact?.getEmbedAuthToken;
|
|
734
|
-
if (!provider)
|
|
735
|
-
|
|
755
|
+
if (!provider) {
|
|
756
|
+
alog("no provider");
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
if (++this.ac > 5) {
|
|
760
|
+
alog("storm cap");
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
736
763
|
try {
|
|
737
764
|
const token = await provider();
|
|
738
765
|
if (token) this.send({ type: "host.auth", token, expiresAt: 0 });
|
|
739
766
|
this.emit({ type: "auth", phase: token ? "granted" : "failed" });
|
|
740
|
-
|
|
767
|
+
alog(token ? "token" : "empty");
|
|
768
|
+
} catch (e) {
|
|
741
769
|
this.emit({ type: "auth", phase: "failed" });
|
|
770
|
+
alog("threw", e);
|
|
742
771
|
}
|
|
743
772
|
}
|
|
744
773
|
loadContext() {
|
|
745
|
-
this.context ?? (this.context = import('./context-
|
|
774
|
+
this.context ?? (this.context = import('./context-4LP3EDXL.js').then((m) => {
|
|
746
775
|
m.start(
|
|
747
776
|
this.send,
|
|
748
777
|
this.config.origin,
|