@matterfact/embed 0.12.0 → 0.13.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.
Files changed (38) hide show
  1. package/README.md +41 -0
  2. package/dist/{chunk-M5TS546Z.js → chunk-C7DXO37G.js} +2 -2
  3. package/dist/{chunk-ZXMJWCQV.js → chunk-JLJG3MDX.js} +57 -35
  4. package/dist/chunk-JLJG3MDX.js.map +1 -0
  5. package/dist/chunk-QZCUQZJK.js +3 -0
  6. package/dist/chunk-QZCUQZJK.js.map +7 -0
  7. package/dist/{chunk-C4XGE6BO.js → chunk-S6OT47DL.js} +56 -34
  8. package/dist/chunk-S6OT47DL.js.map +1 -0
  9. package/dist/{chunk-WAUSVV7Y.js → chunk-UA4Y2O64.js} +2 -2
  10. package/dist/{context-4LP3EDXL.js → context-DAXACLSP.js} +3 -3
  11. package/dist/{context-4LP3EDXL.js.map → context-DAXACLSP.js.map} +1 -1
  12. package/dist/{context-ZSPDZWIB.js → context-IJK345PN.js} +2 -2
  13. package/dist/embed.js +1 -1
  14. package/dist/embed.js.map +3 -3
  15. package/dist/index.cjs +82 -32
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +73 -2
  18. package/dist/index.d.ts +73 -2
  19. package/dist/index.js +29 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/react.cjs +82 -32
  22. package/dist/react.cjs.map +1 -1
  23. package/dist/react.d.cts +28 -1
  24. package/dist/react.d.ts +28 -1
  25. package/dist/react.js +29 -1
  26. package/dist/react.js.map +1 -1
  27. package/dist/{snapshot-OR5SVEUD.js → snapshot-EVBNVVCT.js} +2 -2
  28. package/dist/{snapshot-X6FPP3HF.js → snapshot-P5SVKSPB.js} +3 -3
  29. package/dist/{snapshot-X6FPP3HF.js.map → snapshot-P5SVKSPB.js.map} +1 -1
  30. package/package.json +1 -1
  31. package/dist/chunk-C4XGE6BO.js.map +0 -1
  32. package/dist/chunk-SR4ZNUAN.js +0 -3
  33. package/dist/chunk-SR4ZNUAN.js.map +0 -7
  34. package/dist/chunk-ZXMJWCQV.js.map +0 -1
  35. /package/dist/{chunk-M5TS546Z.js.map → chunk-C7DXO37G.js.map} +0 -0
  36. /package/dist/{chunk-WAUSVV7Y.js.map → chunk-UA4Y2O64.js.map} +0 -0
  37. /package/dist/{context-ZSPDZWIB.js.map → context-IJK345PN.js.map} +0 -0
  38. /package/dist/{snapshot-OR5SVEUD.js.map → snapshot-EVBNVVCT.js.map} +0 -0
package/dist/react.cjs CHANGED
@@ -480,7 +480,7 @@ function mfTools(win) {
480
480
  if (typeof document2 === "function") {
481
481
  out.push({
482
482
  name: "mf.resolveDocument",
483
- description: 'Resolve a matterfact document (dossier, report, briefing) that is NOT on the current page to a concrete id. Call it with the document type and a key (e.g. a ticker) when the site map shows the document lives on another route. Returns {id, label, href}. Cite the result inline as <MFRef kind="document" id="<id>" label="<label>" /> \u2014 it renders as a chip that opens the document in the side panel; href is its "open on page" deeplink.',
483
+ description: `Resolve a matterfact document (dossier, report, briefing) that is NOT on the current page to a concrete id. Call it with the document type and the subject's key, when the site map shows the document lives on another route. For the key, use the current route parameter VERBATIM when the page context states one (e.g. ticker = BP~+LN+Equity \u2192 key "BP~+LN+Equity"): it is the host's own identifier and often differs from the ticker or name a person would write. Do not normalise, decode or re-spell it, and do not substitute what the user typed. Returns {id, label, href}. Cite the result inline as <MFRef kind="document" id="<id>" label="<label>" /> \u2014 it renders as a chip that opens the document in the side panel; href is its "open on page" deeplink.`,
484
484
  inputSchema: {
485
485
  type: "object",
486
486
  properties: {
@@ -1193,6 +1193,7 @@ async function resolveDeclaredContext() {
1193
1193
  async function publishContext() {
1194
1194
  if (!pageContextOn()) return;
1195
1195
  const declared = await resolveDeclaredContext();
1196
+ if (!pageContextOn()) return;
1196
1197
  send?.({ type: "host.context", context: buildPageContext(declared) });
1197
1198
  }
1198
1199
  function provideContext() {
@@ -1270,6 +1271,7 @@ function navigateHost(href) {
1270
1271
  location.assign(target.href);
1271
1272
  }
1272
1273
  function pushActivity(e) {
1274
+ if (!allowsAuto(effectivePageContextMode())) return;
1273
1275
  activity.push({ ...e, seq: ++activitySeq, ts: Date.now() });
1274
1276
  if (activity.length > MAX_ACTIVITY) activity.shift();
1275
1277
  send?.({ type: "host.activity", events: [activity[activity.length - 1]] });
@@ -1334,6 +1336,7 @@ function watchNavigation() {
1334
1336
  publishSitemap();
1335
1337
  publishTools();
1336
1338
  };
1339
+ if (navFire) return;
1337
1340
  navFire = fire;
1338
1341
  for (const name of ["pushState", "replaceState"]) {
1339
1342
  const orig = history[name];
@@ -1404,6 +1407,7 @@ async function sendSnapshot(emit) {
1404
1407
  return;
1405
1408
  }
1406
1409
  const { snapshot: snapshot2 } = await loadSnapshotModule();
1410
+ if (!allowsAuto(effectivePageContextMode())) return;
1407
1411
  const { yaml, truncated, visibleRefs } = snapshot2();
1408
1412
  emit({
1409
1413
  type: "host.snapshot",
@@ -1415,6 +1419,7 @@ async function sendSnapshot(emit) {
1415
1419
  async function sendRegion(ref, emit) {
1416
1420
  if (!allowsAuto(effectivePageContextMode())) return;
1417
1421
  const { snapshotRegion: snapshotRegion2, resolveRef: resolveRef2 } = await loadSnapshotModule();
1422
+ if (!allowsAuto(effectivePageContextMode())) return;
1418
1423
  const el = resolveRef2(ref);
1419
1424
  if (!el) {
1420
1425
  emit({
@@ -1454,13 +1459,39 @@ async function callTool(call, emit) {
1454
1459
  error: r.error
1455
1460
  });
1456
1461
  }
1457
- function stop() {
1462
+ function installAutoObservers() {
1463
+ document.addEventListener("click", onClick, { capture: true, passive: true });
1464
+ document.addEventListener("submit", onSubmit, {
1465
+ capture: true,
1466
+ passive: true
1467
+ });
1468
+ document.addEventListener("change", onChange, {
1469
+ capture: true,
1470
+ passive: true
1471
+ });
1472
+ document.addEventListener("selectionchange", scheduleFocus, { passive: true });
1473
+ document.addEventListener("focusin", scheduleFocus, {
1474
+ capture: true,
1475
+ passive: true
1476
+ });
1477
+ window.addEventListener("scroll", scheduleFocus, {
1478
+ capture: true,
1479
+ passive: true
1480
+ });
1481
+ }
1482
+ function removeAutoObservers() {
1458
1483
  document.removeEventListener("click", onClick, { capture: true });
1459
1484
  document.removeEventListener("submit", onSubmit, { capture: true });
1460
1485
  document.removeEventListener("change", onChange, { capture: true });
1461
1486
  document.removeEventListener("selectionchange", scheduleFocus);
1462
1487
  document.removeEventListener("focusin", scheduleFocus, { capture: true });
1463
1488
  window.removeEventListener("scroll", scheduleFocus, { capture: true });
1489
+ if (focusTimer) {
1490
+ clearTimeout(focusTimer);
1491
+ focusTimer = null;
1492
+ }
1493
+ }
1494
+ function unwatchNavigation() {
1464
1495
  if (navFire) {
1465
1496
  window.removeEventListener("popstate", navFire);
1466
1497
  navFire = null;
@@ -1473,10 +1504,10 @@ function stop() {
1473
1504
  history.replaceState = origReplaceState;
1474
1505
  origReplaceState = null;
1475
1506
  }
1476
- if (focusTimer) {
1477
- clearTimeout(focusTimer);
1478
- focusTimer = null;
1479
- }
1507
+ }
1508
+ function stop() {
1509
+ removeAutoObservers();
1510
+ unwatchNavigation();
1480
1511
  send = null;
1481
1512
  contextProvider = void 0;
1482
1513
  activity.length = 0;
@@ -1486,6 +1517,22 @@ function stop() {
1486
1517
  }
1487
1518
  function setPageContextMax(max) {
1488
1519
  adminPageContextMax = parsePageContextMode(max);
1520
+ applyObservation();
1521
+ }
1522
+ function applyObservation() {
1523
+ const mode = effectivePageContextMode();
1524
+ if (allowsAuto(mode)) {
1525
+ installAutoObservers();
1526
+ } else {
1527
+ removeAutoObservers();
1528
+ activity.length = 0;
1529
+ lastFocus = {};
1530
+ }
1531
+ if (allowsDeclared(mode)) {
1532
+ watchNavigation();
1533
+ } else {
1534
+ unwatchNavigation();
1535
+ }
1489
1536
  }
1490
1537
  function start(emit, origin, pageContext = true, provider) {
1491
1538
  stop();
@@ -1498,33 +1545,8 @@ function start(emit, origin, pageContext = true, provider) {
1498
1545
  void publishContext();
1499
1546
  publishArtifactGrants();
1500
1547
  publishSitemap();
1501
- watchNavigation();
1502
- if (allowsAuto(effectivePageContextMode())) {
1503
- document.addEventListener("click", onClick, {
1504
- capture: true,
1505
- passive: true
1506
- });
1507
- document.addEventListener("submit", onSubmit, {
1508
- capture: true,
1509
- passive: true
1510
- });
1511
- document.addEventListener("change", onChange, {
1512
- capture: true,
1513
- passive: true
1514
- });
1515
- document.addEventListener("selectionchange", scheduleFocus, {
1516
- passive: true
1517
- });
1518
- document.addEventListener("focusin", scheduleFocus, {
1519
- capture: true,
1520
- passive: true
1521
- });
1522
- window.addEventListener("scroll", scheduleFocus, {
1523
- capture: true,
1524
- passive: true
1525
- });
1526
- }
1527
1548
  }
1549
+ applyObservation();
1528
1550
  const theme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1529
1551
  emit({ type: "host.theme", mode: theme });
1530
1552
  {
@@ -2202,6 +2224,13 @@ var EmbedHost = class {
2202
2224
  case "widget.chat":
2203
2225
  this.emit({ type: "chat", phase: msg.phase, chatId: msg.chatId });
2204
2226
  break;
2227
+ case "widget.artifactParams":
2228
+ this.emit({
2229
+ type: "artifactParams",
2230
+ params: msg.params,
2231
+ source: msg.source
2232
+ });
2233
+ break;
2205
2234
  }
2206
2235
  }
2207
2236
  /**
@@ -2347,6 +2376,23 @@ var EmbedHost = class {
2347
2376
  this.queue = [];
2348
2377
  for (const m of pending) this.send(m);
2349
2378
  }
2379
+ /**
2380
+ * Push artifact param values into the widget — a PARTIAL patch; only the named
2381
+ * params change. Buffered like every other host→widget message until the widget
2382
+ * says it's listening.
2383
+ *
2384
+ * Explicit and deliberate, so it applies even to a param whose page-context binding
2385
+ * the viewer has overridden (spec §7.3).
2386
+ */
2387
+ setArtifactParams(params) {
2388
+ if (params == null || typeof params !== "object" || Array.isArray(params)) {
2389
+ console.error(
2390
+ "[matterfact] setArtifactParams expects an object of param values"
2391
+ );
2392
+ return;
2393
+ }
2394
+ this.send({ type: "host.artifactParams", params });
2395
+ }
2350
2396
  /** Tear down: stop listening and remove the host element. For the React wrapper's
2351
2397
  * unmount — the vanilla `<script>` loader lives for the page's lifetime and never
2352
2398
  * calls this. */
@@ -2364,6 +2410,10 @@ var EmbedHost = class {
2364
2410
  function mount(config) {
2365
2411
  const host = new EmbedHost(config);
2366
2412
  host.mount();
2413
+ window.matterfact = {
2414
+ ...window.matterfact ?? {},
2415
+ setArtifactParams: (params) => host.setArtifactParams(params)
2416
+ };
2367
2417
  return host;
2368
2418
  }
2369
2419