@matterfact/embed 0.4.0 → 0.5.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 +26 -6
- package/dist/{chunk-523BCS2Z.js → chunk-GZZYR6YF.js} +2 -2
- package/dist/chunk-JN3ZMONO.js +2 -0
- package/dist/chunk-JN3ZMONO.js.map +7 -0
- package/dist/{chunk-Z4WT3TIZ.js → chunk-JSH3BRYP.js} +8 -31
- package/dist/chunk-JSH3BRYP.js.map +1 -0
- package/dist/{chunk-SBNMM3ZV.js → chunk-NZIN3LK7.js} +6 -30
- package/dist/chunk-NZIN3LK7.js.map +1 -0
- package/dist/chunk-Z53V2P4B.js +2 -0
- package/dist/context-AQY2LJWK.js +3 -0
- package/dist/{context-KZAUOIR6.js.map → context-AQY2LJWK.js.map} +1 -1
- package/dist/{context-432WQST4.js → context-UBTZEEWS.js} +2 -4
- package/dist/embed.js +1 -1
- package/dist/embed.js.map +2 -2
- package/dist/index.cjs +17 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +13 -14
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +17 -42
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +13 -14
- package/dist/react.js.map +1 -1
- package/dist/{snapshot-SOMSG2OF.js → snapshot-HYMRZTZC.js} +2 -2
- package/dist/{snapshot-Q3CALMHD.js → snapshot-XFCV2MYR.js} +3 -3
- package/dist/{snapshot-Q3CALMHD.js.map → snapshot-XFCV2MYR.js.map} +1 -1
- package/examples/README.md +46 -0
- package/examples/demo-host/index.html +163 -0
- package/examples/demo-host/serve.mjs +62 -0
- package/examples/embed-demo/.env.example +24 -0
- package/examples/embed-demo/README.md +72 -0
- package/examples/embed-demo/index.html +12 -0
- package/examples/embed-demo/package.json +25 -0
- package/examples/embed-demo/src/App.tsx +189 -0
- package/examples/embed-demo/src/config.ts +43 -0
- package/examples/embed-demo/src/main.tsx +10 -0
- package/examples/embed-demo/src/styles.css +354 -0
- package/examples/embed-demo/tsconfig.json +16 -0
- package/examples/embed-demo/vite.config.ts +11 -0
- package/examples/host-panel.html +237 -0
- package/package.json +3 -2
- package/dist/chunk-SBNMM3ZV.js.map +0 -1
- package/dist/chunk-URIBHOOQ.js +0 -2
- package/dist/chunk-XLQ36ZMV.js +0 -2
- package/dist/chunk-XLQ36ZMV.js.map +0 -7
- package/dist/chunk-Z4WT3TIZ.js.map +0 -1
- package/dist/context-KZAUOIR6.js +0 -3
- /package/dist/{chunk-523BCS2Z.js.map → chunk-GZZYR6YF.js.map} +0 -0
- /package/dist/{chunk-URIBHOOQ.js.map → chunk-Z53V2P4B.js.map} +0 -0
- /package/dist/{context-432WQST4.js.map → context-UBTZEEWS.js.map} +0 -0
- /package/dist/{snapshot-SOMSG2OF.js.map → snapshot-HYMRZTZC.js.map} +0 -0
package/README.md
CHANGED
|
@@ -84,8 +84,12 @@ the token never reaches the model. Nothing extra to configure.
|
|
|
84
84
|
Script-tag / non-React hosts can use the iframe directly (the Share dialog shows this form):
|
|
85
85
|
|
|
86
86
|
```html
|
|
87
|
-
<iframe
|
|
88
|
-
|
|
87
|
+
<iframe
|
|
88
|
+
src="https://app.matterfact.com/embed/artifacts/tsla-liquidity?owner=you@firm.com&t=…"
|
|
89
|
+
width="100%"
|
|
90
|
+
height="600"
|
|
91
|
+
style="border:0"
|
|
92
|
+
></iframe>
|
|
89
93
|
```
|
|
90
94
|
|
|
91
95
|
## Signing users in
|
|
@@ -111,7 +115,7 @@ On a single-tenant Entra deployment there are **two app registrations**, and mix
|
|
|
111
115
|
is the thing that catches everyone:
|
|
112
116
|
|
|
113
117
|
- the **matterfact** app registration — you created it in your tenant and gave us its
|
|
114
|
-
client id + secret. It
|
|
118
|
+
client id + secret. It _exposes_ the scope.
|
|
115
119
|
- the app you're **embedding into** (e.g. your portal) — a **different** registration with
|
|
116
120
|
its **own** client id. It's the one your users sign into.
|
|
117
121
|
|
|
@@ -127,14 +131,14 @@ done, your embedding app requests that scope with MSAL and hands the access toke
|
|
|
127
131
|
```tsx
|
|
128
132
|
import { useMsal } from '@azure/msal-react';
|
|
129
133
|
|
|
130
|
-
const { instance, accounts } = useMsal();
|
|
134
|
+
const { instance, accounts } = useMsal(); // configured with YOUR app's client id
|
|
131
135
|
|
|
132
136
|
const getAuthToken = async () => {
|
|
133
137
|
const { accessToken } = await instance.acquireTokenSilent({
|
|
134
138
|
scopes: ['api://<matterfact-client-id>/embed.access'],
|
|
135
139
|
account: accounts[0],
|
|
136
140
|
});
|
|
137
|
-
return accessToken;
|
|
141
|
+
return accessToken; // access token, not the ID token
|
|
138
142
|
};
|
|
139
143
|
|
|
140
144
|
<MatterfactAgent publishableKey="pk_live_…" getAuthToken={getAuthToken} />;
|
|
@@ -193,7 +197,10 @@ engineer can flip it on a live deployment without redeploying the customer's sit
|
|
|
193
197
|
prop is for a host that wants it wired into their own debug tooling instead.
|
|
194
198
|
|
|
195
199
|
```tsx
|
|
196
|
-
<MatterfactAgent
|
|
200
|
+
<MatterfactAgent
|
|
201
|
+
publishableKey="pk_live_…"
|
|
202
|
+
dev={process.env.NODE_ENV !== 'production'}
|
|
203
|
+
/>
|
|
197
204
|
```
|
|
198
205
|
|
|
199
206
|
## Security model
|
|
@@ -204,6 +211,19 @@ prop is for a host that wants it wired into their own debug tooling instead.
|
|
|
204
211
|
- The page snapshot is untrusted reference data to the agent — grounding, never
|
|
205
212
|
instructions.
|
|
206
213
|
|
|
214
|
+
## Examples
|
|
215
|
+
|
|
216
|
+
Runnable examples ship inside this package (under `examples/`) and are browsable without
|
|
217
|
+
cloning anything:
|
|
218
|
+
|
|
219
|
+
- **`examples/embed-demo/`** — a tiny Vite + React app that mounts `<MatterfactAgent inline>`
|
|
220
|
+
in a side panel next to an embedded `<MatterfactArtifact>`, configured entirely via `.env`.
|
|
221
|
+
Browse it on [unpkg](https://unpkg.com/browse/@matterfact/embed/examples/embed-demo/), or
|
|
222
|
+
after `npm install @matterfact/embed` find it at
|
|
223
|
+
`node_modules/@matterfact/embed/examples/embed-demo/` — copy it out, `npm install`, `npm run dev`.
|
|
224
|
+
- **`examples/host-panel.html`** — the inline-placement pattern as a single HTML file (script-tag loader).
|
|
225
|
+
- **`examples/demo-host/`** — a zero-dependency host site proving the script-tag loader end to end.
|
|
226
|
+
|
|
207
227
|
## Full guide
|
|
208
228
|
|
|
209
229
|
The complete integration reference — endpoints, single-tenant Entra setup, troubleshooting
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as re,b as P}from"./chunk-XLQ36ZMV.js";var Be=Object.prototype.toString;function ie(e){return typeof e=="function"||Be.call(e)==="[object Function]"}function Fe(e){var t=Number(e);return isNaN(t)?0:t===0||!isFinite(t)?t:(t>0?1:-1)*Math.floor(Math.abs(t))}var Ke=Math.pow(2,53)-1;function ze(e){var t=Fe(e);return Math.min(Math.max(t,0),Ke)}function b(e,t){var n=Array,r=Object(e);if(e==null)throw new TypeError("Array.from requires an array-like object - not null or undefined");if(typeof t<"u"&&!ie(t))throw new TypeError("Array.from: when provided, the second argument must be a function");for(var a=ze(r.length),o=ie(n)?Object(new n(a)):new Array(a),l=0,u;l<a;)u=r[l],t?o[l]=t(u,l):o[l]=u,l+=1;return o.length=a,o}function D(e){"@babel/helpers - typeof";return D=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},D(e)}function Ye(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ae(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,oe(r.key),r)}}function Qe(e,t,n){return t&&ae(e.prototype,t),n&&ae(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function Je(e,t,n){return t=oe(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function oe(e){var t=Ze(e,"string");return D(t)=="symbol"?t:t+""}function Ze(e,t){if(D(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(D(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var et=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];Ye(this,e),Je(this,"items",void 0),this.items=t}return Qe(e,[{key:"add",value:function(n){return this.has(n)===!1&&this.items.push(n),this}},{key:"clear",value:function(){this.items=[]}},{key:"delete",value:function(n){var r=this.items.length;return this.items=this.items.filter(function(a){return a!==n}),r!==this.items.length}},{key:"forEach",value:function(n){var r=this;this.items.forEach(function(a){n(a,a,r)})}},{key:"has",value:function(n){return this.items.indexOf(n)!==-1}},{key:"size",get:function(){return this.items.length}}])})(),le=typeof Set>"u"?Set:et;function d(e){var t;return(t=e.localName)!==null&&t!==void 0?t:e.tagName.toLowerCase()}var tt={article:"article",aside:"complementary",button:"button",datalist:"listbox",dd:"definition",details:"group",dialog:"dialog",dt:"term",fieldset:"group",figure:"figure",form:"form",footer:"contentinfo",h1:"heading",h2:"heading",h3:"heading",h4:"heading",h5:"heading",h6:"heading",header:"banner",hr:"separator",html:"document",legend:"legend",li:"listitem",math:"math",main:"main",menu:"list",nav:"navigation",ol:"list",optgroup:"group",option:"option",output:"status",progress:"progressbar",section:"region",summary:"button",table:"table",tbody:"rowgroup",textarea:"textbox",tfoot:"rowgroup",td:"cell",th:"columnheader",thead:"rowgroup",tr:"row",ul:"list"},nt={caption:new Set(["aria-label","aria-labelledby"]),code:new Set(["aria-label","aria-labelledby"]),deletion:new Set(["aria-label","aria-labelledby"]),emphasis:new Set(["aria-label","aria-labelledby"]),generic:new Set(["aria-label","aria-labelledby","aria-roledescription"]),insertion:new Set(["aria-label","aria-labelledby"]),none:new Set(["aria-label","aria-labelledby"]),paragraph:new Set(["aria-label","aria-labelledby"]),presentation:new Set(["aria-label","aria-labelledby"]),strong:new Set(["aria-label","aria-labelledby"]),subscript:new Set(["aria-label","aria-labelledby"]),superscript:new Set(["aria-label","aria-labelledby"])};function rt(e,t){return["aria-atomic","aria-busy","aria-controls","aria-current","aria-description","aria-describedby","aria-details","aria-dropeffect","aria-flowto","aria-grabbed","aria-hidden","aria-keyshortcuts","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-roledescription"].some(function(n){var r;return e.hasAttribute(n)&&!((r=nt[t])!==null&&r!==void 0&&r.has(n))})}function ue(e,t){return rt(e,t)}function C(e){var t=at(e);if(t===null||_.indexOf(t)!==-1){var n=it(e);if(_.indexOf(t||"")===-1||ue(e,n||""))return n}return t}function it(e){var t=tt[d(e)];if(t!==void 0)return t;switch(d(e)){case"a":case"area":case"link":if(e.hasAttribute("href"))return"link";break;case"img":return e.getAttribute("alt")===""&&!ue(e,"img")?"presentation":"img";case"input":{var n=e,r=n.type;switch(r){case"button":case"image":case"reset":case"submit":return"button";case"checkbox":case"radio":return r;case"range":return"slider";case"email":case"tel":case"text":case"url":return e.hasAttribute("list")?"combobox":"textbox";case"search":return e.hasAttribute("list")?"combobox":"searchbox";case"number":return"spinbutton";default:return null}}case"select":return e.hasAttribute("multiple")||e.size>1?"listbox":"combobox"}return null}function at(e){var t=e.getAttribute("role");if(t!==null){var n=t.trim().split(" ")[0];if(n.length>0)return n}return null}var _=["presentation","none"];function s(e){return e!==null&&e.nodeType===e.ELEMENT_NODE}function B(e){return s(e)&&d(e)==="caption"}function H(e){return s(e)&&d(e)==="input"}function se(e){return s(e)&&d(e)==="optgroup"}function fe(e){return s(e)&&d(e)==="select"}function ce(e){return s(e)&&d(e)==="table"}function de(e){return s(e)&&d(e)==="textarea"}function me(e){var t=e.ownerDocument===null?e:e.ownerDocument,n=t.defaultView;if(n===null)throw new TypeError("no window available");return n}function pe(e){return s(e)&&d(e)==="fieldset"}function be(e){return s(e)&&d(e)==="legend"}function ge(e){return s(e)&&d(e)==="slot"}function ot(e){return s(e)&&e.ownerSVGElement!==void 0}function he(e){return s(e)&&d(e)==="svg"}function ye(e){return ot(e)&&d(e)==="title"}function $(e,t){if(s(e)&&e.hasAttribute(t)){var n=e.getAttribute(t).split(" "),r=e.getRootNode?e.getRootNode():e.ownerDocument;return n.map(function(a){return r.getElementById(a)}).filter(function(a){return a!==null})}return[]}function g(e,t){return s(e)?t.indexOf(C(e))!==-1:!1}function lt(e){return e.trim().replace(/\s\s+/g," ")}function ut(e,t){if(!s(e))return!1;if(e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true")return!0;var n=t(e);return n.getPropertyValue("display")==="none"||n.getPropertyValue("visibility")==="hidden"}function st(e){return g(e,["button","combobox","listbox","textbox"])||Ee(e,"range")}function Ee(e,t){if(!s(e))return!1;switch(t){case"range":return g(e,["meter","progressbar","scrollbar","slider","spinbutton"]);default:throw new TypeError("No knowledge about abstract role '".concat(t,"'. This is likely a bug :("))}}function ve(e,t){var n=b(e.querySelectorAll(t));return $(e,"aria-owns").forEach(function(r){n.push.apply(n,b(r.querySelectorAll(t)))}),n}function ft(e){return fe(e)?e.selectedOptions||ve(e,"[selected]"):ve(e,'[aria-selected="true"]')}function ct(e){return g(e,_)}function dt(e){return B(e)}function mt(e){return g(e,["button","cell","checkbox","columnheader","gridcell","heading","label","legend","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","row","rowheader","switch","tab","tooltip","treeitem"])}function pt(e){return!1}function bt(e){return H(e)||de(e)?e.value:e.textContent||""}function Se(e){var t=e.getPropertyValue("content");return/^["'].*["']$/.test(t)?t.slice(1,-1):""}function xe(e){var t=d(e);return t==="button"||t==="input"&&e.getAttribute("type")!=="hidden"||t==="meter"||t==="output"||t==="progress"||t==="select"||t==="textarea"}function Ae(e){if(xe(e))return e;var t=null;return e.childNodes.forEach(function(n){if(t===null&&s(n)){var r=Ae(n);r!==null&&(t=r)}}),t}function gt(e){if(e.control!==void 0)return e.control;var t=e.getAttribute("for");return t!==null?e.ownerDocument.getElementById(t):Ae(e)}function ht(e){var t=e.labels;if(t===null)return t;if(t!==void 0)return b(t);if(!xe(e))return null;var n=e.ownerDocument;return b(n.querySelectorAll("label")).filter(function(r){return gt(r)===e})}function yt(e){var t=e.assignedNodes();return t.length===0?b(e.childNodes):t}function F(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=new le,r=typeof Map>"u"?void 0:new Map,a=me(e),o=t.compute,l=o===void 0?"name":o,u=t.computedStyleSupportsPseudoElements,m=u===void 0?t.getComputedStyle!==void 0:u,p=t.getComputedStyle,x=p===void 0?a.getComputedStyle.bind(a):p,M=t.hidden,R=M===void 0?!1:M,I=function(f,c){if(c!==void 0)throw new Error("use uncachedGetComputedStyle directly for pseudo elements");if(r===void 0)return x(f);var h=r.get(f);if(h)return h;var y=x(f,c);return r.set(f,y),y};function W(i,f){var c="";if(s(i)&&m){var h=x(i,"::before"),y=Se(h);c="".concat(y," ").concat(c)}var S=ge(i)?yt(i):b(i.childNodes).concat($(i,"aria-owns"));if(S.forEach(function(v){var N=A(v,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1,recursion:!0}),E=s(v)?I(v).getPropertyValue("display"):"inline",k=E!=="inline"?" ":"";c+="".concat(k).concat(N).concat(k)}),s(i)&&m){var T=x(i,"::after"),w=Se(T);c="".concat(c," ").concat(w)}return c.trim()}function O(i,f){var c=i.getAttributeNode(f);return c!==null&&!n.has(c)&&c.value.trim()!==""?(n.add(c),c.value):null}function Ue(i){return s(i)?O(i,"title"):null}function Xe(i){if(!s(i))return null;if(pe(i)){n.add(i);for(var f=b(i.childNodes),c=0;c<f.length;c+=1){var h=f[c];if(be(h))return A(h,{isEmbeddedInLabel:!1,isReferenced:!1,recursion:!1})}}else if(ce(i)){n.add(i);for(var y=b(i.childNodes),S=0;S<y.length;S+=1){var T=y[S];if(B(T))return A(T,{isEmbeddedInLabel:!1,isReferenced:!1,recursion:!1})}}else if(he(i)){n.add(i);for(var w=b(i.childNodes),v=0;v<w.length;v+=1){var N=w[v];if(ye(N))return N.textContent}return null}else if(d(i)==="img"||d(i)==="area"){var E=O(i,"alt");if(E!==null)return E}else if(se(i)){var k=O(i,"label");if(k!==null)return k}if(H(i)&&(i.type==="button"||i.type==="submit"||i.type==="reset")){var Z=O(i,"value");if(Z!==null)return Z;if(i.type==="submit")return"Submit";if(i.type==="reset")return"Reset"}var U=ht(i);if(U!==null&&U.length!==0)return n.add(i),b(U).map(function(X){return A(X,{isEmbeddedInLabel:!0,isReferenced:!1,recursion:!0})}).filter(function(X){return X.length>0}).join(" ");if(H(i)&&i.type==="image"){var ee=O(i,"alt");if(ee!==null)return ee;var te=O(i,"title");return te!==null?te:"Submit Query"}if(g(i,["button"])){var ne=W(i,{isEmbeddedInLabel:!1,isReferenced:!1});if(ne!=="")return ne}return null}function A(i,f){if(n.has(i))return"";if(!R&&ut(i,I)&&!f.isReferenced)return n.add(i),"";var c=s(i)?i.getAttributeNode("aria-labelledby"):null,h=c!==null&&!n.has(c)?$(i,"aria-labelledby"):[];if(l==="name"&&!f.isReferenced&&h.length>0)return n.add(c),h.map(function(E){return A(E,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!0,recursion:!1})}).join(" ");var y=f.recursion&&st(i)&&l==="name";if(!y){var S=(s(i)&&i.getAttribute("aria-label")||"").trim();if(S!==""&&l==="name")return n.add(i),S;if(!ct(i)){var T=Xe(i);if(T!==null)return n.add(i),T}}if(g(i,["menu"]))return n.add(i),"";if(y||f.isEmbeddedInLabel||f.isReferenced){if(g(i,["combobox","listbox"])){n.add(i);var w=ft(i);return w.length===0?H(i)?i.value:"":b(w).map(function(E){return A(E,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1,recursion:!0})}).join(" ")}if(Ee(i,"range"))return n.add(i),i.hasAttribute("aria-valuetext")?i.getAttribute("aria-valuetext"):i.hasAttribute("aria-valuenow")?i.getAttribute("aria-valuenow"):i.getAttribute("value")||"";if(g(i,["textbox"]))return n.add(i),bt(i)}if(mt(i)||s(i)&&f.isReferenced||dt(i)||pt(i)){var v=W(i,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1});if(v!=="")return n.add(i),v}if(i.nodeType===i.TEXT_NODE)return n.add(i),i.textContent||"";if(f.recursion)return n.add(i),W(i,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1});var N=Ue(i);return N!==null?(n.add(i),N):(n.add(i),"")}return lt(A(e,{isEmbeddedInLabel:!1,isReferenced:l==="description",recursion:!1}))}function vt(e){return g(e,["caption","code","deletion","emphasis","generic","insertion","none","paragraph","presentation","strong","subscript","superscript"])}function K(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return vt(e)?"":F(e,t)}function Te(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=n.getComputedStyle,a=r===void 0?(t=e.ownerDocument.defaultView)===null||t===void 0?void 0:t.getComputedStyle:r,o=n.isSubtreeInaccessible,l=o===void 0?St:o;if(typeof a!="function")throw new TypeError("Owner document of the element needs to have an associated window.");if(a(e).visibility==="hidden")return!0;for(var u=e;u;){if(l(u,{getComputedStyle:a}))return!0;u=u.parentElement}return!1}function St(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=n.getComputedStyle,a=r===void 0?(t=e.ownerDocument.defaultView)===null||t===void 0?void 0:t.getComputedStyle:r;if(typeof a!="function")throw new TypeError("Owner document of the element needs to have an associated window.");return e.hidden===!0||e.getAttribute("aria-hidden")==="true"||a(e).display==="none"}var Et=new Set(["button","fieldset","input","optgroup","option","select","textarea"]);function V(e){var t=d(e);return Et.has(t)&&e.hasAttribute("disabled")?!0:e.getAttribute("aria-disabled")==="true"}function Ne(){let e=new WeakMap;return((t,n)=>{if(n)return window.getComputedStyle(t,n);let r=e.get(t);return r||(r=window.getComputedStyle(t),e.set(t,r)),r})}function Le(){return document.documentElement.getClientRects().length>0}function Re(e,t,n){let r=t.display;if(r==="none")return!1;let a=t.visibility;if(a==="hidden"||a==="collapse"||Number(t.opacity)===0)return!1;if(n&&r!=="contents"){let o=e.getBoundingClientRect();if(o.width<=0||o.height<=0||e.getClientRects().length===0||o.right<-2e3||o.bottom<-2e3)return!1}return!0}function Oe(e){return e.pointerEvents!=="none"}var xt=new Set(["button","checkbox","combobox","link","listbox","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]),At=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","SUMMARY"]);function G(e){let t=e.getAttribute("contenteditable");return t!==null&&t!=="false"}function Ce(e,t,n,r){let a=e.tagName;if(a==="A"&&e.hasAttribute("href")||At.has(a)||t!==null&&xt.has(t))return!0;let o=e.getAttribute("tabindex");return!!(o!==null&&Number(o)>=0||G(e)||n.cursor==="pointer"&&r?.cursor!=="pointer")}var Me=new Set(["button","cell","checkbox","columnheader","gridcell","heading","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","row","rowheader","switch","tab","tooltip","treeitem"]),Tt=new Set(["textbox","searchbox","spinbutton"]),wt=new Set(["INPUT","TEXTAREA"]);function Ie(e){return wt.has(e.tagName)||G(e)}function Nt(e,t){let n=e.tagName;return n==="INPUT"||n==="TEXTAREA"?Tt.has(t)?(e.value??"").length>0:!1:G(e)?(e.textContent??"").trim().length>0:!1}function we(e,t){let n=e.getAttribute(t);return n==="true"?"true":n==="mixed"?"mixed":null}function ke(e,t){let n=[],r=e.tagName;if(r==="INPUT"&&(t==="checkbox"||t==="radio"))e.checked&&n.push("[checked]");else{let l=we(e,"aria-checked");l==="mixed"?n.push("[checked=mixed]"):l==="true"&&n.push("[checked]")}V(e)&&n.push("[disabled]");let a=e.getAttribute("aria-expanded");if(a==="true"||a==="false")a==="true"&&n.push("[expanded]");else if(r==="SUMMARY"){let l=e.parentElement;l?.tagName==="DETAILS"&&l.open&&n.push("[expanded]")}if(t==="heading"){let l=e.getAttribute("aria-level"),u=Number(l||r[1]);Number.isFinite(u)&&u>0&&n.push(`[level=${u}]`)}let o=we(e,"aria-pressed");return o==="mixed"?n.push("[pressed=mixed]"):o==="true"&&n.push("[pressed]"),e.getAttribute("aria-selected")==="true"&&n.push("[selected]"),Nt(e,t)&&n.push("[filled]"),n.join(" ")}function Pe(e){return G(e)?"textbox":C(e)}var z='input,textarea,select,[contenteditable=""],[contenteditable="true"],[aria-valuetext],[data-mf-private]';function Lt(e){let t=e.getAttribute("aria-labelledby");if(t){for(let n of t.split(/\s+/)){if(!n)continue;let r=e.ownerDocument.getElementById(n);if(r&&(r.matches(z)||r.querySelector(z)))return!0}return!1}return e.hasAttribute("aria-label")?!1:e.querySelector(z)!==null}function De(e,t){let n=K(e,{getComputedStyle:t,computedStyleSupportsPseudoElements:!1});return n?Lt(e)?e.getAttribute("aria-label")||"":n:""}var Rt=0,q=0,Y=new WeakMap,j=new Map;function _e(){q++,j.clear()}function He(e,t,n){let r=`${t} ${n}`,a=Y.get(e);return!a||a.key!==r?(a={id:`e${++Rt}`,key:r,gen:q},Y.set(e,a)):a.gen=q,j.set(a.id,e),a.id}function Ot(e){let t=j.get(e);if(!t)return null;if(!t.isConnected)return j.delete(e),null;let n=Y.get(t);return!n||n.id!==e||n.gen!==q?null:t}function Ct(){j.clear()}var Mt=4e3,It=800,kt=120,Pt=120,Ge=25,$e=new Set(["generic","presentation","none"]),Dt=new Set(["SCRIPT","STYLE","NOSCRIPT","TEMPLATE","SVG","HEAD","LINK","META","BASE"]);function L(e){return e.nodes>=Mt||e.lines>=It?(e.truncated=!0,!1):!0}function _t(e){return e.id==="matterfact-embed"||e.hasAttribute("data-mf-embed")}function Ht(e,t,n){return e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden")||e.hasAttribute("inert")?!0:!Re(e,t,n)}function $t(e){if(e.shadowRoot)return e.shadowRoot.childNodes;if(e.tagName==="SLOT"){let t=e.assignedNodes({flatten:!0});if(t.length)return t}return e.childNodes}function Q(e,t,n,r){let a=$t(e);for(let o=0;o<a.length;o++){let l=a[o];l&&Wt(l,t,n,r)}}function Vt(e,t,n){let r=(e.nodeValue??"").replace(/\s+/g," ").trim();r&&(Me.has(t.role)||L(n)&&(n.lines++,t.children.push(r)))}function J(e){let t=e.matches(":disabled")||V(e);return{role:"option",name:(e.label||e.textContent||"").trim(),props:(t?" [disabled]":"")+(e.selected?" [selected]":""),children:[]}}function jt(e,t,n){let r=e.options,a=Math.min(r.length,Ge);for(let m=0;m<a;m++){if(!L(n))return;let p=r[m];!p||P(p)||(n.lines++,t.children.push(J(p)))}let o=0,l=e.selectedOptions;for(let m=0;m<l.length;m++){let p=l[m];if(p&&p.index>=a&&!P(p)){if(!L(n))return;n.lines++,t.children.push(J(p)),o++}}let u=r.length-a-o;u>0&&L(n)&&(n.lines++,t.children.push(`\u2026 (+${u} more options)`))}function Gt(e,t,n){let r=e.list;if(!r)return;let a=r.options,o=Math.min(a.length,Ge);for(let u=0;u<o;u++){if(!L(n))return;let m=a[u];!m||P(m)||(n.lines++,t.children.push(J(m)))}let l=a.length-o;l>0&&L(n)&&(n.lines++,t.children.push(`\u2026 (+${l} more options)`))}function qt(e,t,n,r){if(!L(r)||Dt.has(e.tagName)||_t(e)||P(e))return;r.nodes++;let a=r.styleOf(e);if(Ht(e,a,r.layout))return;let o=Pe(e),l=o===null||$e.has(o),u=Ce(e,o,a,n);if(l&&!u){Q(e,t,a,r);return}let m=o===null||$e.has(o)?"generic":o,p=De(e,r.styleOf),x="";if(u&&Oe(a)){let I=He(e,m,p);x=` [ref=${I}]`,r.onRef?.(I,e)}let M=ke(e,m),R={role:m,name:p,props:(M?` ${M}`:"")+x,children:[]};if(r.lines++,t.children.push(R),e.tagName==="SELECT"){jt(e,R,r);return}e.tagName==="INPUT"&&e.list&&Gt(e,R,r),!Ie(e)&&Q(e,R,a,r)}function Wt(e,t,n,r){e.nodeType===3?Vt(e,t,r):e.nodeType===1&&qt(e,t,n,r)}function Ve(e,t){let n=e.replace(/\s+/g," ").trim(),r=re(n);return r.length>t?`${r.slice(0,t-1)}\u2026`:r}function je(e){return`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function qe(e,t,n){let r=" ".repeat(t);for(let a of e){if(typeof a=="string"){n.push(`${r}- text: ${je(Ve(a,Pt))}`);continue}let o=a.name?` ${je(Ve(a.name,kt))}`:"",l=`${r}- ${a.role}${o}${a.props}`;a.children.length?(n.push(`${l}:`),qe(a.children,t+1,n)):n.push(l)}}function We(e,t){let n=Ne(),r={styleOf:n,layout:Le(),nodes:0,lines:0,truncated:!1,onRef:t};if(Te(e,{getComputedStyle:n}))return{yaml:"",truncated:!1};let a={role:"",name:"",props:"",children:[]};Q(e,a,n(e),r);let o=[];return qe(a.children,0,o),r.truncated&&o.length&&(o[o.length-1]='- text: "\u2026 (snapshot truncated \u2014 more of the page is below)"'),{yaml:o.join(`
|
|
1
|
+
import{a as re,b as P}from"./chunk-JN3ZMONO.js";var Be=Object.prototype.toString;function ie(e){return typeof e=="function"||Be.call(e)==="[object Function]"}function Fe(e){var t=Number(e);return isNaN(t)?0:t===0||!isFinite(t)?t:(t>0?1:-1)*Math.floor(Math.abs(t))}var Ke=Math.pow(2,53)-1;function ze(e){var t=Fe(e);return Math.min(Math.max(t,0),Ke)}function b(e,t){var n=Array,r=Object(e);if(e==null)throw new TypeError("Array.from requires an array-like object - not null or undefined");if(typeof t<"u"&&!ie(t))throw new TypeError("Array.from: when provided, the second argument must be a function");for(var a=ze(r.length),o=ie(n)?Object(new n(a)):new Array(a),l=0,u;l<a;)u=r[l],t?o[l]=t(u,l):o[l]=u,l+=1;return o.length=a,o}function D(e){"@babel/helpers - typeof";return D=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},D(e)}function Ye(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ae(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,oe(r.key),r)}}function Qe(e,t,n){return t&&ae(e.prototype,t),n&&ae(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function Je(e,t,n){return t=oe(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function oe(e){var t=Ze(e,"string");return D(t)=="symbol"?t:t+""}function Ze(e,t){if(D(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(D(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var et=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];Ye(this,e),Je(this,"items",void 0),this.items=t}return Qe(e,[{key:"add",value:function(n){return this.has(n)===!1&&this.items.push(n),this}},{key:"clear",value:function(){this.items=[]}},{key:"delete",value:function(n){var r=this.items.length;return this.items=this.items.filter(function(a){return a!==n}),r!==this.items.length}},{key:"forEach",value:function(n){var r=this;this.items.forEach(function(a){n(a,a,r)})}},{key:"has",value:function(n){return this.items.indexOf(n)!==-1}},{key:"size",get:function(){return this.items.length}}])})(),le=typeof Set>"u"?Set:et;function d(e){var t;return(t=e.localName)!==null&&t!==void 0?t:e.tagName.toLowerCase()}var tt={article:"article",aside:"complementary",button:"button",datalist:"listbox",dd:"definition",details:"group",dialog:"dialog",dt:"term",fieldset:"group",figure:"figure",form:"form",footer:"contentinfo",h1:"heading",h2:"heading",h3:"heading",h4:"heading",h5:"heading",h6:"heading",header:"banner",hr:"separator",html:"document",legend:"legend",li:"listitem",math:"math",main:"main",menu:"list",nav:"navigation",ol:"list",optgroup:"group",option:"option",output:"status",progress:"progressbar",section:"region",summary:"button",table:"table",tbody:"rowgroup",textarea:"textbox",tfoot:"rowgroup",td:"cell",th:"columnheader",thead:"rowgroup",tr:"row",ul:"list"},nt={caption:new Set(["aria-label","aria-labelledby"]),code:new Set(["aria-label","aria-labelledby"]),deletion:new Set(["aria-label","aria-labelledby"]),emphasis:new Set(["aria-label","aria-labelledby"]),generic:new Set(["aria-label","aria-labelledby","aria-roledescription"]),insertion:new Set(["aria-label","aria-labelledby"]),none:new Set(["aria-label","aria-labelledby"]),paragraph:new Set(["aria-label","aria-labelledby"]),presentation:new Set(["aria-label","aria-labelledby"]),strong:new Set(["aria-label","aria-labelledby"]),subscript:new Set(["aria-label","aria-labelledby"]),superscript:new Set(["aria-label","aria-labelledby"])};function rt(e,t){return["aria-atomic","aria-busy","aria-controls","aria-current","aria-description","aria-describedby","aria-details","aria-dropeffect","aria-flowto","aria-grabbed","aria-hidden","aria-keyshortcuts","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-roledescription"].some(function(n){var r;return e.hasAttribute(n)&&!((r=nt[t])!==null&&r!==void 0&&r.has(n))})}function ue(e,t){return rt(e,t)}function C(e){var t=at(e);if(t===null||_.indexOf(t)!==-1){var n=it(e);if(_.indexOf(t||"")===-1||ue(e,n||""))return n}return t}function it(e){var t=tt[d(e)];if(t!==void 0)return t;switch(d(e)){case"a":case"area":case"link":if(e.hasAttribute("href"))return"link";break;case"img":return e.getAttribute("alt")===""&&!ue(e,"img")?"presentation":"img";case"input":{var n=e,r=n.type;switch(r){case"button":case"image":case"reset":case"submit":return"button";case"checkbox":case"radio":return r;case"range":return"slider";case"email":case"tel":case"text":case"url":return e.hasAttribute("list")?"combobox":"textbox";case"search":return e.hasAttribute("list")?"combobox":"searchbox";case"number":return"spinbutton";default:return null}}case"select":return e.hasAttribute("multiple")||e.size>1?"listbox":"combobox"}return null}function at(e){var t=e.getAttribute("role");if(t!==null){var n=t.trim().split(" ")[0];if(n.length>0)return n}return null}var _=["presentation","none"];function s(e){return e!==null&&e.nodeType===e.ELEMENT_NODE}function B(e){return s(e)&&d(e)==="caption"}function H(e){return s(e)&&d(e)==="input"}function se(e){return s(e)&&d(e)==="optgroup"}function fe(e){return s(e)&&d(e)==="select"}function ce(e){return s(e)&&d(e)==="table"}function de(e){return s(e)&&d(e)==="textarea"}function me(e){var t=e.ownerDocument===null?e:e.ownerDocument,n=t.defaultView;if(n===null)throw new TypeError("no window available");return n}function pe(e){return s(e)&&d(e)==="fieldset"}function be(e){return s(e)&&d(e)==="legend"}function ge(e){return s(e)&&d(e)==="slot"}function ot(e){return s(e)&&e.ownerSVGElement!==void 0}function he(e){return s(e)&&d(e)==="svg"}function ye(e){return ot(e)&&d(e)==="title"}function $(e,t){if(s(e)&&e.hasAttribute(t)){var n=e.getAttribute(t).split(" "),r=e.getRootNode?e.getRootNode():e.ownerDocument;return n.map(function(a){return r.getElementById(a)}).filter(function(a){return a!==null})}return[]}function g(e,t){return s(e)?t.indexOf(C(e))!==-1:!1}function lt(e){return e.trim().replace(/\s\s+/g," ")}function ut(e,t){if(!s(e))return!1;if(e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true")return!0;var n=t(e);return n.getPropertyValue("display")==="none"||n.getPropertyValue("visibility")==="hidden"}function st(e){return g(e,["button","combobox","listbox","textbox"])||Ee(e,"range")}function Ee(e,t){if(!s(e))return!1;switch(t){case"range":return g(e,["meter","progressbar","scrollbar","slider","spinbutton"]);default:throw new TypeError("No knowledge about abstract role '".concat(t,"'. This is likely a bug :("))}}function ve(e,t){var n=b(e.querySelectorAll(t));return $(e,"aria-owns").forEach(function(r){n.push.apply(n,b(r.querySelectorAll(t)))}),n}function ft(e){return fe(e)?e.selectedOptions||ve(e,"[selected]"):ve(e,'[aria-selected="true"]')}function ct(e){return g(e,_)}function dt(e){return B(e)}function mt(e){return g(e,["button","cell","checkbox","columnheader","gridcell","heading","label","legend","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","row","rowheader","switch","tab","tooltip","treeitem"])}function pt(e){return!1}function bt(e){return H(e)||de(e)?e.value:e.textContent||""}function Se(e){var t=e.getPropertyValue("content");return/^["'].*["']$/.test(t)?t.slice(1,-1):""}function xe(e){var t=d(e);return t==="button"||t==="input"&&e.getAttribute("type")!=="hidden"||t==="meter"||t==="output"||t==="progress"||t==="select"||t==="textarea"}function Ae(e){if(xe(e))return e;var t=null;return e.childNodes.forEach(function(n){if(t===null&&s(n)){var r=Ae(n);r!==null&&(t=r)}}),t}function gt(e){if(e.control!==void 0)return e.control;var t=e.getAttribute("for");return t!==null?e.ownerDocument.getElementById(t):Ae(e)}function ht(e){var t=e.labels;if(t===null)return t;if(t!==void 0)return b(t);if(!xe(e))return null;var n=e.ownerDocument;return b(n.querySelectorAll("label")).filter(function(r){return gt(r)===e})}function yt(e){var t=e.assignedNodes();return t.length===0?b(e.childNodes):t}function F(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=new le,r=typeof Map>"u"?void 0:new Map,a=me(e),o=t.compute,l=o===void 0?"name":o,u=t.computedStyleSupportsPseudoElements,m=u===void 0?t.getComputedStyle!==void 0:u,p=t.getComputedStyle,x=p===void 0?a.getComputedStyle.bind(a):p,M=t.hidden,R=M===void 0?!1:M,I=function(f,c){if(c!==void 0)throw new Error("use uncachedGetComputedStyle directly for pseudo elements");if(r===void 0)return x(f);var h=r.get(f);if(h)return h;var y=x(f,c);return r.set(f,y),y};function W(i,f){var c="";if(s(i)&&m){var h=x(i,"::before"),y=Se(h);c="".concat(y," ").concat(c)}var S=ge(i)?yt(i):b(i.childNodes).concat($(i,"aria-owns"));if(S.forEach(function(v){var N=A(v,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1,recursion:!0}),E=s(v)?I(v).getPropertyValue("display"):"inline",k=E!=="inline"?" ":"";c+="".concat(k).concat(N).concat(k)}),s(i)&&m){var T=x(i,"::after"),w=Se(T);c="".concat(c," ").concat(w)}return c.trim()}function O(i,f){var c=i.getAttributeNode(f);return c!==null&&!n.has(c)&&c.value.trim()!==""?(n.add(c),c.value):null}function Ue(i){return s(i)?O(i,"title"):null}function Xe(i){if(!s(i))return null;if(pe(i)){n.add(i);for(var f=b(i.childNodes),c=0;c<f.length;c+=1){var h=f[c];if(be(h))return A(h,{isEmbeddedInLabel:!1,isReferenced:!1,recursion:!1})}}else if(ce(i)){n.add(i);for(var y=b(i.childNodes),S=0;S<y.length;S+=1){var T=y[S];if(B(T))return A(T,{isEmbeddedInLabel:!1,isReferenced:!1,recursion:!1})}}else if(he(i)){n.add(i);for(var w=b(i.childNodes),v=0;v<w.length;v+=1){var N=w[v];if(ye(N))return N.textContent}return null}else if(d(i)==="img"||d(i)==="area"){var E=O(i,"alt");if(E!==null)return E}else if(se(i)){var k=O(i,"label");if(k!==null)return k}if(H(i)&&(i.type==="button"||i.type==="submit"||i.type==="reset")){var Z=O(i,"value");if(Z!==null)return Z;if(i.type==="submit")return"Submit";if(i.type==="reset")return"Reset"}var U=ht(i);if(U!==null&&U.length!==0)return n.add(i),b(U).map(function(X){return A(X,{isEmbeddedInLabel:!0,isReferenced:!1,recursion:!0})}).filter(function(X){return X.length>0}).join(" ");if(H(i)&&i.type==="image"){var ee=O(i,"alt");if(ee!==null)return ee;var te=O(i,"title");return te!==null?te:"Submit Query"}if(g(i,["button"])){var ne=W(i,{isEmbeddedInLabel:!1,isReferenced:!1});if(ne!=="")return ne}return null}function A(i,f){if(n.has(i))return"";if(!R&&ut(i,I)&&!f.isReferenced)return n.add(i),"";var c=s(i)?i.getAttributeNode("aria-labelledby"):null,h=c!==null&&!n.has(c)?$(i,"aria-labelledby"):[];if(l==="name"&&!f.isReferenced&&h.length>0)return n.add(c),h.map(function(E){return A(E,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!0,recursion:!1})}).join(" ");var y=f.recursion&&st(i)&&l==="name";if(!y){var S=(s(i)&&i.getAttribute("aria-label")||"").trim();if(S!==""&&l==="name")return n.add(i),S;if(!ct(i)){var T=Xe(i);if(T!==null)return n.add(i),T}}if(g(i,["menu"]))return n.add(i),"";if(y||f.isEmbeddedInLabel||f.isReferenced){if(g(i,["combobox","listbox"])){n.add(i);var w=ft(i);return w.length===0?H(i)?i.value:"":b(w).map(function(E){return A(E,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1,recursion:!0})}).join(" ")}if(Ee(i,"range"))return n.add(i),i.hasAttribute("aria-valuetext")?i.getAttribute("aria-valuetext"):i.hasAttribute("aria-valuenow")?i.getAttribute("aria-valuenow"):i.getAttribute("value")||"";if(g(i,["textbox"]))return n.add(i),bt(i)}if(mt(i)||s(i)&&f.isReferenced||dt(i)||pt(i)){var v=W(i,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1});if(v!=="")return n.add(i),v}if(i.nodeType===i.TEXT_NODE)return n.add(i),i.textContent||"";if(f.recursion)return n.add(i),W(i,{isEmbeddedInLabel:f.isEmbeddedInLabel,isReferenced:!1});var N=Ue(i);return N!==null?(n.add(i),N):(n.add(i),"")}return lt(A(e,{isEmbeddedInLabel:!1,isReferenced:l==="description",recursion:!1}))}function vt(e){return g(e,["caption","code","deletion","emphasis","generic","insertion","none","paragraph","presentation","strong","subscript","superscript"])}function K(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return vt(e)?"":F(e,t)}function Te(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=n.getComputedStyle,a=r===void 0?(t=e.ownerDocument.defaultView)===null||t===void 0?void 0:t.getComputedStyle:r,o=n.isSubtreeInaccessible,l=o===void 0?St:o;if(typeof a!="function")throw new TypeError("Owner document of the element needs to have an associated window.");if(a(e).visibility==="hidden")return!0;for(var u=e;u;){if(l(u,{getComputedStyle:a}))return!0;u=u.parentElement}return!1}function St(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=n.getComputedStyle,a=r===void 0?(t=e.ownerDocument.defaultView)===null||t===void 0?void 0:t.getComputedStyle:r;if(typeof a!="function")throw new TypeError("Owner document of the element needs to have an associated window.");return e.hidden===!0||e.getAttribute("aria-hidden")==="true"||a(e).display==="none"}var Et=new Set(["button","fieldset","input","optgroup","option","select","textarea"]);function V(e){var t=d(e);return Et.has(t)&&e.hasAttribute("disabled")?!0:e.getAttribute("aria-disabled")==="true"}function Ne(){let e=new WeakMap;return((t,n)=>{if(n)return window.getComputedStyle(t,n);let r=e.get(t);return r||(r=window.getComputedStyle(t),e.set(t,r)),r})}function Le(){return document.documentElement.getClientRects().length>0}function Re(e,t,n){let r=t.display;if(r==="none")return!1;let a=t.visibility;if(a==="hidden"||a==="collapse"||Number(t.opacity)===0)return!1;if(n&&r!=="contents"){let o=e.getBoundingClientRect();if(o.width<=0||o.height<=0||e.getClientRects().length===0||o.right<-2e3||o.bottom<-2e3)return!1}return!0}function Oe(e){return e.pointerEvents!=="none"}var xt=new Set(["button","checkbox","combobox","link","listbox","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]),At=new Set(["BUTTON","INPUT","SELECT","TEXTAREA","SUMMARY"]);function G(e){let t=e.getAttribute("contenteditable");return t!==null&&t!=="false"}function Ce(e,t,n,r){let a=e.tagName;if(a==="A"&&e.hasAttribute("href")||At.has(a)||t!==null&&xt.has(t))return!0;let o=e.getAttribute("tabindex");return!!(o!==null&&Number(o)>=0||G(e)||n.cursor==="pointer"&&r?.cursor!=="pointer")}var Me=new Set(["button","cell","checkbox","columnheader","gridcell","heading","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","row","rowheader","switch","tab","tooltip","treeitem"]),Tt=new Set(["textbox","searchbox","spinbutton"]),wt=new Set(["INPUT","TEXTAREA"]);function Ie(e){return wt.has(e.tagName)||G(e)}function Nt(e,t){let n=e.tagName;return n==="INPUT"||n==="TEXTAREA"?Tt.has(t)?(e.value??"").length>0:!1:G(e)?(e.textContent??"").trim().length>0:!1}function we(e,t){let n=e.getAttribute(t);return n==="true"?"true":n==="mixed"?"mixed":null}function ke(e,t){let n=[],r=e.tagName;if(r==="INPUT"&&(t==="checkbox"||t==="radio"))e.checked&&n.push("[checked]");else{let l=we(e,"aria-checked");l==="mixed"?n.push("[checked=mixed]"):l==="true"&&n.push("[checked]")}V(e)&&n.push("[disabled]");let a=e.getAttribute("aria-expanded");if(a==="true"||a==="false")a==="true"&&n.push("[expanded]");else if(r==="SUMMARY"){let l=e.parentElement;l?.tagName==="DETAILS"&&l.open&&n.push("[expanded]")}if(t==="heading"){let l=e.getAttribute("aria-level"),u=Number(l||r[1]);Number.isFinite(u)&&u>0&&n.push(`[level=${u}]`)}let o=we(e,"aria-pressed");return o==="mixed"?n.push("[pressed=mixed]"):o==="true"&&n.push("[pressed]"),e.getAttribute("aria-selected")==="true"&&n.push("[selected]"),Nt(e,t)&&n.push("[filled]"),n.join(" ")}function Pe(e){return G(e)?"textbox":C(e)}var z='input,textarea,select,[contenteditable=""],[contenteditable="true"],[aria-valuetext],[data-mf-private]';function Lt(e){let t=e.getAttribute("aria-labelledby");if(t){for(let n of t.split(/\s+/)){if(!n)continue;let r=e.ownerDocument.getElementById(n);if(r&&(r.matches(z)||r.querySelector(z)))return!0}return!1}return e.hasAttribute("aria-label")?!1:e.querySelector(z)!==null}function De(e,t){let n=K(e,{getComputedStyle:t,computedStyleSupportsPseudoElements:!1});return n?Lt(e)?e.getAttribute("aria-label")||"":n:""}var Rt=0,q=0,Y=new WeakMap,j=new Map;function _e(){q++,j.clear()}function He(e,t,n){let r=`${t} ${n}`,a=Y.get(e);return!a||a.key!==r?(a={id:`e${++Rt}`,key:r,gen:q},Y.set(e,a)):a.gen=q,j.set(a.id,e),a.id}function Ot(e){let t=j.get(e);if(!t)return null;if(!t.isConnected)return j.delete(e),null;let n=Y.get(t);return!n||n.id!==e||n.gen!==q?null:t}function Ct(){j.clear()}var Mt=4e3,It=800,kt=120,Pt=120,Ge=25,$e=new Set(["generic","presentation","none"]),Dt=new Set(["SCRIPT","STYLE","NOSCRIPT","TEMPLATE","SVG","HEAD","LINK","META","BASE"]);function L(e){return e.nodes>=Mt||e.lines>=It?(e.truncated=!0,!1):!0}function _t(e){return e.id==="matterfact-embed"||e.hasAttribute("data-mf-embed")}function Ht(e,t,n){return e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden")||e.hasAttribute("inert")?!0:!Re(e,t,n)}function $t(e){if(e.shadowRoot)return e.shadowRoot.childNodes;if(e.tagName==="SLOT"){let t=e.assignedNodes({flatten:!0});if(t.length)return t}return e.childNodes}function Q(e,t,n,r){let a=$t(e);for(let o=0;o<a.length;o++){let l=a[o];l&&Wt(l,t,n,r)}}function Vt(e,t,n){let r=(e.nodeValue??"").replace(/\s+/g," ").trim();r&&(Me.has(t.role)||L(n)&&(n.lines++,t.children.push(r)))}function J(e){let t=e.matches(":disabled")||V(e);return{role:"option",name:(e.label||e.textContent||"").trim(),props:(t?" [disabled]":"")+(e.selected?" [selected]":""),children:[]}}function jt(e,t,n){let r=e.options,a=Math.min(r.length,Ge);for(let m=0;m<a;m++){if(!L(n))return;let p=r[m];!p||P(p)||(n.lines++,t.children.push(J(p)))}let o=0,l=e.selectedOptions;for(let m=0;m<l.length;m++){let p=l[m];if(p&&p.index>=a&&!P(p)){if(!L(n))return;n.lines++,t.children.push(J(p)),o++}}let u=r.length-a-o;u>0&&L(n)&&(n.lines++,t.children.push(`\u2026 (+${u} more options)`))}function Gt(e,t,n){let r=e.list;if(!r)return;let a=r.options,o=Math.min(a.length,Ge);for(let u=0;u<o;u++){if(!L(n))return;let m=a[u];!m||P(m)||(n.lines++,t.children.push(J(m)))}let l=a.length-o;l>0&&L(n)&&(n.lines++,t.children.push(`\u2026 (+${l} more options)`))}function qt(e,t,n,r){if(!L(r)||Dt.has(e.tagName)||_t(e)||P(e))return;r.nodes++;let a=r.styleOf(e);if(Ht(e,a,r.layout))return;let o=Pe(e),l=o===null||$e.has(o),u=Ce(e,o,a,n);if(l&&!u){Q(e,t,a,r);return}let m=o===null||$e.has(o)?"generic":o,p=De(e,r.styleOf),x="";if(u&&Oe(a)){let I=He(e,m,p);x=` [ref=${I}]`,r.onRef?.(I,e)}let M=ke(e,m),R={role:m,name:p,props:(M?` ${M}`:"")+x,children:[]};if(r.lines++,t.children.push(R),e.tagName==="SELECT"){jt(e,R,r);return}e.tagName==="INPUT"&&e.list&&Gt(e,R,r),!Ie(e)&&Q(e,R,a,r)}function Wt(e,t,n,r){e.nodeType===3?Vt(e,t,r):e.nodeType===1&&qt(e,t,n,r)}function Ve(e,t){let n=e.replace(/\s+/g," ").trim(),r=re(n);return r.length>t?`${r.slice(0,t-1)}\u2026`:r}function je(e){return`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function qe(e,t,n){let r=" ".repeat(t);for(let a of e){if(typeof a=="string"){n.push(`${r}- text: ${je(Ve(a,Pt))}`);continue}let o=a.name?` ${je(Ve(a.name,kt))}`:"",l=`${r}- ${a.role}${o}${a.props}`;a.children.length?(n.push(`${l}:`),qe(a.children,t+1,n)):n.push(l)}}function We(e,t){let n=Ne(),r={styleOf:n,layout:Le(),nodes:0,lines:0,truncated:!1,onRef:t};if(Te(e,{getComputedStyle:n}))return{yaml:"",truncated:!1};let a={role:"",name:"",props:"",children:[]};Q(e,a,n(e),r);let o=[];return qe(a.children,0,o),r.truncated&&o.length&&(o[o.length-1]='- text: "\u2026 (snapshot truncated \u2014 more of the page is below)"'),{yaml:o.join(`
|
|
2
2
|
`),truncated:r.truncated}}function wn(){let e=document.body;if(!e)return{yaml:"",truncated:!1,visibleRefs:[]};_e();let t=[],n=window.innerHeight||0,r=window.innerWidth||0;return{...We(e,(o,l)=>{let u=l.getBoundingClientRect();u.bottom>0&&u.top<n&&u.right>0&&u.left<r&&t.push(o)}),visibleRefs:t}}function Nn(e){return e.isConnected?We(e):{yaml:"",truncated:!1}}export{Ct as clearRefs,Ot as resolveRef,wn as snapshot,Nn as snapshotRegion};
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
3
|
+
//# sourceMappingURL=chunk-GZZYR6YF.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c="";var p=null,R=0,l=[],S="",b=!0,g=null,h=null,y=null,x=null,M=[/\b[\w.+-]+@[\w-]+\.[\w.]{2,}\b/g,/\b(?:\d[ -]?){13,19}\b/g,/\b\d{3}[- ]?\d{2}[- ]?\d{4}\b/g,/\b\d{9,}\b/g,/(?:\+?\d{1,2}[\s.-]?)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\b/g,/\b(?:sk|pk|rk|ak)_(?:live|test)_[A-Za-z0-9]{8,}\b/g,/\beyJ[\w-]+\.[\w-]+\.[\w-]+\b/g];function s(t){let e=t;for(let n of M)e=e.replace(n,"[redacted]");return e}function v(t){if(t.closest("[data-mf-private]"))return!0;if(t.tagName==="INPUT"){let n=t.type;if(n==="password"||n==="hidden")return!0}return!1}function L(t){let e=t.match(/^\/(?:embed\/)?artifacts\/(.+?)\/?$/);return e?decodeURIComponent(e[1]):null}function q(){if(!c)return[];let t=[];for(let e of Array.from(document.querySelectorAll("iframe"))){let n;try{n=new URL(e.getAttribute("src")||"",location.href)}catch{continue}if(n.origin!==c)continue;let r=L(n.pathname);r&&(t.some(o=>o.id===r)||t.push({kind:"artifact",id:r,label:s(e.getAttribute("title")||"")||r}))}return t}function F(){return Array.from(document.querySelectorAll("iframe")).filter(t=>{try{let e=new URL(t.getAttribute("src")||"",location.href);return e.origin!==location.origin&&e.origin!==c}catch{return!1}}).length}function N(){let t=window.matterfact?.context??{},e=q(),n=F();return{url:location.origin+location.pathname,path:location.pathname,title:s(document.title),locale:document.documentElement.lang||void 0,...t,entities:[...t.entities??[],...e],data:{...t.data??{},...n?{opaque_frames:n}:{}}}}function T(){p?.({type:"host.context",context:N()})}function $(t,e){let n=[];for(let r of t){let o;try{o=new URL(r||"",location.href)}catch{continue}if(o.origin!==e)continue;let i=L(o.pathname);if(!i)continue;let a=o.searchParams.get("owner")||"",A=o.searchParams.get("t")||"";!a||!A||n.some(P=>P.id===i)||n.push({id:i,owner:a,token:A})}return n}function U(){if(!c)return[];let t=Array.from(document.querySelectorAll("iframe")).map(e=>e.getAttribute("src")||"");return $(t,c)}function C(){p?.({type:"host.artifactGrants",grants:U()})}function E(t){l.push({...t,seq:++R,ts:Date.now()}),l.length>40&&l.shift(),p?.({type:"host.activity",events:[l[l.length-1]]})}function O(t){let e=t.getAttribute("aria-label");if(e)return e;let n=t.id;if(n){let a=document.querySelector(`label[for="${CSS.escape(n)}"]`)?.textContent?.trim();if(a)return a}let r=t.closest("label")?.textContent?.trim();if(r)return r;let o=t.getAttribute("placeholder");return o||""}var G=new Set(["INPUT","SELECT","TEXTAREA"]);function u(t){let e=t.getAttribute("role")||t.tagName.toLowerCase(),n=t.getAttribute("aria-label")||(G.has(t.tagName)?O(t):t.innerText?.trim().slice(0,60))||t.getAttribute("title")||"";return n?`${e} "${s(n)}"`:e}var _='a[href],button,input,select,textarea,summary,[role="button"],[role="link"],[role="menuitem"],[role="tab"],[role="option"],[role="checkbox"],[role="switch"],[role="radio"],[onclick],[tabindex]';function k(t){let e=t.target;if(!e||!(e instanceof Element))return;let n=e.closest("label"),o=(n?n.getAttribute("for")&&document.getElementById(n.getAttribute("for"))||n.querySelector("input,select,textarea"):null)??e.closest(_);!o||v(o)||E({type:"click",summary:`clicked ${u(o)}`})}function I(t){let e=t.target;!e||v(e)||E({type:"submit",summary:`submitted ${u(e)}`})}function H(t){let e=t.target;if(!e||!(e instanceof Element)||v(e))return;let n=e.tagName,r=e.type;if(n==="INPUT"&&(r==="password"||r==="hidden"))return;let o=`changed ${u(e)}`;if(n==="SELECT"){let i=e.selectedOptions[0]?.text;i&&(o=`${u(e)} \u2192 "${s(i)}"`)}else(r==="checkbox"||r==="radio")&&(o=`${e.checked?"checked":"unchecked"} ${u(e)}`);E({type:"input",summary:o})}function X(){let t=()=>{let e=location.pathname;e!==S&&(S=e,E({type:"nav",summary:`navigated to ${e}`}),T(),C())};g=t;for(let e of["pushState","replaceState"]){let n=history[e];e==="pushState"?h=n:y=n,history[e]=function(...r){let o=n.apply(this,r);return t(),o}}window.addEventListener("popstate",t)}var d={};async function B(){let t={},e=window.getSelection?.();if(e&&!e.isCollapsed){let i=e.anchorNode?.parentElement??null;if(!i||!i.closest("[data-mf-private]")){let a=e.toString().trim().slice(0,500);a&&(t.selection=s(a))}}let n=document.activeElement;if(n&&n!==document.body&&!v(n)&&!n.closest("[data-mf-private]")){let{snapshot:i}=await w();t.focused={label:s(V(n)),role:n.getAttribute("role")||n.tagName.toLowerCase()}}let r=document.documentElement,o=r.scrollHeight-r.clientHeight;return t.scroll=o>0?Math.round(r.scrollTop/o*100)/100:0,t}function V(t){return u(t)}async function w(){let t=await import("./chunk-GZZYR6YF.js");return x=t,t}var f=null;function m(){f||(f=setTimeout(async()=>{f=null,d=await B(),p?.({type:"host.focus",focus:d})},250))}var W=0;async function z(t){if(!b)return;let{snapshot:e}=await w(),{yaml:n,truncated:r,visibleRefs:o}=e();t({type:"host.snapshot",snapshot:{yaml:s(n),seq:++W,truncated:r}}),d={...d,visibleRefs:o},t({type:"host.focus",focus:d})}async function D(t,e){if(!b)return;let{snapshotRegion:n,resolveRef:r}=await w(),o=r(t);if(!o){e({type:"host.region",ref:t,yaml:"(this element is no longer on the page)"});return}let{yaml:i}=n(o);e({type:"host.region",ref:t,yaml:s(i)})}async function J(t,e){e({type:"host.toolResult",callId:t.callId,ok:!1,error:"Host tools are read-only in this version; no action was taken."})}function Y(){document.removeEventListener("click",k,{capture:!0}),document.removeEventListener("submit",I,{capture:!0}),document.removeEventListener("change",H,{capture:!0}),document.removeEventListener("selectionchange",m),document.removeEventListener("focusin",m,{capture:!0}),window.removeEventListener("scroll",m,{capture:!0}),g&&(window.removeEventListener("popstate",g),g=null),h&&(history.pushState=h,h=null),y&&(history.replaceState=y,y=null),f&&(clearTimeout(f),f=null),p=null,l.length=0,d={},c="",x?.clearRefs()}function Z(t,e,n=!0){Y(),p=t,c=e||"",S=location.pathname,b=n,b&&(T(),C(),X(),document.addEventListener("click",k,{capture:!0,passive:!0}),document.addEventListener("submit",I,{capture:!0,passive:!0}),document.addEventListener("change",H,{capture:!0,passive:!0}),document.addEventListener("selectionchange",m,{passive:!0}),document.addEventListener("focusin",m,{capture:!0,passive:!0}),window.addEventListener("scroll",m,{capture:!0,passive:!0}));let r=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";t({type:"host.theme",mode:r})}export{s as a,v as b,L as c,N as d,$ as e,z as f,D as g,J as h,Y as i,Z as j};
|
|
2
|
+
//# sourceMappingURL=chunk-JN3ZMONO.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/context.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n ActivityEvent,\n FocusContext,\n HostToWidget,\n PageContext,\n PageEntity,\n ToolCall,\n} from './protocol';\n\n/** The origin serving our chat \u2014 how we tell OUR embedded content from the host's own\n * iframes. Set by start(); empty until then, which just means we spot nothing. */\nlet widgetOrigin = '';\n\n/**\n * The eye.\n *\n * Everything in this module can see the customer's page. It is a SEPARATE CHUNK,\n * loaded only when someone actually opens the chat \u2014 so a page whose visitors never\n * click the widget pays nothing for any of it, and a security reviewer can read\n * exactly one file to know what we look at.\n *\n * The rules, which are not negotiable:\n *\n * NEVER captured \u2014 no config enables it: the value of any <input>, <textarea> or\n * contenteditable; anything inside a password field; cookies; localStorage;\n * sessionStorage; the raw DOM; screenshots; network traffic; anything inside an\n * element marked `data-mf-private`.\n *\n * The agent never gets a selector and never touches the DOM. It gets refs. A ref\n * is resolved to an element HERE, in the page, by us.\n */\n\ntype Send = (msg: HostToWidget) => void;\n\nconst MAX_ACTIVITY = 40;\n\nlet send: Send | null = null;\nlet activitySeq = 0;\nconst activity: ActivityEvent[] = [];\nlet lastUrl = '';\n/** Set once by `start()`. False \u21D2 the host opted out of ALL page observation \u2014 every\n * exported entry point below that would otherwise read or send the page checks this. */\nlet pageContextOn = true;\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 teardown state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n/**\n * Everything below is module-global bookkeeping so `stop()` (see `start()`, bottom of\n * file) can undo exactly what `start()`/`watchNavigation()` installed \u2014 remove every\n * listener, restore `history` to what it was before we wrapped it, and forget any\n * DOM-walk module we pulled in. All of this outlives a single `EmbedHost`; see\n * `stop()`'s doc comment for why that's the bug this exists to close.\n */\n\n/** The `fire` closure `watchNavigation()` handed to `popstate` \u2014 the only handle we\n * have to remove that listener again. */\nlet navFire: (() => void) | null = null;\n/** The `history.pushState`/`replaceState` this module wrapped, captured so `stop()`\n * can restore them EXACTLY rather than re-wrapping (which is how the old code\n * double-fired navigation on a second `start()`). */\nlet origPushState: History['pushState'] | null = null;\nlet origReplaceState: History['replaceState'] | null = null;\n/** Set once `sendSnapshot`/`sendRegion`/`readFocus` actually pull in the DOM-walk\n * chunk (`./dom/snapshot`) \u2014 never imported eagerly, so `stop()` doesn't pay for a\n * chunk that a host who only ever opted out (and never opened a snapshot) never\n * loaded in the first place. */\nlet snapshotModule: { clearRefs: () => void } | null = null;\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 redaction \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nconst PII = [\n /\\b[\\w.+-]+@[\\w-]+\\.[\\w.]{2,}\\b/g, // email\n /\\b(?:\\d[ -]?){13,19}\\b/g, // card-ish\n /\\b\\d{3}[- ]?\\d{2}[- ]?\\d{4}\\b/g, // ssn \u2014 dashed, spaced, OR bare 9 digits\n /\\b\\d{9,}\\b/g, // long bare digit runs: account / MRN / routing numbers\n /(?:\\+?\\d{1,2}[\\s.-]?)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}\\b/g, // us phone\n /\\b(?:sk|pk|rk|ak)_(?:live|test)_[A-Za-z0-9]{8,}\\b/g, // stripe-style api keys\n /\\beyJ[\\w-]+\\.[\\w-]+\\.[\\w-]+\\b/g, // jwt\n];\n\n/**\n * Scrub before anything leaves the page \u2014 not after it arrives.\n *\n * A compromised widget, or a bug in ours, must not be able to retroactively obtain\n * a customer's users' email addresses. The only way to guarantee that is to never\n * put them on the wire.\n */\nexport function redact(text: string): string {\n let out = text;\n for (const re of PII) out = out.replace(re, '[redacted]');\n return out;\n}\n\n/** Anything the host has marked private, or that is inherently sensitive, is out. */\nexport function isPrivate(el: Element): boolean {\n if (el.closest('[data-mf-private]')) return true;\n const tag = el.tagName;\n if (tag === 'INPUT') {\n const t = (el as HTMLInputElement).type;\n if (t === 'password' || t === 'hidden') return true;\n }\n return false;\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 page context \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n/**\n * What the page says about itself.\n *\n * A host that declares nothing still gets URL + title, which is what every other\n * embeddable assistant on the market offers in total. The interesting fields\n * (`route`, `description`, `entities`) are host-declared, because only the host\n * knows that `/o/8813` is \"the Acme Corp order, 3 items, unpaid\".\n *\n * Declared via a global the host sets before we load:\n * window.matterfact = { context: { route: '/orders/:id', description: '...', entities: [...] } }\n */\n/**\n * matterfact content embedded IN the host page \u2014 today, artifact iframes.\n *\n * A cross-origin iframe is opaque: `contentDocument` throws, so the DOM snapshot walks\n * straight past an embedded artifact and the agent is blind to the very thing the page\n * is built around. It reads the page as empty and asks which URL you mean.\n *\n * We don't need to see inside, and shouldn't want to. The artifact's ID is right there\n * in the src, and the agent can already resolve `artifacts/<id>/` in its session \u2014 the\n * same path an `@`-mention uses. So we report the ID and let the backend fetch the real\n * thing, which beats scraping a rendering of it: it gets the data, not the picture.\n *\n * Matched by ORIGIN, not by path shape: a customer is perfectly entitled to their own\n * /artifacts/ route, and it isn't ours.\n */\n/** The artifact slug from a matterfact artifact path, or null. Matches both the\n * chrome-free embed route (/embed/artifacts/<slug>) and the bare /artifacts/<slug>. */\nexport function artifactIdFromPath(pathname: string): string | null {\n const m = pathname.match(/^\\/(?:embed\\/)?artifacts\\/(.+?)\\/?$/);\n return m ? decodeURIComponent(m[1]) : null;\n}\n\nfunction embeddedMatterfactEntities(): PageEntity[] {\n if (!widgetOrigin) return [];\n const out: PageEntity[] = [];\n for (const frame of Array.from(document.querySelectorAll('iframe'))) {\n let u: URL;\n try {\n u = new URL(frame.getAttribute('src') || '', location.href);\n } catch {\n continue;\n }\n if (u.origin !== widgetOrigin) continue;\n const id = artifactIdFromPath(u.pathname);\n if (!id) continue;\n if (out.some((e) => e.id === id)) continue; // same artifact twice = once\n // No url field: the agent reaches an artifact by ID (`artifacts/<id>/`), never by\n // fetching the page, and an artifact URL can carry a share token we've no business\n // forwarding. The id is the whole useful payload.\n out.push({\n kind: 'artifact',\n id,\n label: redact(frame.getAttribute('title') || '') || id,\n });\n }\n return out;\n}\n\n/**\n * Frames we can see the existence of but nothing inside \u2014 someone else's cross-origin\n * embed. Worth one line: \"there is a thing here I cannot read\" is a true and useful\n * statement, and much better than the agent confidently describing a page while missing\n * the widget the user is actually asking about.\n */\nfunction opaqueFrameCount(): number {\n return Array.from(document.querySelectorAll('iframe')).filter((f) => {\n try {\n const u = new URL(f.getAttribute('src') || '', location.href);\n return u.origin !== location.origin && u.origin !== widgetOrigin;\n } catch {\n return false;\n }\n }).length;\n}\n\nexport function readPageContext(): PageContext {\n const declared =\n (window as { matterfact?: { context?: PageContext } }).matterfact\n ?.context ?? {};\n\n const found = embeddedMatterfactEntities();\n const opaque = opaqueFrameCount();\n\n return {\n // Path only. A query string is where session ids, tokens and email addresses\n // live; it is not ours to take.\n url: location.origin + location.pathname,\n path: location.pathname,\n title: redact(document.title),\n locale: document.documentElement.lang || undefined,\n ...declared,\n // After the spread: what we FOUND is additive to what the host DECLARED, never a\n // replacement. A host that declares its own entities still gets the artifacts we\n // spotted, and vice versa.\n entities: [...(declared.entities ?? []), ...found],\n data: {\n ...(declared.data ?? {}),\n ...(opaque ? { opaque_frames: opaque } : {}),\n },\n };\n}\n\nfunction publishContext() {\n send?.({ type: 'host.context', context: readPageContext() });\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 artifact grants (backend-only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nexport interface ArtifactGrantSrc {\n id: string;\n owner: string;\n token: string;\n}\n\n/** Read-only capability grants from co-embedded artifact iframes, for the backend to\n * materialize their data. Separate from entities on purpose: the token must never ride\n * ambient (rendered) context, only this backend-only channel. */\nexport function grantsFromIframeSrcs(\n srcs: string[],\n origin: string,\n): ArtifactGrantSrc[] {\n const out: ArtifactGrantSrc[] = [];\n for (const raw of srcs) {\n let u: URL;\n try {\n u = new URL(raw || '', location.href);\n } catch {\n continue;\n }\n if (u.origin !== origin) continue;\n const id = artifactIdFromPath(u.pathname);\n if (!id) continue;\n const owner = u.searchParams.get('owner') || '';\n const token = u.searchParams.get('t') || '';\n if (!owner || !token) continue;\n if (out.some((g) => g.id === id)) continue;\n out.push({ id, owner, token });\n }\n return out;\n}\n\nfunction readArtifactGrants(): ArtifactGrantSrc[] {\n if (!widgetOrigin) return [];\n const srcs = Array.from(document.querySelectorAll('iframe')).map(\n (f) => f.getAttribute('src') || '',\n );\n return grantsFromIframeSrcs(srcs, widgetOrigin);\n}\n\nfunction publishArtifactGrants() {\n send?.({ type: 'host.artifactGrants', grants: readArtifactGrants() });\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 activity \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction pushActivity(e: Omit<ActivityEvent, 'seq' | 'ts'>) {\n activity.push({ ...e, seq: ++activitySeq, ts: Date.now() });\n if (activity.length > MAX_ACTIVITY) activity.shift();\n send?.({ type: 'host.activity', events: [activity[activity.length - 1]] });\n}\n\n/**\n * A short, human-readable label for what got clicked.\n *\n * Shaped after PostHog's autocapture, not after a session-replay frame: rrweb would\n * give us `{source:2, type:2, id:417, x:210, y:88}` \u2014 no text, no role, no href,\n * meaningless to a model without the full DOM snapshot it deltas against. One line\n * of \"clicked button 'Export CSV'\" is worth more and costs less.\n */\n/**\n * The accessible NAME of a form control \u2014 never its value.\n *\n * A control has no `innerText`, so the generic path below misses it. We look where a\n * control's name actually lives: `aria-label`, then a `<label for>` or a wrapping\n * `<label>`, then `placeholder`. `placeholder` is a LABEL, not a value \u2014 it is the\n * hint shown when the field is empty (\"Order number or customer\"), so it is safe.\n */\nfunction controlLabel(el: Element): string {\n const aria = el.getAttribute('aria-label');\n if (aria) return aria;\n\n const id = el.id;\n if (id) {\n const forLabel = document.querySelector(`label[for=\"${CSS.escape(id)}\"]`);\n const t = forLabel?.textContent?.trim();\n if (t) return t;\n }\n const wrapping = el.closest('label')?.textContent?.trim();\n if (wrapping) return wrapping;\n\n const placeholder = el.getAttribute('placeholder');\n if (placeholder) return placeholder;\n\n return '';\n}\n\nconst FORM_CONTROLS = new Set(['INPUT', 'SELECT', 'TEXTAREA']);\n\nfunction describe(el: Element): string {\n const role = el.getAttribute('role') || el.tagName.toLowerCase();\n const label =\n el.getAttribute('aria-label') ||\n (FORM_CONTROLS.has(el.tagName)\n ? controlLabel(el)\n : (el as HTMLElement).innerText?.trim().slice(0, 60)) ||\n el.getAttribute('title') ||\n '';\n return label ? `${role} \"${redact(label)}\"` : role;\n}\n\n/**\n * Elements a click is worth recording. Deliberately tight: the point of the activity\n * stream is INTENT (\"the user chose to export\"), and a click on a heading, a label,\n * a card gutter, or blank page is not intent, it is noise. We only log a click that\n * lands on something actionable.\n */\nconst ACTIONABLE =\n 'a[href],button,input,select,textarea,summary,' +\n '[role=\"button\"],[role=\"link\"],[role=\"menuitem\"],[role=\"tab\"],[role=\"option\"],' +\n '[role=\"checkbox\"],[role=\"switch\"],[role=\"radio\"],[onclick],[tabindex]';\n\nfunction onClick(ev: Event) {\n const target = ev.target as Element | null;\n if (!target || !(target instanceof Element)) return;\n\n // Clicking a <label> operates the control it labels \u2014 record THAT, not \"clicked\n // label\", so the event reads as the user's actual intent.\n const label = target.closest('label');\n const labelled = label\n ? (label.getAttribute('for') &&\n document.getElementById(label.getAttribute('for')!)) ||\n label.querySelector('input,select,textarea')\n : null;\n\n const actionable = labelled ?? target.closest(ACTIONABLE);\n // No actionable target \u2014 a click on text, a gutter, or blank space. That is not an\n // action; dropping it is the whole fix for the click-log noise.\n if (!actionable || isPrivate(actionable)) return;\n\n pushActivity({ type: 'click', summary: `clicked ${describe(actionable)}` });\n}\n\nfunction onSubmit(ev: Event) {\n const el = ev.target as Element | null;\n if (!el || isPrivate(el)) return;\n // The FORM was submitted \u2014 never its values.\n pushActivity({ type: 'submit', summary: `submitted ${describe(el)}` });\n}\n\n/**\n * A form field changed.\n *\n * The rule is the same as everywhere else and the temptation here is sharpest:\n * record THAT a field changed and WHICH field (its label), never WHAT it was\n * changed to. `change` fires on exactly the elements whose values are off-limits.\n *\n * One safe exception: a <select>, a checkbox, or a radio chose from a fixed, visible\n * set of options the agent can already see in the snapshot \u2014 \"Unpaid\", \"Shipped\".\n * That is a user *choice*, not typed data, so the chosen option's LABEL is fair to\n * include and is the useful part (\"filtered status to Shipped\"). Free-text and\n * numeric inputs get their label only.\n */\nfunction onChange(ev: Event) {\n const el = ev.target as (HTMLElement & { type?: string }) | null;\n if (!el || !(el instanceof Element) || isPrivate(el)) return;\n\n const tag = el.tagName;\n const type = (el as HTMLInputElement).type;\n\n // Never a password/hidden field, and isPrivate already covered data-mf-private.\n if (tag === 'INPUT' && (type === 'password' || type === 'hidden')) return;\n\n let summary = `changed ${describe(el)}`;\n\n if (tag === 'SELECT') {\n const opt = (el as HTMLSelectElement).selectedOptions[0]?.text;\n if (opt) summary = `${describe(el)} \u2192 \"${redact(opt)}\"`;\n } else if (type === 'checkbox' || type === 'radio') {\n summary = `${(el as HTMLInputElement).checked ? 'checked' : 'unchecked'} ${describe(el)}`;\n }\n\n pushActivity({ type: 'input', summary });\n}\n\n/**\n * SPA navigation. There is no event for `pushState`, so we wrap it \u2014 a 20-line job\n * that no library does better.\n */\nfunction watchNavigation() {\n const fire = () => {\n const url = location.pathname;\n if (url === lastUrl) return;\n lastUrl = url;\n pushActivity({ type: 'nav', summary: `navigated to ${url}` });\n publishContext();\n publishArtifactGrants();\n };\n // Captured so stop() can remove exactly this listener, and so history.pushState/\n // replaceState get restored to what they were before we wrapped them \u2014 never\n // re-wrapped on top of an existing wrap (that was the pre-existing bug: a second\n // start() used to wrap the ALREADY-wrapped methods, double-firing every nav).\n navFire = fire;\n\n for (const name of ['pushState', 'replaceState'] as const) {\n const orig = history[name];\n if (name === 'pushState') origPushState = orig as History['pushState'];\n else origReplaceState = orig as History['replaceState'];\n history[name] = function (\n this: History,\n ...args: Parameters<History['pushState']>\n ) {\n const r = orig.apply(this, args);\n fire();\n return r;\n } as History[typeof name];\n }\n window.addEventListener('popstate', fire);\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 focal context \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n/**\n * Where the user's attention is, right now.\n *\n * This is the \"knows what you're doing\" layer, and it is deliberately small so it can\n * ride on every turn \u2014 where the full snapshot cannot. It is also the most sensitive:\n * `selection` is whatever the user highlighted, which could be their own email, so it\n * is redacted and respects data-mf-private like everything else. Focus and the\n * viewport are labels and refs \u2014 never a value.\n *\n * Held so the last-known focus can travel with a turn even between the (throttled)\n * push updates.\n */\nlet lastFocus: FocusContext = {};\n\nasync function readFocus(): Promise<FocusContext> {\n const focus: FocusContext = {};\n\n // Selection \u2014 the single strongest \"this is what I'm asking about\" signal.\n const sel = window.getSelection?.();\n if (sel && !sel.isCollapsed) {\n const anchor = sel.anchorNode?.parentElement ?? null;\n // Don't lift a selection out of a private region, and cap it \u2014 a user can select\n // the whole page.\n if (!anchor || !anchor.closest('[data-mf-private]')) {\n const text = sel.toString().trim().slice(0, 500);\n if (text) focus.selection = redact(text);\n }\n }\n\n // The control they're working in \u2014 its label, never its contents.\n const active = document.activeElement;\n if (\n active &&\n active !== document.body &&\n !isPrivate(active) &&\n !active.closest('[data-mf-private]')\n ) {\n const { snapshot } = await loadSnapshotModule();\n void snapshot; // ensure the chunk that owns refFor is loaded before we describe\n focus.focused = {\n label: redact(describeControl(active)),\n role: active.getAttribute('role') || active.tagName.toLowerCase(),\n };\n }\n\n const doc = document.documentElement;\n const scrollable = doc.scrollHeight - doc.clientHeight;\n focus.scroll =\n scrollable > 0 ? Math.round((doc.scrollTop / scrollable) * 100) / 100 : 0;\n\n return focus;\n}\n\n/** A label for whatever is focused, reusing the same value-blind rules as activity. */\nfunction describeControl(el: Element): string {\n return describe(el);\n}\n\n/** The one place any of the three call sites below reach into the DOM-walk chunk \u2014\n * so `stop()` has a single `snapshotModule` to check without importing anything\n * itself (see the teardown-state block above). */\nasync function loadSnapshotModule() {\n const m = await import('./dom/snapshot');\n snapshotModule = m;\n return m;\n}\n\nlet focusTimer: ReturnType<typeof setTimeout> | null = null;\n\n/** Coalesce a burst of selection/focus/scroll events into one push. */\nfunction scheduleFocus() {\n if (focusTimer) return;\n focusTimer = setTimeout(async () => {\n focusTimer = null;\n lastFocus = await readFocus();\n send?.({ type: 'host.focus', focus: lastFocus });\n }, 250);\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 snapshot \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nlet snapshotSeq = 0;\n\nexport async function sendSnapshot(emit: Send) {\n // pageContext: false \u21D2 no snapshot, ever \u2014 a `widget.requestSnapshot` must not be\n // able to reintroduce the page observation the host explicitly turned off.\n if (!pageContextOn) return;\n // The a11y walk is itself lazily imported: a host that only ever declares\n // PageContext and never lets the agent look at the page never downloads it.\n const { snapshot } = await loadSnapshotModule();\n const { yaml, truncated, visibleRefs } = snapshot();\n emit({\n type: 'host.snapshot',\n snapshot: { yaml: redact(yaml), seq: ++snapshotSeq, truncated },\n });\n // The viewport slice rides with the focus context so the agent can tell the few\n // things on screen from the whole tree it just received.\n lastFocus = { ...lastFocus, visibleRefs };\n emit({ type: 'host.focus', focus: lastFocus });\n}\n\n/**\n * Zoom in on one ref \u2014 the pull half of the model. The agent asks; we resolve the ref\n * to a live element and return just its sub-tree.\n */\nexport async function sendRegion(ref: string, emit: Send) {\n // Mirrors sendSnapshot's guard: a `widget.readRegion` for a ref minted before\n // opt-out must not pull a live DOM subtree just because the ref is still\n // resolvable (see refs.ts's `clearRefs`, which `stop()` also uses as a backstop).\n if (!pageContextOn) return;\n const { snapshotRegion, resolveRef } = await loadSnapshotModule();\n const el = resolveRef(ref);\n if (!el) {\n emit({\n type: 'host.region',\n ref,\n yaml: '(this element is no longer on the page)',\n });\n return;\n }\n const { yaml } = snapshotRegion(el);\n emit({ type: 'host.region', ref, yaml: redact(yaml) });\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 tools \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n/**\n * v1 IS READ-ONLY.\n *\n * The page's content is untrusted \u2014 text on it can try to instruct the agent \u2014 and\n * the moment the agent can act, a bad answer becomes a bad ACTION. So no tool here\n * mutates the page yet. The call path exists, and the enforcement point is HERE (in\n * the page, where we control what actually happens) rather than in the widget, which\n * can be lied to.\n *\n * When write tools land: anything not `readOnly` gets a user confirmation, on every\n * call. Not \"unless the host opts out\" \u2014 every call, because the trigger may have\n * been written by the page.\n */\nexport async function callTool(call: ToolCall, emit: Send) {\n emit({\n type: 'host.toolResult',\n callId: call.callId,\n ok: false,\n error: 'Host tools are read-only in this version; no action was taken.',\n });\n}\n\n/* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 stop / start \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n/**\n * The opposite number of `start()` \u2014 remove every listener it (or `watchNavigation`)\n * installed, restore `history.pushState`/`replaceState` to what they were before we\n * wrapped them, and forget the module-level `send`/`activity`/focus state. Nothing\n * here is a filter over what gets sent afterward \u2014 there is simply nothing left\n * installed to send anything.\n *\n * Why this has to exist at all: everything `start()` installs is MODULE-GLOBAL, and\n * this module outlives any single `EmbedHost`. React remounts `EmbedHost` whenever\n * ANY of its identity-defining props change (react.tsx's effect deps: publishableKey,\n * widgetOrigin, surface, theme, inline, pageContext, dev) \u2014 including just a theme\n * swap, not only a deliberate opt-out. Before this fix, a remount's `start()` call\n * only ever ADDED listeners; the previous mount's were still attached and kept firing\n * into the module `send`, which the new `start()` had just repointed at the NEW\n * widget. Net effect: open once with pageContext on, then remount for any reason\n * (including `pageContext: false`) and the new widget silently keeps receiving\n * clicks/nav/focus collected by the old mount's still-live listeners.\n *\n * Called from two places: the top of `start()` (idempotency \u2014 a second `start()`\n * never doubles up, which also fixes the pre-existing double history-wrap /\n * double-`fire()`-per-navigation bug), and `EmbedHost.destroy()` in loader.ts (a\n * plain unmount with no remount still has to stop, not just wait for a `start()`\n * that may never come).\n */\nexport function stop(): void {\n document.removeEventListener('click', onClick, { capture: true });\n document.removeEventListener('submit', onSubmit, { capture: true });\n document.removeEventListener('change', onChange, { capture: true });\n document.removeEventListener('selectionchange', scheduleFocus);\n document.removeEventListener('focusin', scheduleFocus, { capture: true });\n window.removeEventListener('scroll', scheduleFocus, { capture: true });\n\n if (navFire) {\n window.removeEventListener('popstate', navFire);\n navFire = null;\n }\n // Restore, don't re-wrap: this is what stops a repeated start() from wrapping an\n // already-wrapped pushState/replaceState (the old double-fire-per-nav bug).\n if (origPushState) {\n history.pushState = origPushState;\n origPushState = null;\n }\n if (origReplaceState) {\n history.replaceState = origReplaceState;\n origReplaceState = null;\n }\n\n if (focusTimer) {\n clearTimeout(focusTimer);\n focusTimer = null;\n }\n\n send = null;\n activity.length = 0;\n lastFocus = {};\n widgetOrigin = '';\n\n // Belt-and-suspenders alongside sendRegion's own pageContextOn check (see above):\n // an old ref minted while observation was on must not stay resolvable afterward.\n // Only touches the DOM-walk chunk if it was ever actually loaded \u2014 see\n // loadSnapshotModule's doc comment.\n snapshotModule?.clearRefs();\n}\n\n/**\n * @param pageContext Whether to observe the host page at all. Default `true`. False is\n * the loader's `pageContext: false` opt-out reaching all the way down here: skip every\n * bit of page reading below \u2014 no declared/found context, no artifact grants, no nav/\n * click/submit/change/focus observers \u2014 so there is nothing to send and nothing that\n * could later be asked for (see `widget.requestSnapshot` in loader.ts). Theme detection\n * is unaffected: it reads an OS media query, never the page, so it isn't page context.\n */\nexport function start(emit: Send, origin?: string, pageContext = true) {\n // Idempotent: undo whatever a PREVIOUS start() installed before this one installs\n // anything. Without this, a remount (see stop()'s doc comment) leaves the old\n // mount's listeners live, writing into the `send` this call is about to reassign.\n stop();\n\n send = emit;\n widgetOrigin = origin || '';\n lastUrl = location.pathname;\n pageContextOn = pageContext;\n\n if (pageContextOn) {\n publishContext();\n publishArtifactGrants();\n watchNavigation();\n\n // Passive + capture: we observe, we never interfere with the host's own handling.\n document.addEventListener('click', onClick, {\n capture: true,\n passive: true,\n });\n document.addEventListener('submit', onSubmit, {\n capture: true,\n passive: true,\n });\n // `change` fires on blur/commit for text inputs and immediately for select/\n // checkbox/radio \u2014 not on every keystroke, which is what we want: a settled\n // choice, not a stream of partial values.\n document.addEventListener('change', onChange, {\n capture: true,\n passive: true,\n });\n\n // Focal context: what the user is attending to. Coalesced (scheduleFocus), because\n // selectionchange and scroll fire in torrents.\n document.addEventListener('selectionchange', scheduleFocus, {\n passive: true,\n });\n document.addEventListener('focusin', scheduleFocus, {\n capture: true,\n passive: true,\n });\n window.addEventListener('scroll', scheduleFocus, {\n capture: true,\n passive: true,\n });\n }\n\n const theme = matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light';\n emit({ type: 'host.theme', mode: theme });\n}\n"],
|
|
5
|
+
"mappings": "AAWA,IAAIA,EAAe,GAyBnB,IAAIC,EAAoB,KACpBC,EAAc,EACZC,EAA4B,CAAC,EAC/BC,EAAU,GAGVC,EAAgB,GAchBC,EAA+B,KAI/BC,EAA6C,KAC7CC,EAAmD,KAKnDC,EAAmD,KAIjDC,EAAM,CACV,kCACA,0BACA,iCACA,cACA,6DACA,qDACA,gCACF,EASO,SAASC,EAAOC,EAAsB,CAC3C,IAAIC,EAAMD,EACV,QAAWE,KAAMJ,EAAKG,EAAMA,EAAI,QAAQC,EAAI,YAAY,EACxD,OAAOD,CACT,CAGO,SAASE,EAAUC,EAAsB,CAC9C,GAAIA,EAAG,QAAQ,mBAAmB,EAAG,MAAO,GAE5C,GADYA,EAAG,UACH,QAAS,CACnB,IAAMC,EAAKD,EAAwB,KACnC,GAAIC,IAAM,YAAcA,IAAM,SAAU,MAAO,EACjD,CACA,MAAO,EACT,CAgCO,SAASC,EAAmBC,EAAiC,CAClE,IAAMC,EAAID,EAAS,MAAM,qCAAqC,EAC9D,OAAOC,EAAI,mBAAmBA,EAAE,CAAC,CAAC,EAAI,IACxC,CAEA,SAASC,GAA2C,CAClD,GAAI,CAACC,EAAc,MAAO,CAAC,EAC3B,IAAMT,EAAoB,CAAC,EAC3B,QAAWU,KAAS,MAAM,KAAK,SAAS,iBAAiB,QAAQ,CAAC,EAAG,CACnE,IAAIC,EACJ,GAAI,CACFA,EAAI,IAAI,IAAID,EAAM,aAAa,KAAK,GAAK,GAAI,SAAS,IAAI,CAC5D,MAAQ,CACN,QACF,CACA,GAAIC,EAAE,SAAWF,EAAc,SAC/B,IAAMG,EAAKP,EAAmBM,EAAE,QAAQ,EACnCC,IACDZ,EAAI,KAAMa,GAAMA,EA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U,GACzBhC,EAAU,SAAS,SACnBC,EAAgB4F,EAEZ5F,IACF4B,EAAe,EACfS,EAAsB,EACtBqB,EAAgB,EAGhB,SAAS,iBAAiB,QAASV,EAAS,CAC1C,QAAS,GACT,QAAS,EACX,CAAC,EACD,SAAS,iBAAiB,SAAUI,EAAU,CAC5C,QAAS,GACT,QAAS,EACX,CAAC,EAID,SAAS,iBAAiB,SAAUC,EAAU,CAC5C,QAAS,GACT,QAAS,EACX,CAAC,EAID,SAAS,iBAAiB,kBAAmBwB,EAAe,CAC1D,QAAS,EACX,CAAC,EACD,SAAS,iBAAiB,UAAWA,EAAe,CAClD,QAAS,GACT,QAAS,EACX,CAAC,EACD,OAAO,iBAAiB,SAAUA,EAAe,CAC/C,QAAS,GACT,QAAS,EACX,CAAC,GAGH,IAAMgB,EAAQ,WAAW,8BAA8B,EAAE,QACrD,OACA,QACJb,EAAK,CAAE,KAAM,aAAc,KAAMa,CAAM,CAAC,CAC1C",
|
|
6
|
+
"names": ["widgetOrigin", "send", "activitySeq", "activity", "lastUrl", "pageContextOn", "navFire", "origPushState", "origReplaceState", "snapshotModule", "PII", "redact", "text", "out", "re", "isPrivate", "el", "t", "artifactIdFromPath", "pathname", "m", "embeddedMatterfactEntities", "widgetOrigin", "frame", "u", "id", "e", "opaqueFrameCount", "f", "readPageContext", "declared", "found", "opaque", "publishContext", "grantsFromIframeSrcs", "srcs", "origin", "raw", "owner", "token", "g", "readArtifactGrants", "publishArtifactGrants", "pushActivity", "controlLabel", "aria", "wrapping", "placeholder", "FORM_CONTROLS", "describe", "role", "label", "ACTIONABLE", "onClick", "ev", "target", "actionable", "onSubmit", "onChange", "tag", "type", "summary", "opt", "watchNavigation", "fire", "url", "name", "orig", "args", "r", "lastFocus", "readFocus", "focus", "sel", "anchor", "active", "snapshot", "loadSnapshotModule", "describeControl", "doc", "scrollable", "focusTimer", "scheduleFocus", "snapshotSeq", "sendSnapshot", "emit", "yaml", "truncated", "visibleRefs", "sendRegion", "ref", "snapshotRegion", "resolveRef", "callTool", "call", "stop", "start", "pageContext", "theme"]
|
|
7
|
+
}
|
|
@@ -9,7 +9,6 @@ var pageContextOn = true;
|
|
|
9
9
|
var navFire = null;
|
|
10
10
|
var origPushState = null;
|
|
11
11
|
var origReplaceState = null;
|
|
12
|
-
var pendingAuthListener = null;
|
|
13
12
|
var snapshotModule = null;
|
|
14
13
|
var PII = [
|
|
15
14
|
/\b[\w.+-]+@[\w-]+\.[\w.]{2,}\b/g,
|
|
@@ -238,7 +237,7 @@ function describeControl(el) {
|
|
|
238
237
|
return describe(el);
|
|
239
238
|
}
|
|
240
239
|
async function loadSnapshotModule() {
|
|
241
|
-
const m = await import('./snapshot-
|
|
240
|
+
const m = await import('./snapshot-XFCV2MYR.js');
|
|
242
241
|
snapshotModule = m;
|
|
243
242
|
return m;
|
|
244
243
|
}
|
|
@@ -286,27 +285,6 @@ async function callTool(call, emit) {
|
|
|
286
285
|
error: "Host tools are read-only in this version; no action was taken."
|
|
287
286
|
});
|
|
288
287
|
}
|
|
289
|
-
function beginAuth(config, emit) {
|
|
290
|
-
const w = window.open(
|
|
291
|
-
`${config.origin}/embed/authorize?k=${encodeURIComponent(
|
|
292
|
-
config.publishableKey
|
|
293
|
-
)}&o=${encodeURIComponent(location.origin)}`,
|
|
294
|
-
"mf_auth",
|
|
295
|
-
"width=460,height=640"
|
|
296
|
-
);
|
|
297
|
-
if (!w) return;
|
|
298
|
-
if (pendingAuthListener) window.removeEventListener("message", pendingAuthListener);
|
|
299
|
-
const onMsg = (event) => {
|
|
300
|
-
if (event.origin !== config.origin) return;
|
|
301
|
-
const d = event.data;
|
|
302
|
-
if (d?.type !== "mf:embed:auth") return;
|
|
303
|
-
window.removeEventListener("message", onMsg);
|
|
304
|
-
pendingAuthListener = null;
|
|
305
|
-
emit({ type: "host.auth", token: d.token, expiresAt: d.expiresAt });
|
|
306
|
-
};
|
|
307
|
-
pendingAuthListener = onMsg;
|
|
308
|
-
window.addEventListener("message", onMsg);
|
|
309
|
-
}
|
|
310
288
|
function stop() {
|
|
311
289
|
document.removeEventListener("click", onClick, { capture: true });
|
|
312
290
|
document.removeEventListener("submit", onSubmit, { capture: true });
|
|
@@ -326,10 +304,6 @@ function stop() {
|
|
|
326
304
|
history.replaceState = origReplaceState;
|
|
327
305
|
origReplaceState = null;
|
|
328
306
|
}
|
|
329
|
-
if (pendingAuthListener) {
|
|
330
|
-
window.removeEventListener("message", pendingAuthListener);
|
|
331
|
-
pendingAuthListener = null;
|
|
332
|
-
}
|
|
333
307
|
if (focusTimer) {
|
|
334
308
|
clearTimeout(focusTimer);
|
|
335
309
|
focusTimer = null;
|
|
@@ -350,7 +324,10 @@ function start(emit, origin, pageContext = true) {
|
|
|
350
324
|
publishContext();
|
|
351
325
|
publishArtifactGrants();
|
|
352
326
|
watchNavigation();
|
|
353
|
-
document.addEventListener("click", onClick, {
|
|
327
|
+
document.addEventListener("click", onClick, {
|
|
328
|
+
capture: true,
|
|
329
|
+
passive: true
|
|
330
|
+
});
|
|
354
331
|
document.addEventListener("submit", onSubmit, {
|
|
355
332
|
capture: true,
|
|
356
333
|
passive: true
|
|
@@ -375,6 +352,6 @@ function start(emit, origin, pageContext = true) {
|
|
|
375
352
|
emit({ type: "host.theme", mode: theme });
|
|
376
353
|
}
|
|
377
354
|
|
|
378
|
-
export { artifactIdFromPath,
|
|
379
|
-
//# sourceMappingURL=chunk-
|
|
380
|
-
//# sourceMappingURL=chunk-
|
|
355
|
+
export { artifactIdFromPath, callTool, grantsFromIframeSrcs, isPrivate, readPageContext, redact, sendRegion, sendSnapshot, start, stop };
|
|
356
|
+
//# sourceMappingURL=chunk-JSH3BRYP.js.map
|
|
357
|
+
//# sourceMappingURL=chunk-JSH3BRYP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context.ts"],"names":[],"mappings":";AAWA,IAAI,YAAA,GAAe,EAAA;AAuBnB,IAAM,YAAA,GAAe,EAAA;AAErB,IAAI,IAAA,G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AA,EAAM,OAAO,CAAA;AAC1C","file":"chunk-JSH3BRYP.js","sourcesContent":["import type {\n ActivityEvent,\n FocusContext,\n HostToWidget,\n PageContext,\n PageEntity,\n ToolCall,\n} from './protocol';\n\n/** The origin serving our chat — how we tell OUR embedded content from the host's own\n * iframes. Set by start(); empty until then, which just means we spot nothing. */\nlet widgetOrigin = '';\n\n/**\n * The eye.\n *\n * Everything in this module can see the customer's page. It is a SEPARATE CHUNK,\n * loaded only when someone actually opens the chat — so a page whose visitors never\n * click the widget pays nothing for any of it, and a security reviewer can read\n * exactly one file to know what we look at.\n *\n * The rules, which are not negotiable:\n *\n * NEVER captured — no config enables it: the value of any <input>, <textarea> or\n * contenteditable; anything inside a password field; cookies; localStorage;\n * sessionStorage; the raw DOM; screenshots; network traffic; anything inside an\n * element marked `data-mf-private`.\n *\n * The agent never gets a selector and never touches the DOM. It gets refs. A ref\n * is resolved to an element HERE, in the page, by us.\n */\n\ntype Send = (msg: HostToWidget) => void;\n\nconst MAX_ACTIVITY = 40;\n\nlet send: Send | null = null;\nlet activitySeq = 0;\nconst activity: ActivityEvent[] = [];\nlet lastUrl = '';\n/** Set once by `start()`. False ⇒ the host opted out of ALL page observation — every\n * exported entry point below that would otherwise read or send the page checks this. */\nlet pageContextOn = true;\n\n/* ─────────────────────────── teardown state ───────────────────────────── */\n\n/**\n * Everything below is module-global bookkeeping so `stop()` (see `start()`, bottom of\n * file) can undo exactly what `start()`/`watchNavigation()` installed — remove every\n * listener, restore `history` to what it was before we wrapped it, and forget any\n * DOM-walk module we pulled in. All of this outlives a single `EmbedHost`; see\n * `stop()`'s doc comment for why that's the bug this exists to close.\n */\n\n/** The `fire` closure `watchNavigation()` handed to `popstate` — the only handle we\n * have to remove that listener again. */\nlet navFire: (() => void) | null = null;\n/** The `history.pushState`/`replaceState` this module wrapped, captured so `stop()`\n * can restore them EXACTLY rather than re-wrapping (which is how the old code\n * double-fired navigation on a second `start()`). */\nlet origPushState: History['pushState'] | null = null;\nlet origReplaceState: History['replaceState'] | null = null;\n/** Set once `sendSnapshot`/`sendRegion`/`readFocus` actually pull in the DOM-walk\n * chunk (`./dom/snapshot`) — never imported eagerly, so `stop()` doesn't pay for a\n * chunk that a host who only ever opted out (and never opened a snapshot) never\n * loaded in the first place. */\nlet snapshotModule: { clearRefs: () => void } | null = null;\n\n/* ─────────────────────────── redaction ────────────────────────────────── */\n\nconst PII = [\n /\\b[\\w.+-]+@[\\w-]+\\.[\\w.]{2,}\\b/g, // email\n /\\b(?:\\d[ -]?){13,19}\\b/g, // card-ish\n /\\b\\d{3}[- ]?\\d{2}[- ]?\\d{4}\\b/g, // ssn — dashed, spaced, OR bare 9 digits\n /\\b\\d{9,}\\b/g, // long bare digit runs: account / MRN / routing numbers\n /(?:\\+?\\d{1,2}[\\s.-]?)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}\\b/g, // us phone\n /\\b(?:sk|pk|rk|ak)_(?:live|test)_[A-Za-z0-9]{8,}\\b/g, // stripe-style api keys\n /\\beyJ[\\w-]+\\.[\\w-]+\\.[\\w-]+\\b/g, // jwt\n];\n\n/**\n * Scrub before anything leaves the page — not after it arrives.\n *\n * A compromised widget, or a bug in ours, must not be able to retroactively obtain\n * a customer's users' email addresses. The only way to guarantee that is to never\n * put them on the wire.\n */\nexport function redact(text: string): string {\n let out = text;\n for (const re of PII) out = out.replace(re, '[redacted]');\n return out;\n}\n\n/** Anything the host has marked private, or that is inherently sensitive, is out. */\nexport function isPrivate(el: Element): boolean {\n if (el.closest('[data-mf-private]')) return true;\n const tag = el.tagName;\n if (tag === 'INPUT') {\n const t = (el as HTMLInputElement).type;\n if (t === 'password' || t === 'hidden') return true;\n }\n return false;\n}\n\n/* ───────────────────────── page context ───────────────────────────────── */\n\n/**\n * What the page says about itself.\n *\n * A host that declares nothing still gets URL + title, which is what every other\n * embeddable assistant on the market offers in total. The interesting fields\n * (`route`, `description`, `entities`) are host-declared, because only the host\n * knows that `/o/8813` is \"the Acme Corp order, 3 items, unpaid\".\n *\n * Declared via a global the host sets before we load:\n * window.matterfact = { context: { route: '/orders/:id', description: '...', entities: [...] } }\n */\n/**\n * matterfact content embedded IN the host page — today, artifact iframes.\n *\n * A cross-origin iframe is opaque: `contentDocument` throws, so the DOM snapshot walks\n * straight past an embedded artifact and the agent is blind to the very thing the page\n * is built around. It reads the page as empty and asks which URL you mean.\n *\n * We don't need to see inside, and shouldn't want to. The artifact's ID is right there\n * in the src, and the agent can already resolve `artifacts/<id>/` in its session — the\n * same path an `@`-mention uses. So we report the ID and let the backend fetch the real\n * thing, which beats scraping a rendering of it: it gets the data, not the picture.\n *\n * Matched by ORIGIN, not by path shape: a customer is perfectly entitled to their own\n * /artifacts/ route, and it isn't ours.\n */\n/** The artifact slug from a matterfact artifact path, or null. Matches both the\n * chrome-free embed route (/embed/artifacts/<slug>) and the bare /artifacts/<slug>. */\nexport function artifactIdFromPath(pathname: string): string | null {\n const m = pathname.match(/^\\/(?:embed\\/)?artifacts\\/(.+?)\\/?$/);\n return m ? decodeURIComponent(m[1]) : null;\n}\n\nfunction embeddedMatterfactEntities(): PageEntity[] {\n if (!widgetOrigin) return [];\n const out: PageEntity[] = [];\n for (const frame of Array.from(document.querySelectorAll('iframe'))) {\n let u: URL;\n try {\n u = new URL(frame.getAttribute('src') || '', location.href);\n } catch {\n continue;\n }\n if (u.origin !== widgetOrigin) continue;\n const id = artifactIdFromPath(u.pathname);\n if (!id) continue;\n if (out.some((e) => e.id === id)) continue; // same artifact twice = once\n // No url field: the agent reaches an artifact by ID (`artifacts/<id>/`), never by\n // fetching the page, and an artifact URL can carry a share token we've no business\n // forwarding. The id is the whole useful payload.\n out.push({\n kind: 'artifact',\n id,\n label: redact(frame.getAttribute('title') || '') || id,\n });\n }\n return out;\n}\n\n/**\n * Frames we can see the existence of but nothing inside — someone else's cross-origin\n * embed. Worth one line: \"there is a thing here I cannot read\" is a true and useful\n * statement, and much better than the agent confidently describing a page while missing\n * the widget the user is actually asking about.\n */\nfunction opaqueFrameCount(): number {\n return Array.from(document.querySelectorAll('iframe')).filter((f) => {\n try {\n const u = new URL(f.getAttribute('src') || '', location.href);\n return u.origin !== location.origin && u.origin !== widgetOrigin;\n } catch {\n return false;\n }\n }).length;\n}\n\nexport function readPageContext(): PageContext {\n const declared =\n (window as { matterfact?: { context?: PageContext } }).matterfact\n ?.context ?? {};\n\n const found = embeddedMatterfactEntities();\n const opaque = opaqueFrameCount();\n\n return {\n // Path only. A query string is where session ids, tokens and email addresses\n // live; it is not ours to take.\n url: location.origin + location.pathname,\n path: location.pathname,\n title: redact(document.title),\n locale: document.documentElement.lang || undefined,\n ...declared,\n // After the spread: what we FOUND is additive to what the host DECLARED, never a\n // replacement. A host that declares its own entities still gets the artifacts we\n // spotted, and vice versa.\n entities: [...(declared.entities ?? []), ...found],\n data: {\n ...(declared.data ?? {}),\n ...(opaque ? { opaque_frames: opaque } : {}),\n },\n };\n}\n\nfunction publishContext() {\n send?.({ type: 'host.context', context: readPageContext() });\n}\n\n/* ─────────────────────── artifact grants (backend-only) ────────────────── */\n\nexport interface ArtifactGrantSrc {\n id: string;\n owner: string;\n token: string;\n}\n\n/** Read-only capability grants from co-embedded artifact iframes, for the backend to\n * materialize their data. Separate from entities on purpose: the token must never ride\n * ambient (rendered) context, only this backend-only channel. */\nexport function grantsFromIframeSrcs(\n srcs: string[],\n origin: string,\n): ArtifactGrantSrc[] {\n const out: ArtifactGrantSrc[] = [];\n for (const raw of srcs) {\n let u: URL;\n try {\n u = new URL(raw || '', location.href);\n } catch {\n continue;\n }\n if (u.origin !== origin) continue;\n const id = artifactIdFromPath(u.pathname);\n if (!id) continue;\n const owner = u.searchParams.get('owner') || '';\n const token = u.searchParams.get('t') || '';\n if (!owner || !token) continue;\n if (out.some((g) => g.id === id)) continue;\n out.push({ id, owner, token });\n }\n return out;\n}\n\nfunction readArtifactGrants(): ArtifactGrantSrc[] {\n if (!widgetOrigin) return [];\n const srcs = Array.from(document.querySelectorAll('iframe')).map(\n (f) => f.getAttribute('src') || '',\n );\n return grantsFromIframeSrcs(srcs, widgetOrigin);\n}\n\nfunction publishArtifactGrants() {\n send?.({ type: 'host.artifactGrants', grants: readArtifactGrants() });\n}\n\n/* ────────────────────────── activity ──────────────────────────────────── */\n\nfunction pushActivity(e: Omit<ActivityEvent, 'seq' | 'ts'>) {\n activity.push({ ...e, seq: ++activitySeq, ts: Date.now() });\n if (activity.length > MAX_ACTIVITY) activity.shift();\n send?.({ type: 'host.activity', events: [activity[activity.length - 1]] });\n}\n\n/**\n * A short, human-readable label for what got clicked.\n *\n * Shaped after PostHog's autocapture, not after a session-replay frame: rrweb would\n * give us `{source:2, type:2, id:417, x:210, y:88}` — no text, no role, no href,\n * meaningless to a model without the full DOM snapshot it deltas against. One line\n * of \"clicked button 'Export CSV'\" is worth more and costs less.\n */\n/**\n * The accessible NAME of a form control — never its value.\n *\n * A control has no `innerText`, so the generic path below misses it. We look where a\n * control's name actually lives: `aria-label`, then a `<label for>` or a wrapping\n * `<label>`, then `placeholder`. `placeholder` is a LABEL, not a value — it is the\n * hint shown when the field is empty (\"Order number or customer\"), so it is safe.\n */\nfunction controlLabel(el: Element): string {\n const aria = el.getAttribute('aria-label');\n if (aria) return aria;\n\n const id = el.id;\n if (id) {\n const forLabel = document.querySelector(`label[for=\"${CSS.escape(id)}\"]`);\n const t = forLabel?.textContent?.trim();\n if (t) return t;\n }\n const wrapping = el.closest('label')?.textContent?.trim();\n if (wrapping) return wrapping;\n\n const placeholder = el.getAttribute('placeholder');\n if (placeholder) return placeholder;\n\n return '';\n}\n\nconst FORM_CONTROLS = new Set(['INPUT', 'SELECT', 'TEXTAREA']);\n\nfunction describe(el: Element): string {\n const role = el.getAttribute('role') || el.tagName.toLowerCase();\n const label =\n el.getAttribute('aria-label') ||\n (FORM_CONTROLS.has(el.tagName)\n ? controlLabel(el)\n : (el as HTMLElement).innerText?.trim().slice(0, 60)) ||\n el.getAttribute('title') ||\n '';\n return label ? `${role} \"${redact(label)}\"` : role;\n}\n\n/**\n * Elements a click is worth recording. Deliberately tight: the point of the activity\n * stream is INTENT (\"the user chose to export\"), and a click on a heading, a label,\n * a card gutter, or blank page is not intent, it is noise. We only log a click that\n * lands on something actionable.\n */\nconst ACTIONABLE =\n 'a[href],button,input,select,textarea,summary,' +\n '[role=\"button\"],[role=\"link\"],[role=\"menuitem\"],[role=\"tab\"],[role=\"option\"],' +\n '[role=\"checkbox\"],[role=\"switch\"],[role=\"radio\"],[onclick],[tabindex]';\n\nfunction onClick(ev: Event) {\n const target = ev.target as Element | null;\n if (!target || !(target instanceof Element)) return;\n\n // Clicking a <label> operates the control it labels — record THAT, not \"clicked\n // label\", so the event reads as the user's actual intent.\n const label = target.closest('label');\n const labelled = label\n ? (label.getAttribute('for') &&\n document.getElementById(label.getAttribute('for')!)) ||\n label.querySelector('input,select,textarea')\n : null;\n\n const actionable = labelled ?? target.closest(ACTIONABLE);\n // No actionable target — a click on text, a gutter, or blank space. That is not an\n // action; dropping it is the whole fix for the click-log noise.\n if (!actionable || isPrivate(actionable)) return;\n\n pushActivity({ type: 'click', summary: `clicked ${describe(actionable)}` });\n}\n\nfunction onSubmit(ev: Event) {\n const el = ev.target as Element | null;\n if (!el || isPrivate(el)) return;\n // The FORM was submitted — never its values.\n pushActivity({ type: 'submit', summary: `submitted ${describe(el)}` });\n}\n\n/**\n * A form field changed.\n *\n * The rule is the same as everywhere else and the temptation here is sharpest:\n * record THAT a field changed and WHICH field (its label), never WHAT it was\n * changed to. `change` fires on exactly the elements whose values are off-limits.\n *\n * One safe exception: a <select>, a checkbox, or a radio chose from a fixed, visible\n * set of options the agent can already see in the snapshot — \"Unpaid\", \"Shipped\".\n * That is a user *choice*, not typed data, so the chosen option's LABEL is fair to\n * include and is the useful part (\"filtered status to Shipped\"). Free-text and\n * numeric inputs get their label only.\n */\nfunction onChange(ev: Event) {\n const el = ev.target as (HTMLElement & { type?: string }) | null;\n if (!el || !(el instanceof Element) || isPrivate(el)) return;\n\n const tag = el.tagName;\n const type = (el as HTMLInputElement).type;\n\n // Never a password/hidden field, and isPrivate already covered data-mf-private.\n if (tag === 'INPUT' && (type === 'password' || type === 'hidden')) return;\n\n let summary = `changed ${describe(el)}`;\n\n if (tag === 'SELECT') {\n const opt = (el as HTMLSelectElement).selectedOptions[0]?.text;\n if (opt) summary = `${describe(el)} → \"${redact(opt)}\"`;\n } else if (type === 'checkbox' || type === 'radio') {\n summary = `${(el as HTMLInputElement).checked ? 'checked' : 'unchecked'} ${describe(el)}`;\n }\n\n pushActivity({ type: 'input', summary });\n}\n\n/**\n * SPA navigation. There is no event for `pushState`, so we wrap it — a 20-line job\n * that no library does better.\n */\nfunction watchNavigation() {\n const fire = () => {\n const url = location.pathname;\n if (url === lastUrl) return;\n lastUrl = url;\n pushActivity({ type: 'nav', summary: `navigated to ${url}` });\n publishContext();\n publishArtifactGrants();\n };\n // Captured so stop() can remove exactly this listener, and so history.pushState/\n // replaceState get restored to what they were before we wrapped them — never\n // re-wrapped on top of an existing wrap (that was the pre-existing bug: a second\n // start() used to wrap the ALREADY-wrapped methods, double-firing every nav).\n navFire = fire;\n\n for (const name of ['pushState', 'replaceState'] as const) {\n const orig = history[name];\n if (name === 'pushState') origPushState = orig as History['pushState'];\n else origReplaceState = orig as History['replaceState'];\n history[name] = function (\n this: History,\n ...args: Parameters<History['pushState']>\n ) {\n const r = orig.apply(this, args);\n fire();\n return r;\n } as History[typeof name];\n }\n window.addEventListener('popstate', fire);\n}\n\n/* ─────────────────────────── focal context ────────────────────────────── */\n\n/**\n * Where the user's attention is, right now.\n *\n * This is the \"knows what you're doing\" layer, and it is deliberately small so it can\n * ride on every turn — where the full snapshot cannot. It is also the most sensitive:\n * `selection` is whatever the user highlighted, which could be their own email, so it\n * is redacted and respects data-mf-private like everything else. Focus and the\n * viewport are labels and refs — never a value.\n *\n * Held so the last-known focus can travel with a turn even between the (throttled)\n * push updates.\n */\nlet lastFocus: FocusContext = {};\n\nasync function readFocus(): Promise<FocusContext> {\n const focus: FocusContext = {};\n\n // Selection — the single strongest \"this is what I'm asking about\" signal.\n const sel = window.getSelection?.();\n if (sel && !sel.isCollapsed) {\n const anchor = sel.anchorNode?.parentElement ?? null;\n // Don't lift a selection out of a private region, and cap it — a user can select\n // the whole page.\n if (!anchor || !anchor.closest('[data-mf-private]')) {\n const text = sel.toString().trim().slice(0, 500);\n if (text) focus.selection = redact(text);\n }\n }\n\n // The control they're working in — its label, never its contents.\n const active = document.activeElement;\n if (\n active &&\n active !== document.body &&\n !isPrivate(active) &&\n !active.closest('[data-mf-private]')\n ) {\n const { snapshot } = await loadSnapshotModule();\n void snapshot; // ensure the chunk that owns refFor is loaded before we describe\n focus.focused = {\n label: redact(describeControl(active)),\n role: active.getAttribute('role') || active.tagName.toLowerCase(),\n };\n }\n\n const doc = document.documentElement;\n const scrollable = doc.scrollHeight - doc.clientHeight;\n focus.scroll =\n scrollable > 0 ? Math.round((doc.scrollTop / scrollable) * 100) / 100 : 0;\n\n return focus;\n}\n\n/** A label for whatever is focused, reusing the same value-blind rules as activity. */\nfunction describeControl(el: Element): string {\n return describe(el);\n}\n\n/** The one place any of the three call sites below reach into the DOM-walk chunk —\n * so `stop()` has a single `snapshotModule` to check without importing anything\n * itself (see the teardown-state block above). */\nasync function loadSnapshotModule() {\n const m = await import('./dom/snapshot');\n snapshotModule = m;\n return m;\n}\n\nlet focusTimer: ReturnType<typeof setTimeout> | null = null;\n\n/** Coalesce a burst of selection/focus/scroll events into one push. */\nfunction scheduleFocus() {\n if (focusTimer) return;\n focusTimer = setTimeout(async () => {\n focusTimer = null;\n lastFocus = await readFocus();\n send?.({ type: 'host.focus', focus: lastFocus });\n }, 250);\n}\n\n/* ───────────────────────────── snapshot ───────────────────────────────── */\n\nlet snapshotSeq = 0;\n\nexport async function sendSnapshot(emit: Send) {\n // pageContext: false ⇒ no snapshot, ever — a `widget.requestSnapshot` must not be\n // able to reintroduce the page observation the host explicitly turned off.\n if (!pageContextOn) return;\n // The a11y walk is itself lazily imported: a host that only ever declares\n // PageContext and never lets the agent look at the page never downloads it.\n const { snapshot } = await loadSnapshotModule();\n const { yaml, truncated, visibleRefs } = snapshot();\n emit({\n type: 'host.snapshot',\n snapshot: { yaml: redact(yaml), seq: ++snapshotSeq, truncated },\n });\n // The viewport slice rides with the focus context so the agent can tell the few\n // things on screen from the whole tree it just received.\n lastFocus = { ...lastFocus, visibleRefs };\n emit({ type: 'host.focus', focus: lastFocus });\n}\n\n/**\n * Zoom in on one ref — the pull half of the model. The agent asks; we resolve the ref\n * to a live element and return just its sub-tree.\n */\nexport async function sendRegion(ref: string, emit: Send) {\n // Mirrors sendSnapshot's guard: a `widget.readRegion` for a ref minted before\n // opt-out must not pull a live DOM subtree just because the ref is still\n // resolvable (see refs.ts's `clearRefs`, which `stop()` also uses as a backstop).\n if (!pageContextOn) return;\n const { snapshotRegion, resolveRef } = await loadSnapshotModule();\n const el = resolveRef(ref);\n if (!el) {\n emit({\n type: 'host.region',\n ref,\n yaml: '(this element is no longer on the page)',\n });\n return;\n }\n const { yaml } = snapshotRegion(el);\n emit({ type: 'host.region', ref, yaml: redact(yaml) });\n}\n\n/* ───────────────────────────── tools ──────────────────────────────────── */\n\n/**\n * v1 IS READ-ONLY.\n *\n * The page's content is untrusted — text on it can try to instruct the agent — and\n * the moment the agent can act, a bad answer becomes a bad ACTION. So no tool here\n * mutates the page yet. The call path exists, and the enforcement point is HERE (in\n * the page, where we control what actually happens) rather than in the widget, which\n * can be lied to.\n *\n * When write tools land: anything not `readOnly` gets a user confirmation, on every\n * call. Not \"unless the host opts out\" — every call, because the trigger may have\n * been written by the page.\n */\nexport async function callTool(call: ToolCall, emit: Send) {\n emit({\n type: 'host.toolResult',\n callId: call.callId,\n ok: false,\n error: 'Host tools are read-only in this version; no action was taken.',\n });\n}\n\n/* ───────────────────────────── stop / start ───────────────────────────── */\n\n/**\n * The opposite number of `start()` — remove every listener it (or `watchNavigation`)\n * installed, restore `history.pushState`/`replaceState` to what they were before we\n * wrapped them, and forget the module-level `send`/`activity`/focus state. Nothing\n * here is a filter over what gets sent afterward — there is simply nothing left\n * installed to send anything.\n *\n * Why this has to exist at all: everything `start()` installs is MODULE-GLOBAL, and\n * this module outlives any single `EmbedHost`. React remounts `EmbedHost` whenever\n * ANY of its identity-defining props change (react.tsx's effect deps: publishableKey,\n * widgetOrigin, surface, theme, inline, pageContext, dev) — including just a theme\n * swap, not only a deliberate opt-out. Before this fix, a remount's `start()` call\n * only ever ADDED listeners; the previous mount's were still attached and kept firing\n * into the module `send`, which the new `start()` had just repointed at the NEW\n * widget. Net effect: open once with pageContext on, then remount for any reason\n * (including `pageContext: false`) and the new widget silently keeps receiving\n * clicks/nav/focus collected by the old mount's still-live listeners.\n *\n * Called from two places: the top of `start()` (idempotency — a second `start()`\n * never doubles up, which also fixes the pre-existing double history-wrap /\n * double-`fire()`-per-navigation bug), and `EmbedHost.destroy()` in loader.ts (a\n * plain unmount with no remount still has to stop, not just wait for a `start()`\n * that may never come).\n */\nexport function stop(): void {\n document.removeEventListener('click', onClick, { capture: true });\n document.removeEventListener('submit', onSubmit, { capture: true });\n document.removeEventListener('change', onChange, { capture: true });\n document.removeEventListener('selectionchange', scheduleFocus);\n document.removeEventListener('focusin', scheduleFocus, { capture: true });\n window.removeEventListener('scroll', scheduleFocus, { capture: true });\n\n if (navFire) {\n window.removeEventListener('popstate', navFire);\n navFire = null;\n }\n // Restore, don't re-wrap: this is what stops a repeated start() from wrapping an\n // already-wrapped pushState/replaceState (the old double-fire-per-nav bug).\n if (origPushState) {\n history.pushState = origPushState;\n origPushState = null;\n }\n if (origReplaceState) {\n history.replaceState = origReplaceState;\n origReplaceState = null;\n }\n\n if (focusTimer) {\n clearTimeout(focusTimer);\n focusTimer = null;\n }\n\n send = null;\n activity.length = 0;\n lastFocus = {};\n widgetOrigin = '';\n\n // Belt-and-suspenders alongside sendRegion's own pageContextOn check (see above):\n // an old ref minted while observation was on must not stay resolvable afterward.\n // Only touches the DOM-walk chunk if it was ever actually loaded — see\n // loadSnapshotModule's doc comment.\n snapshotModule?.clearRefs();\n}\n\n/**\n * @param pageContext Whether to observe the host page at all. Default `true`. False is\n * the loader's `pageContext: false` opt-out reaching all the way down here: skip every\n * bit of page reading below — no declared/found context, no artifact grants, no nav/\n * click/submit/change/focus observers — so there is nothing to send and nothing that\n * could later be asked for (see `widget.requestSnapshot` in loader.ts). Theme detection\n * is unaffected: it reads an OS media query, never the page, so it isn't page context.\n */\nexport function start(emit: Send, origin?: string, pageContext = true) {\n // Idempotent: undo whatever a PREVIOUS start() installed before this one installs\n // anything. Without this, a remount (see stop()'s doc comment) leaves the old\n // mount's listeners live, writing into the `send` this call is about to reassign.\n stop();\n\n send = emit;\n widgetOrigin = origin || '';\n lastUrl = location.pathname;\n pageContextOn = pageContext;\n\n if (pageContextOn) {\n publishContext();\n publishArtifactGrants();\n watchNavigation();\n\n // Passive + capture: we observe, we never interfere with the host's own handling.\n document.addEventListener('click', onClick, {\n capture: true,\n passive: true,\n });\n document.addEventListener('submit', onSubmit, {\n capture: true,\n passive: true,\n });\n // `change` fires on blur/commit for text inputs and immediately for select/\n // checkbox/radio — not on every keystroke, which is what we want: a settled\n // choice, not a stream of partial values.\n document.addEventListener('change', onChange, {\n capture: true,\n passive: true,\n });\n\n // Focal context: what the user is attending to. Coalesced (scheduleFocus), because\n // selectionchange and scroll fire in torrents.\n document.addEventListener('selectionchange', scheduleFocus, {\n passive: true,\n });\n document.addEventListener('focusin', scheduleFocus, {\n capture: true,\n passive: true,\n });\n window.addEventListener('scroll', scheduleFocus, {\n capture: true,\n passive: true,\n });\n }\n\n const theme = matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light';\n emit({ type: 'host.theme', mode: theme });\n}\n"]}
|
|
@@ -11,7 +11,6 @@ var pageContextOn = true;
|
|
|
11
11
|
var navFire = null;
|
|
12
12
|
var origPushState = null;
|
|
13
13
|
var origReplaceState = null;
|
|
14
|
-
var pendingAuthListener = null;
|
|
15
14
|
var snapshotModule = null;
|
|
16
15
|
var PII = [
|
|
17
16
|
/\b[\w.+-]+@[\w-]+\.[\w.]{2,}\b/g,
|
|
@@ -241,7 +240,7 @@ function describeControl(el) {
|
|
|
241
240
|
return describe(el);
|
|
242
241
|
}
|
|
243
242
|
async function loadSnapshotModule() {
|
|
244
|
-
const m = await import("./snapshot-
|
|
243
|
+
const m = await import("./snapshot-HYMRZTZC.js");
|
|
245
244
|
snapshotModule = m;
|
|
246
245
|
return m;
|
|
247
246
|
}
|
|
@@ -289,27 +288,6 @@ async function callTool(call, emit) {
|
|
|
289
288
|
error: "Host tools are read-only in this version; no action was taken."
|
|
290
289
|
});
|
|
291
290
|
}
|
|
292
|
-
function beginAuth(config, emit) {
|
|
293
|
-
const w = window.open(
|
|
294
|
-
`${config.origin}/embed/authorize?k=${encodeURIComponent(
|
|
295
|
-
config.publishableKey
|
|
296
|
-
)}&o=${encodeURIComponent(location.origin)}`,
|
|
297
|
-
"mf_auth",
|
|
298
|
-
"width=460,height=640"
|
|
299
|
-
);
|
|
300
|
-
if (!w) return;
|
|
301
|
-
if (pendingAuthListener) window.removeEventListener("message", pendingAuthListener);
|
|
302
|
-
const onMsg = (event) => {
|
|
303
|
-
if (event.origin !== config.origin) return;
|
|
304
|
-
const d = event.data;
|
|
305
|
-
if (d?.type !== "mf:embed:auth") return;
|
|
306
|
-
window.removeEventListener("message", onMsg);
|
|
307
|
-
pendingAuthListener = null;
|
|
308
|
-
emit({ type: "host.auth", token: d.token, expiresAt: d.expiresAt });
|
|
309
|
-
};
|
|
310
|
-
pendingAuthListener = onMsg;
|
|
311
|
-
window.addEventListener("message", onMsg);
|
|
312
|
-
}
|
|
313
291
|
function stop() {
|
|
314
292
|
document.removeEventListener("click", onClick, { capture: true });
|
|
315
293
|
document.removeEventListener("submit", onSubmit, { capture: true });
|
|
@@ -329,10 +307,6 @@ function stop() {
|
|
|
329
307
|
history.replaceState = origReplaceState;
|
|
330
308
|
origReplaceState = null;
|
|
331
309
|
}
|
|
332
|
-
if (pendingAuthListener) {
|
|
333
|
-
window.removeEventListener("message", pendingAuthListener);
|
|
334
|
-
pendingAuthListener = null;
|
|
335
|
-
}
|
|
336
310
|
if (focusTimer) {
|
|
337
311
|
clearTimeout(focusTimer);
|
|
338
312
|
focusTimer = null;
|
|
@@ -353,7 +327,10 @@ function start(emit, origin, pageContext = true) {
|
|
|
353
327
|
publishContext();
|
|
354
328
|
publishArtifactGrants();
|
|
355
329
|
watchNavigation();
|
|
356
|
-
document.addEventListener("click", onClick, {
|
|
330
|
+
document.addEventListener("click", onClick, {
|
|
331
|
+
capture: true,
|
|
332
|
+
passive: true
|
|
333
|
+
});
|
|
357
334
|
document.addEventListener("submit", onSubmit, {
|
|
358
335
|
capture: true,
|
|
359
336
|
passive: true
|
|
@@ -387,8 +364,7 @@ export {
|
|
|
387
364
|
sendSnapshot,
|
|
388
365
|
sendRegion,
|
|
389
366
|
callTool,
|
|
390
|
-
beginAuth,
|
|
391
367
|
stop,
|
|
392
368
|
start
|
|
393
369
|
};
|
|
394
|
-
//# sourceMappingURL=chunk-
|
|
370
|
+
//# sourceMappingURL=chunk-NZIN3LK7.js.map
|