auto-webmcp 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/auto-webmcp.cjs.js +391 -135
- package/dist/auto-webmcp.cjs.js.map +4 -4
- package/dist/auto-webmcp.esm.js +391 -142
- package/dist/auto-webmcp.esm.js.map +4 -4
- package/dist/auto-webmcp.iife.js +1 -1
- package/dist/auto-webmcp.iife.js.map +4 -4
- package/dist/discovery.d.ts.map +1 -1
- package/dist/interceptor.d.ts +11 -1
- package/dist/interceptor.d.ts.map +1 -1
- package/dist/registry.d.ts +7 -3
- package/dist/registry.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/auto-webmcp.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var AutoWebMCP=(()=>{var q=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Be=Object.prototype.hasOwnProperty;var Ne=(e,t)=>()=>(e&&(t=e(e=0)),t);var ne=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},qe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _e(t))!Be.call(e,r)&&r!==n&&q(e,r,{get:()=>t[r],enumerable:!(o=Pe(t,r))||o.enumerable});return e};var De=e=>qe(q({},"__esModule",{value:!0}),e);var Me={};ne(Me,{getAllRegisteredTools:()=>V,getRegisteredToolName:()=>lt,isWebMCPSupported:()=>M,registerFormTool:()=>z,unregisterAll:()=>G,unregisterFormTool:()=>k});function M(){return typeof navigator<"u"&&typeof navigator.modelContext<"u"}async function z(e,t,n){if(!M())return;w.get(e)&&await k(e);let r={name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n};t.annotations&&Object.keys(t.annotations).length>0&&(r.annotations=t.annotations);try{await navigator.modelContext.registerTool(r)}catch{try{await navigator.modelContext.unregisterTool(t.name),await navigator.modelContext.registerTool(r)}catch{}}w.set(e,t.name)}async function k(e){if(!M())return;let t=w.get(e);if(t){try{await navigator.modelContext.unregisterTool(t)}catch{}w.delete(e)}}function lt(e){return w.get(e)}function V(){return Array.from(w.entries()).map(([e,t])=>({form:e,name:t}))}async function G(){let e=Array.from(w.entries());await Promise.all(e.map(([t])=>k(t)))}var w,$=Ne(()=>{"use strict";w=new Map});var Ht={};ne(Ht,{autoWebMCP:()=>Oe});function oe(e){return{exclude:e?.exclude??[],autoSubmit:e?.autoSubmit??!1,overrides:e?.overrides??{},debug:e?.debug??!1}}var C=["textbox","combobox","checkbox","radio","switch","spinbutton","searchbox","slider"];function W(e){return e instanceof HTMLInputElement?We(e):e instanceof HTMLTextAreaElement?{type:"string"}:e instanceof HTMLSelectElement?je(e):null}function We(e){switch(e.type.toLowerCase()){case"text":case"search":case"tel":return D(e);case"email":return{...D(e),format:"email"};case"url":return{...D(e),format:"uri"};case"number":case"range":{let n={type:"number"};return e.min!==""&&(n.minimum=parseFloat(e.min)),e.max!==""&&(n.maximum=parseFloat(e.max)),n}case"date":return{type:"string",format:"date"};case"datetime-local":return{type:"string",format:"date-time"};case"time":return{type:"string",format:"time"};case"month":return{type:"string",pattern:"^\\d{4}-\\d{2}$"};case"week":return{type:"string",pattern:"^\\d{4}-W\\d{2}$"};case"color":return{type:"string",pattern:"^#[0-9a-fA-F]{6}$"};case"checkbox":return{type:"boolean"};case"radio":return{type:"string"};case"file":case"hidden":case"submit":case"reset":case"button":case"image":return null;case"password":return null;default:return{type:"string"}}}function D(e){let t={type:"string"};e.minLength>0&&(t.minLength=e.minLength),e.maxLength>0&&e.maxLength!==524288&&(t.maxLength=e.maxLength),e.pattern&&(t.pattern=e.pattern);let n=e.getAttribute("list");if(n){let o=e.ownerDocument.getElementById(n);if(o instanceof HTMLDataListElement){let r=Array.from(o.options).filter(s=>!s.disabled&&s.value.trim()!=="");r.length>0&&(t.enum=r.map(s=>s.value.trim()),t.oneOf=r.map(s=>({const:s.value.trim(),title:s.textContent?.trim()||s.value.trim()})))}}return t}var Je=/^(select|choose|pick)\b|^--+|---/i;function ie(e){return e.disabled?!0:e.value!==""?!1:Je.test(e.text.trim())}function je(e){let t=[],n=[];for(let o of Array.from(e.children))if(o instanceof HTMLOptGroupElement){if(o.disabled)continue;let r=o.label?.trim()??"";for(let s of Array.from(o.children)){if(!(s instanceof HTMLOptionElement)||ie(s))continue;t.push(s.value);let i={const:s.value,title:s.text.trim()||s.value};r&&(i.group=r),n.push(i)}}else if(o instanceof HTMLOptionElement){if(ie(o))continue;t.push(o.value),n.push({const:o.value,title:o.text.trim()||o.value})}return t.length===0?{type:"string"}:e.multiple?{type:"array",items:{type:"string",enum:t}}:{type:"string",enum:t,oneOf:n}}function re(e,t){return Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(t)}"]`)).map(n=>n.value).filter(n=>n!==""&&n!=="on")}function se(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).map(o=>o.value).filter(o=>o!=="")}function ae(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).filter(o=>o.value!=="").map(o=>{let r=Ue(o);return{const:o.value,title:r||o.value}})}function le(e,t){switch(t){case"checkbox":case"switch":return{type:"boolean"};case"spinbutton":case"slider":{let n={type:"number"},o=e.getAttribute("aria-valuemin"),r=e.getAttribute("aria-valuemax");return o!==null&&(n.minimum=parseFloat(o)),r!==null&&(n.maximum=parseFloat(r)),n}case"combobox":{let n=e.getAttribute("aria-owns")??e.getAttribute("aria-controls");if(n){let o=document.getElementById(n);if(o){let r=Array.from(o.querySelectorAll('[role="option"]')).filter(s=>s.getAttribute("aria-disabled")!=="true");if(r.length>0){let s=r.map(l=>(l.getAttribute("data-value")??l.textContent??"").trim()).filter(Boolean),i=r.map(l=>({const:(l.getAttribute("data-value")??l.textContent??"").trim(),title:(l.textContent??"").trim()}));return{type:"string",enum:s,oneOf:i}}}}return{type:"string"}}case"textbox":case"searchbox":case"radio":default:return{type:"string"}}}function Ue(e){let t=e.closest("label");if(t){let n=t.cloneNode(!0);n.querySelectorAll("input, select, textarea, button").forEach(r=>r.remove());let o=n.textContent?.trim()??"";if(o)return o}if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let o=n.textContent?.trim()??"";if(o)return o}}return""}var me=0;function de(e,t){let n=t?.name??ze(e),o=t?.description??Ge(e),{schema:r,fieldElements:s}=Qe(e),i=Ye(e);return{name:n,description:o,inputSchema:r,annotations:i,fieldElements:s}}function ze(e){let t=e.getAttribute("toolname");if(t)return E(t);let n=e.dataset.webmcpName;if(n)return E(n);let o=J(e);if(o)return E(o);let r=pe(e);if(r)return E(r);if(e.id)return E(e.id);if(e.name)return E(e.name);if(e.action){let s=Ve(e.action);if(s)return E(s)}return`form_${++me}`}function E(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)||"form"}function J(e){let t=[...Array.from(e.querySelectorAll('button[type="submit"], button:not([type])')),...Array.from(e.querySelectorAll('input[type="submit"]'))];for(let n of t){let o=n instanceof HTMLInputElement?n.value.trim():n.textContent?.trim()??"";if(o&&o.length>0&&o.length<80)return o}return""}function pe(e){let t=e;for(;t;){let n=t.previousElementSibling;for(;n;){if(/^H[1-3]$/i.test(n.tagName)){let o=n.textContent?.trim()??"";if(o)return o}n=n.previousElementSibling}if(t=t.parentElement,!t||t===document.body)break}return""}function Ve(e){try{let n=new URL(e,window.location.href).pathname.split("/").filter(Boolean);return n[n.length-1]??""}catch{return""}}function Ge(e){let t=e.getAttribute("tooldescription");if(t)return t.trim();let n=e.dataset.webmcpDescription;if(n)return n.trim();let o=e.querySelector("legend");if(o?.textContent?.trim())return o.textContent.trim();let r=e.getAttribute("aria-label");if(r?.trim())return r.trim();let s=e.getAttribute("aria-describedby");if(s){let a=document.getElementById(s);if(a?.textContent?.trim())return a.textContent.trim()}let i=pe(e),l=document.title?.trim();return i&&l?`${i}: ${l}`:i||l||"Submit form"}var fe=/^(search|find|look|filter|browse|view|show|check|preview|get|fetch|retrieve|load)\b/i,ge=/^(delete|remove|cancel|terminate|destroy|purge|revoke|unsubscribe|deactivate)\b/i,Ke=/\/(delete|remove|cancel|destroy)\b/i;function Ye(e){let t={};if(e.dataset.webmcpReadonly!==void 0&&(t.readOnlyHint=e.dataset.webmcpReadonly!=="false"),e.dataset.webmcpDestructive!==void 0&&(t.destructiveHint=e.dataset.webmcpDestructive!=="false"),e.dataset.webmcpIdempotent!==void 0&&(t.idempotentHint=e.dataset.webmcpIdempotent!=="false"),e.dataset.webmcpOpenworld!==void 0&&(t.openWorldHint=e.dataset.webmcpOpenworld!=="false"),t.readOnlyHint===void 0){let o=e.method.toLowerCase()==="get",r=J(e),s=r?fe.test(r.trim()):!1;(o||s)&&(t.readOnlyHint=!0)}if(t.destructiveHint===void 0){let o=J(e),r=o?ge.test(o.trim()):!1,s=e.action?Ke.test(e.action):!1;(r||s)&&(t.destructiveHint=!0)}return t.idempotentHint===void 0&&(t.readOnlyHint===!0||e.method.toLowerCase()==="get")&&(t.idempotentHint=!0),t.openWorldHint===void 0&&(t.openWorldHint=t.readOnlyHint!==!0),t.readOnlyHint===!0||t.destructiveHint===!0||t.idempotentHint===!0||t.openWorldHint===!1?t:{}}function Xe(e){if(e instanceof HTMLInputElement){let t=e.type.toLowerCase();return t==="checkbox"?e.checked?!0:void 0:t==="radio"?void 0:t==="number"||t==="range"?e.value!==""?parseFloat(e.value):void 0:e.value!==""?e.value:void 0}if(e instanceof HTMLTextAreaElement)return e.value!==""?e.value:void 0;if(e instanceof HTMLSelectElement){if(e.multiple){let t=Array.from(e.options).filter(n=>n.selected).map(n=>n.value);return t.length>0?t:void 0}return e.value!==""?e.value:void 0}}function be(e,t=new Set){if(t.has(e))return[];t.add(e);let n=[];for(let o of Array.from(e.querySelectorAll("*")))o.shadowRoot&&n.push(...Array.from(o.shadowRoot.querySelectorAll("input, textarea, select")),...be(o.shadowRoot,t));return n}function Qe(e){let t={},n=[],o=new Map,r=new Set,s=new Set,i=[...Array.from(e.querySelectorAll("input, textarea, select")),...be(e)];for(let c of i){let m=c.name,u=m||he(c);if(!u)continue;if(c instanceof HTMLInputElement&&c.type==="radio"){if(r.has(u))continue;r.add(u)}if(c instanceof HTMLInputElement&&c.type==="checkbox"){if(s.has(u))continue;s.add(u)}let p=W(c);if(!p||!U(c))continue;p.title=Te(c);let f=ye(c);f&&(p.description=f);let b=Xe(c);if(b!==void 0&&(p.default=b),c instanceof HTMLInputElement&&c.type==="radio"){p.enum=se(e,u);let L=ae(e,u);L.length>0&&(p.oneOf=L);let d=e.querySelector(`input[type="radio"][name="${CSS.escape(u)}"]:checked`);d?.value&&(p.default=d.value)}if(c instanceof HTMLInputElement&&c.type==="checkbox"){let L=re(e,u);if(L.length>1){let d={type:"array",items:{type:"string",enum:L},title:p.title};p.description&&(d.description=p.description);let g=Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(u)}"]:checked`)).map(h=>h.value);g.length>0&&(d.default=g),t[u]=d,c.required&&n.push(u);continue}}t[u]=p,m||o.set(u,c),c.required&&n.push(u)}let l=et(e),a=new Set;for(let{el:c,role:m,key:u,enumValues:p,enumOneOf:f}of l){if(t[u])continue;if(m==="radio"){if(a.has(u))continue;a.add(u)}let b=le(c,m);p&&p.length>0&&(b.enum=p,f&&f.length>0&&(b.oneOf=f)),b.title=tt(c);let L=nt(c);L&&(b.description=L),t[u]=b,o.set(u,c),c.getAttribute("aria-required")==="true"&&n.push(u)}return{schema:{$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:t,required:n},fieldElements:o}}var Ee=/^_r_[0-9a-z]+_$|^:[a-z0-9]+:$/i;function he(e){let t=e;if(t.dataset.webmcpName)return E(t.dataset.webmcpName);if(e.id&&!Ee.test(e.id))return E(e.id);let n=e.getAttribute("aria-label");return n?E(n):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?E(e.placeholder.trim()):e instanceof HTMLInputElement&&e.type!=="text"?e.type:null}function Ze(e){if(e.dataset.webmcpName)return E(e.dataset.webmcpName);if(e.id&&!Ee.test(e.id))return E(e.id);let t=e.getAttribute("aria-label");if(t)return E(t);let n=e.getAttribute("placeholder");return n?E(n):null}function et(e){let t=C.map(a=>`[role="${a}"]`).join(", "),n=[];for(let a of Array.from(e.querySelectorAll(t))){if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement||a instanceof HTMLSelectElement||a.getAttribute("aria-hidden")==="true"||a.hidden)continue;let c=a.getAttribute("role"),m=ce(a);m&&n.push({el:a,role:c,key:m})}let o=n.filter(a=>a.role==="radio"),r=n.filter(a=>a.role!=="radio"),s=new Map,i=[];for(let a of o){let c=a.el.closest('[role="radiogroup"]');c?(s.has(c)||s.set(c,[]),s.get(c).push(a.el)):i.push(a)}let l=[];for(let[a,c]of s){let m=ce(a);if(!m)continue;let u=c.map(f=>(f.getAttribute("data-value")??f.getAttribute("aria-label")??f.textContent??"").trim()).filter(Boolean),p=c.map(f=>{let b=(f.getAttribute("data-value")??f.getAttribute("aria-label")??f.textContent??"").trim(),L=(f.getAttribute("aria-label")??f.textContent??"").trim();return{const:b,title:L||b}}).filter(f=>f.const!=="");u.length>0&&l.push({el:a,role:"radio",key:m,enumValues:u,enumOneOf:p})}return[...r,...l,...i]}function ce(e){let t=e;if(t.dataset?.webmcpName)return E(t.dataset.webmcpName);if(e.id)return E(e.id);let n=e.getAttribute("aria-label");if(n)return E(n);let o=e.getAttribute("aria-labelledby");if(o){let r=document.getElementById(o)?.textContent?.trim();if(r)return E(r)}return null}function tt(e){let t=e;if(t.dataset?.webmcpTitle)return t.dataset.webmcpTitle;let n=e.getAttribute("aria-label");if(n)return n.trim();let o=e.getAttribute("aria-labelledby");if(o){let r=document.getElementById(o)?.textContent?.trim();if(r)return r}return e.id?j(e.id):""}function nt(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let n=e;if(n.dataset?.webmcpDescription)return n.dataset.webmcpDescription;let o=e.getAttribute("aria-description");if(o)return o;let r=e.getAttribute("aria-describedby");if(r){let i=document.getElementById(r)?.textContent?.trim();if(i)return i}let s=e.getAttribute("placeholder")??e.dataset?.placeholder;return s?s.trim():""}function Te(e){if("dataset"in e&&e.dataset.webmcpTitle)return e.dataset.webmcpTitle;let t=ot(e);return t||(e.name?j(e.name):e.id?j(e.id):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?e.placeholder.trim():"")}function ye(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let n=e;if(n.dataset.webmcpDescription)return n.dataset.webmcpDescription;let o=e.getAttribute("aria-description");if(o)return o;let r=e.getAttribute("aria-describedby");if(r){let s=document.getElementById(r);if(s?.textContent?.trim())return s.textContent.trim()}if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement){let s=e.placeholder?.trim();if(s&&s.length>0)return s}return""}function ot(e){if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let o=ue(n);if(o)return o}}let t=e.closest("label");if(t){let n=ue(t);if(n)return n}return""}function ue(e){let t=e.cloneNode(!0);return t.querySelectorAll("input, select, textarea, button").forEach(n=>n.remove()),t.textContent?.trim()??""}function j(e){return e.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim().replace(/\b\w/g,t=>t.toUpperCase())}function U(e){let t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||e.offsetParent===null&&t.position!=="fixed")return!1;let n=e;for(;n&&n!==document.body;){if(n.getAttribute("aria-hidden")==="true")return!1;n=n.parentElement}return!e.closest("fieldset")?.disabled}function Le(e,t,n){let o=rt(e,n),r=st(e),{schema:s,fieldElements:i}=at(t),l=it(n);return{name:o,description:r,inputSchema:s,annotations:l,fieldElements:i}}function it(e){let t={},n=e instanceof HTMLInputElement?e.value.trim():e?.textContent?.trim()??"";return fe.test(n)&&(t.readOnlyHint=!0,t.idempotentHint=!0),ge.test(n)&&(t.destructiveHint=!0),t.readOnlyHint!==!0&&(t.openWorldHint=!0),t.readOnlyHint===!0||t.destructiveHint===!0||t.idempotentHint===!0||t.openWorldHint===!1?t:{}}function rt(e,t){if(t){let r=t instanceof HTMLInputElement?t.value.trim():t.textContent?.trim()??"";if(r&&r.length>0&&r.length<80)return E(r)}let n=xe(e);if(n)return E(n);let o=document.title?.trim();return o?E(o):`form_${++me}`}function st(e){let t=xe(e),n=document.title?.trim();return t&&n&&t!==n?`${t} on ${n}`:t||n||"Submit form"}function xe(e){let t=e.querySelector("h1, h2, h3");if(t?.textContent?.trim())return t.textContent.trim();let n=e;for(;n;){let o=n.previousElementSibling;for(;o;){if(/^H[1-3]$/i.test(o.tagName)){let r=o.textContent?.trim()??"";if(r)return r}o=o.previousElementSibling}if(n=n.parentElement,!n||n===document.body)break}return""}function at(e){let t={},n=[],o=new Map,r=new Set,s=new Set;for(let i of e){if(!(i instanceof HTMLInputElement)&&!(i instanceof HTMLTextAreaElement)&&!(i instanceof HTMLSelectElement)){let u=Ze(i);if(!u||!U(i))continue;let p={type:"string"};p.title=i.getAttribute("aria-label")??u;let f=(i.getAttribute("aria-description")??i.getAttribute("aria-describedby"),null);f&&(p.description=f),t[u]=p,o.set(u,i),n.push(u);continue}let l=i.name,a=(l?E(l):null)||he(i);if(!a)continue;if(i instanceof HTMLInputElement&&i.type==="radio"){if(r.has(a))continue;r.add(a)}if(i instanceof HTMLInputElement&&i.type==="checkbox"){if(s.has(a))continue;s.add(a)}let c=W(i);if(!c||!U(i))continue;c.title=Te(i);let m=ye(i);if(m&&(c.description=m),i instanceof HTMLInputElement&&i.type==="checkbox"){let u=e.filter(p=>p instanceof HTMLInputElement&&p.type==="checkbox"&&p.name===a).map(p=>p.value).filter(p=>p!==""&&p!=="on");if(u.length>1){let p={type:"array",items:{type:"string",enum:u},title:c.title};c.description&&(p.description=c.description),t[a]=p,i.required&&n.push(a);continue}}t[a]=c,l||o.set(a,i),i.required&&n.push(a)}return{schema:{$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:t,required:n},fieldElements:o}}$();var O=new WeakMap,Se=new WeakMap,P=new WeakMap,H=new WeakMap,A=new WeakMap,_=new WeakMap,ct=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set,ut=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set,v=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked")?.set;function ve(e,t,n,o){return o?.fieldElements&&P.set(e,o.fieldElements),He(e,n),async r=>{A.set(e,[]),H.delete(e),K(e,r);let s=pt(o,r);return s.length>0&&H.set(e,s),window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:n}})),new Promise((i,l)=>{O.set(e,{resolve:i,reject:l}),(t.autoSubmit||e.hasAttribute("toolautosubmit")||e.dataset.webmcpAutosubmit!==void 0)&&Ae(e).then(async()=>{try{K(e,r);for(let c=0;c<2&&dt(e,r,P.get(e)).length!==0;c++)K(e,r),await Ae(e,400,100);let a=e;if(!e.isConnected){let m=document.querySelector('button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])')?.closest("form");m&&(a=m,O.set(a,{resolve:i,reject:l}),He(a,n))}a!==e&&H.has(e)&&(H.set(a,H.get(e)),H.delete(e)),a.requestSubmit()}catch(a){l(a instanceof Error?a:new Error(String(a)))}})})}}function He(e,t){e.__awmcp_intercepted||(e.__awmcp_intercepted=!0,e.addEventListener("submit",n=>{let o=O.get(e);if(!o)return;let{resolve:r}=o;O.delete(e);let s=mt(e,Se.get(e),P.get(e));_.delete(e);let i=H.get(e)??[];H.delete(e);let l=A.get(e)??[];A.delete(e);let a=l.filter(b=>b.type==="not_filled").map(b=>b.field),c={status:i.length>0||a.length>0?"partial":"success",filled_fields:s,skipped_fields:a,missing_required:i,warnings:[...i.map(b=>({field:b,type:"missing_required",message:`required field "${b}" was not provided`})),...l]},m=[...i.length?[`required fields were not filled: ${i.join(", ")}`]:[],...l.map(b=>b.message)],u=m.length?` Note: ${m.join("; ")}.`:"",f={content:[{type:"text",text:`Form submitted. Fields: ${JSON.stringify(s)}${u}`},{type:"text",text:JSON.stringify(c)}]};n.agentInvoked&&typeof n.respondWith=="function"&&(n.preventDefault(),n.respondWith(Promise.resolve(f))),r(f)}),e.addEventListener("reset",()=>{_.delete(e),window.dispatchEvent(new CustomEvent("toolcancel",{detail:{toolName:t}}))}))}function R(e,t){if(e.focus(),e.select?.(),document.execCommand("insertText",!1,t)&&e.value===t)return;let n=e instanceof HTMLTextAreaElement?ut:ct;n?n.call(e,t):e.value=t,e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:t})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function Y(e,t){v?v.call(e,t):e.checked=t,e.dispatchEvent(new Event("change",{bubbles:!0}))}function B(e,t){for(let n of Array.from(e.querySelectorAll("*"))){let o=n.shadowRoot;if(!o)continue;let r=o.querySelector(t);if(r)return r;let s=B(o,t);if(s)return s}return null}function Q(e,t){let n=CSS.escape(t),o=e.querySelector(`[name="${n}"]`)??e.querySelector(`input#${n}, textarea#${n}, select#${n}`);return o||(B(document,`[name="${n}"]`)??B(document,`input#${n}, textarea#${n}, select#${n}`))}function K(e,t){Se.set(e,t);let n=P.get(e),o={};for(let[r,s]of Object.entries(t)){let i=Q(e,r);if(i){if(i instanceof HTMLInputElement)if(we(i,e,r,s),i.type==="checkbox")if(Array.isArray(s)){let a=CSS.escape(r);o[r]=Array.from(e.querySelectorAll(`input[type="checkbox"][name="${a}"]`)).filter(c=>c.checked).map(c=>c.value)}else o[r]=i.checked;else o[r]=i.value;else i instanceof HTMLTextAreaElement?(R(i,String(s??"")),o[r]=i.value):i instanceof HTMLSelectElement&&(X(i,s,e,r),o[r]=i.multiple?Array.from(i.options).filter(a=>a.selected).map(a=>a.value):i.value);continue}let l=n?.get(r);if(l){let a=l;if(!l.isConnected){let c=l.id;if(c){let m=document.getElementById(c)??B(document,`#${CSS.escape(c)}`);m&&(a=m)}}a instanceof HTMLInputElement?(we(a,e,r,s),o[r]=a.type==="checkbox"?a.checked:a.value):a instanceof HTMLTextAreaElement?(R(a,String(s??"")),o[r]=a.value):a instanceof HTMLSelectElement?(X(a,s,e,r),o[r]=a.multiple?Array.from(a.options).filter(c=>c.selected).map(c=>c.value):a.value):(Ce(a,s),o[r]=s)}}_.set(e,o),window.__lastFillWarnings=A.get(e)??[]}function we(e,t,n,o){let r=e.type.toLowerCase();if(r==="checkbox"){if(Array.isArray(o)){let s=CSS.escape(n),i=t.querySelectorAll(`input[type="checkbox"][name="${s}"]`);for(let l of i)Y(l,o.map(String).includes(l.value));return}Y(e,!!o);return}if(r==="number"||r==="range"){let s=String(o??""),i=Number(s);if(s===""||isNaN(i)){A.get(t)?.push({field:n,type:"type_mismatch",message:`"${n}" expects a number, got: ${JSON.stringify(o)}`,original:o});return}let l=e.min!==""?parseFloat(e.min):-1/0,a=e.max!==""?parseFloat(e.max):1/0;if(i<l||i>a){let c=Math.min(Math.max(i,l),a);A.get(t)?.push({field:n,type:"clamped",message:`"${n}" value ${i} is outside allowed range [${e.min||"?"}, ${e.max||"?"}], clamped to ${c}`,original:i,actual:c}),e.value=String(c)}else e.value=String(i);e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:String(i)})),e.dispatchEvent(new Event("change",{bubbles:!0}));return}if(r==="radio"){let s=CSS.escape(n),i=t.querySelectorAll(`input[type="radio"][name="${s}"]`);for(let l of i)if(l.value===String(o)){v?v.call(l,!0):l.checked=!0,l.dispatchEvent(new Event("change",{bubbles:!0}));break}return}R(e,String(o??""))}function X(e,t,n,o){if(e.multiple){let s=Array.isArray(t)?t.map(String):[String(t??"")];for(let i of Array.from(e.options))i.selected=s.includes(i.value);e.dispatchEvent(new Event("change",{bubbles:!0}));return}let r=String(t??"");if(e.value=r,e.value!==r){let s=r.toLowerCase(),i=Array.from(e.options).find(l=>l.text.trim().toLowerCase()===s||l.label.trim().toLowerCase()===s);i?e.value=i.value:n&&o&&A.get(n)?.push({field:o,type:"not_filled",message:`"${o}" value "${r}" did not match any option in the select`,original:r})}e.dispatchEvent(new Event("change",{bubbles:!0}))}function Ce(e,t){let n=e.getAttribute("role");if(n==="checkbox"||n==="switch"){e.setAttribute("aria-checked",String(!!t)),e.dispatchEvent(new MouseEvent("click",{bubbles:!0}));return}if(n==="radio"){e.setAttribute("aria-checked","true"),e.dispatchEvent(new MouseEvent("click",{bubbles:!0}));return}if(n==="radiogroup"){let r=Array.from(e.querySelectorAll('[role="radio"]'));for(let s of r)if((s.getAttribute("data-value")??s.getAttribute("aria-label")??s.textContent??"").trim()===String(t)){s.setAttribute("aria-checked","true"),s.dispatchEvent(new MouseEvent("click",{bubbles:!0}));for(let l of r)l!==s&&l.setAttribute("aria-checked","false");break}return}let o=e;if(console.log("[auto-webmcp] fillAriaField",{tag:e.tagName,role:n,isContentEditable:o.isContentEditable,id:e.id,ariaLabel:e.getAttribute("aria-label"),textContentBefore:(o.textContent??"").slice(0,80)}),o.isContentEditable){o.focus();let r=document.createRange();r.selectNodeContents(o);let s=window.getSelection();s?.removeAllRanges(),s?.addRange(r);let i=String(t??"");console.log("[auto-webmcp] fillAriaField: text to insert:",JSON.stringify(i));let l=!1;try{let a=new DataTransfer;a.setData("text/plain",i),o.dispatchEvent(new ClipboardEvent("paste",{bubbles:!0,cancelable:!0,composed:!0,clipboardData:a})),l=(o.textContent??"").trim().length>0,console.log("[auto-webmcp] fillAriaField: S1 paste result:",l,JSON.stringify((o.textContent??"").slice(0,80)))}catch(a){console.log("[auto-webmcp] fillAriaField: S1 paste threw:",a)}if(!l){let a=document.execCommand("insertText",!1,i);l=(o.textContent??"").trim().length>0,console.log("[auto-webmcp] fillAriaField: S2 execCommand result:",a,"inserted:",l,JSON.stringify((o.textContent??"").slice(0,80)))}if(!l)try{o.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,composed:!0,inputType:"insertText",data:i})),l=(o.textContent??"").trim().length>0,console.log("[auto-webmcp] fillAriaField: S3 beforeinput result:",l,JSON.stringify((o.textContent??"").slice(0,80)))}catch(a){console.log("[auto-webmcp] fillAriaField: S3 beforeinput threw:",a)}if(!l){o.textContent=i;let a=document.createRange();a.selectNodeContents(o),a.collapse(!1),s?.removeAllRanges(),s?.addRange(a),console.log("[auto-webmcp] fillAriaField: S4 textContent assignment done, textContent:",JSON.stringify((o.textContent??"").slice(0,80)))}o.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:i})),console.log("[auto-webmcp] fillAriaField: done, final textContent:",JSON.stringify((o.textContent??"").slice(0,80)))}else console.log("[auto-webmcp] fillAriaField: not contentEditable, dispatching input/change only"),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function mt(e,t,n){let o={},r=new FormData(e),s=_.get(e);for(let[i,l]of r.entries())if(o[i]!==void 0){let a=o[i];Array.isArray(a)?a.push(l):o[i]=[a,l]}else o[i]=l;if(t)for(let i of Object.keys(t)){if(i in o)continue;if(s&&i in s){o[i]=s[i];continue}let l=Q(e,i)??n?.get(i)??null;if(l)if(l instanceof HTMLInputElement&&l.type==="checkbox")o[i]=l.checked;else if(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement)o[i]=l.value;else{let a=l.getAttribute("role");a==="checkbox"||a==="switch"?o[i]=l.getAttribute("aria-checked")==="true":o[i]=l.textContent?.trim()??""}}return o}function ke(e,t){if(e instanceof HTMLInputElement){let n=e.type.toLowerCase();n==="checkbox"?Y(e,!!t):n==="radio"?e.value===String(t)&&(v?v.call(e,!0):e.checked=!0,e.dispatchEvent(new Event("change",{bubbles:!0}))):R(e,String(t??""))}else e instanceof HTMLTextAreaElement?R(e,String(t??"")):e instanceof HTMLSelectElement?X(e,t):Ce(e,t)}function Ae(e,t=800,n=150){return new Promise(o=>{let r=!1,s=null,i=()=>{r||(r=!0,l.disconnect(),s!==null&&clearTimeout(s),o())},l=new MutationObserver(()=>{s!==null&&clearTimeout(s),s=setTimeout(i,n)});l.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),setTimeout(i,t),s=setTimeout(i,n)})}function dt(e,t,n){let o=[];for(let[r,s]of Object.entries(t)){let i=Q(e,r)??n?.get(r)??null;i&&(i instanceof HTMLInputElement&&i.type==="checkbox"?i.checked!==!!s&&o.push(r):(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)&&i.value!==String(s??"")&&o.push(r))}return o}function pt(e,t){return e?.inputSchema?.required?.length?e.inputSchema.required.filter(n=>!(n in t)):[]}function Re(e,t,n){window.dispatchEvent(new CustomEvent(e,{detail:{form:t,toolName:n}}))}function ft(e,t){if(e.dataset.noWebmcp!==void 0)return!0;for(let n of t.exclude)try{if(e.matches(n))return!0}catch{}return!1}async function N(e,t){if(ft(e,t))return;let n;for(let[l,a]of Object.entries(t.overrides))try{if(e.matches(l)){n=a;break}}catch{}let o=de(e,n);t.debug&&Mt(o.name,o.description);let r=ve(e,t,o.name,o);await z(e,o,r),ee.add(e),Ie++;let s=e.querySelector('[type="submit"], button[data-variant="primary"], button:not([type])')??null,i=window.__pendingSubmitBtns??={};i[o.name]=s,t.debug&&console.log(`[auto-webmcp] Registered: ${o.name}`,o),Re("form:registered",e,o.name)}async function gt(e,t){let{getRegisteredToolName:n}=await Promise.resolve().then(()=>($(),Me)),o=n(e);o&&(await k(e),ee.delete(e),t.debug&&console.log(`[auto-webmcp] Unregistered: ${o}`),Re("form:unregistered",e,o))}var F=null,ee=new WeakSet,Ie=0,Z=new Map,bt=300;function Et(e){let t=e.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select")return!0;let n=e.getAttribute("role");if(n&&C.includes(n)||e.querySelector("input, textarea, select"))return!0;for(let o of C)if(e.querySelector(`[role="${o}"]`))return!0;return!1}function ht(e,t){let n=Z.get(e);n&&clearTimeout(n),Z.set(e,setTimeout(()=>{Z.delete(e),N(e,t)},bt))}function Tt(e){F||(F=new MutationObserver(t=>{for(let n of t){for(let o of n.addedNodes){if(!(o instanceof Element))continue;if(o instanceof HTMLFormElement){N(o,e);continue}let r=o.closest("form");r instanceof HTMLFormElement&&ee.has(r)&&Et(o)&&ht(r,e);for(let s of Array.from(o.querySelectorAll("form")))N(s,e)}for(let o of n.removedNodes){if(!(o instanceof Element))continue;let r=o instanceof HTMLFormElement?[o]:Array.from(o.querySelectorAll("form"));for(let s of r)gt(s,e)}}}),F.observe(document.body,{childList:!0,subtree:!0}))}function yt(e){window.addEventListener("hashchange",()=>I(e));let t={pushState:history.pushState.bind(history),replaceState:history.replaceState.bind(history)};history.pushState=function(...n){t.pushState(...n),I(e)},history.replaceState=function(...n){t.replaceState(...n),I(e)},window.addEventListener("popstate",()=>I(e))}async function I(e){let t=Array.from(document.querySelectorAll("form"));await Promise.allSettled(t.map(n=>N(n,e)))}var Lt=new Set(["password","hidden","file","submit","reset","button","image"]);async function xt(e){if(!M())return;let t='[type="submit"]:not([disabled]), button[data-variant="primary"]:not([disabled])',n='[type="submit"], button[data-variant="primary"]',o=/subscribe|submit|sign[\s-]?up|send|join|go|search|post|tweet|publish/i,r=Array.from(document.querySelectorAll('input:not(form input), textarea:not(form textarea), select:not(form select), [role="textbox"]:not(form [role="textbox"]):not(input):not(textarea), [role="searchbox"]:not(form [role="searchbox"]):not(input):not(textarea), [contenteditable="true"]:not(form [contenteditable="true"]):not(input):not(textarea)')).filter(i=>{if(i instanceof HTMLInputElement&&Lt.has(i.type.toLowerCase()))return console.log(`[auto-webmcp] orphan: skipping excluded type "${i.type}" (name="${i.name}" id="${i.id}")`),!1;let l=i.getBoundingClientRect();return l.width===0||l.height===0?(console.log(`[auto-webmcp] orphan: skipping invisible input (name="${i.name}" id="${i.id}")`),!1):!0});if(console.log(`[auto-webmcp] orphan: found ${r.length} visible orphan input(s)`),r.length===0)return;let s=new Map;for(let i of r){let l=i.parentElement,a=i.parentElement??document.body;for(;l&&l!==document.body;){if(l.querySelector(n)!==null||Array.from(l.querySelectorAll("button")).some(m=>o.test(m.textContent??""))){a=l;break}l=l.parentElement}console.log(`[auto-webmcp] orphan: input (name="${i.name}" id="${i.id}") grouped into container`,a),s.has(a)||s.set(a,[]),s.get(a).push(i)}console.log(`[auto-webmcp] orphan: ${s.size} group(s) found`);for(let[i,l]of s){let a=Array.from(i.querySelectorAll(t)).filter(d=>{let g=d.getBoundingClientRect();return g.width>0&&g.height>0}),c=a[a.length-1]??null;if(!c){let d=Array.from(i.querySelectorAll(n)).filter(g=>{let h=g.getBoundingClientRect();return h.width>0&&h.height>0&&g.disabled});c=d[d.length-1]??null,c&&console.log(`[auto-webmcp] orphan: using disabled submit button as reference: "${c.textContent?.trim()}"`)}if(!c){let d=Array.from(i.querySelectorAll('button, [role="button"]')).filter(g=>{let h=g.getBoundingClientRect();return h.width>0&&h.height>0&&!g.disabled&&g.getAttribute("aria-disabled")!=="true"&&o.test(g.textContent??"")});c=d[d.length-1]??null,c&&console.log(`[auto-webmcp] orphan: using text-matched button in container: "${c.textContent?.trim()}"`)}if(!c){let d=i.closest('[role="dialog"], [aria-modal="true"]');if(d){let g=Array.from(d.querySelectorAll('button, [role="button"]')).filter(T=>{let S=T.getBoundingClientRect();return S.width>0&&S.height>0&&o.test(T.textContent??"")});console.log("[auto-webmcp] orphan: dialog buttons matching submit text:",g.map(T=>`"${T.textContent?.trim().slice(0,30)}" disabled=${T.disabled} aria-disabled=${T.getAttribute("aria-disabled")}`));let h=g.filter(T=>T.disabled||T.getAttribute("aria-disabled")==="true"),x=g.filter(T=>!T.disabled&&T.getAttribute("aria-disabled")!=="true"),y=h.length>0?h:x;c=y[y.length-1]??null,c&&console.log(`[auto-webmcp] orphan: using text-matched button in dialog: "${c.textContent?.trim().slice(0,40)}" disabled=${c.disabled} aria-disabled=${c.getAttribute("aria-disabled")}`)}}if(!c){let d=Array.from(document.querySelectorAll('button, [role="button"]')).filter(g=>{let h=g.getBoundingClientRect();return h.width>0&&h.height>0&&g.getAttribute("aria-disabled")!=="true"&&o.test(g.textContent??"")});c=d[d.length-1]??null,c&&console.log(`[auto-webmcp] orphan: using page-wide fallback submit button: "${c.textContent?.trim()}"`)}console.log("[auto-webmcp] orphan: submit button for group:",c?`"${c.textContent?.trim()}" disabled=${c.disabled}`:"none");let m=Le(i,l,c);console.log(`[auto-webmcp] orphan: tool="${m.name}" schema keys:`,Object.keys(m.inputSchema.properties));let u=[],p=m.inputSchema.properties,f=/^_r_[0-9a-z]+_$/i;for(let d of l){let g=d.id&&!f.test(d.id)?d.id:null,h=d.name||d.getAttribute("name")||d.dataset.webmcpName||g||d.getAttribute("aria-label")||d.getAttribute("placeholder")||null,x=h?h.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64):null,y=!!(x&&p[x]);console.log(`[auto-webmcp] orphan: field (name="${d.name??""}" id="${d.id}") rawKey="${h}" safeKey="${x}" matched=${y}`),y&&u.push({key:x,el:d})}if(console.log(`[auto-webmcp] orphan: ${u.length}/${l.length} input(s) mapped to schema keys`),u.length===0){console.log(`[auto-webmcp] orphan: skipping group "${m.name}" \u2014 no inputs mapped to schema keys`);continue}let b=m.name,L=async d=>{console.log(`[auto-webmcp] orphan execute: tool="${b}" params=`,d),console.log("[auto-webmcp] orphan execute: inputPairs=",u.map(y=>y.key));for(let{key:y,el:T}of u)d[y]!==void 0?(console.log(`[auto-webmcp] orphan execute: filling key="${y}" value=`,d[y],"element=",T),ke(T,d[y]),console.log("[auto-webmcp] orphan execute: after fill, element value=",T.value)):console.log(`[auto-webmcp] orphan execute: key="${y}" not in params, skipping`);if(window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:b}})),!(e.autoSubmit||!!c?.hasAttribute("toolautosubmit")||c instanceof HTMLElement&&c.dataset.webmcpAutosubmit!==void 0||i.hasAttribute("toolautosubmit")||i instanceof HTMLElement&&i.dataset.webmcpAutosubmit!==void 0))return console.log("[auto-webmcp] orphan execute: autoSubmit=false, returning without clicking submit"),{content:[{type:"text",text:"Fields filled. Ready to submit."}]};console.log("[auto-webmcp] orphan execute: polling for enabled submit button (up to 2s)...");let h=null,x=Date.now()+2e3;for(;Date.now()<x;){let y=Array.from(i.querySelectorAll(t)).filter(S=>{let te=S.getBoundingClientRect();return te.width>0&&te.height>0}),T=y[y.length-1]??null;if(T){h=T;break}await new Promise(S=>setTimeout(S,100))}return h?(console.log(`[auto-webmcp] orphan execute: clicking submit button "${h.textContent?.trim()}"`),h.click(),{content:[{type:"text",text:"Fields filled and form submitted."}]}):(console.warn("[auto-webmcp] orphan execute: submit button still disabled after 2s"),{content:[{type:"text",text:"Fields filled but the submit button is still disabled. The page may require additional input before submitting."}]})};try{let d={name:m.name,description:m.description,inputSchema:m.inputSchema,execute:L};m.annotations&&Object.keys(m.annotations).length>0&&(d.annotations=m.annotations),await navigator.modelContext.registerTool(d);let g=window.__pendingSubmitBtns??={};g[m.name]=c,e.debug&&console.log(`[auto-webmcp] Orphan tool registered: ${m.name}`,m)}catch{}}}function Mt(e,t){/^form_\d+$|^submit$|^form$/.test(e)&&console.warn(`[auto-webmcp] Tool "${e}" has a generic name. Consider adding a toolname or data-webmcp-name attribute.`),(!t||t==="Submit form")&&console.warn(`[auto-webmcp] Tool "${e}" has no meaningful description.`),/don'?t|do not|never|avoid|not for/i.test(t)&&console.warn(`[auto-webmcp] Tool "${e}" description contains negative instructions. Per spec best practices, prefer positive descriptions.`)}async function Fe(e){document.readyState==="loading"&&await new Promise(t=>document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})),Ie=0,Tt(e),yt(e),await I(e),await xt(e)}function $e(){F?.disconnect(),F=null}$();async function Oe(e){let t=oe(e);return t.debug&&console.debug("[auto-webmcp] Initializing",{webmcpSupported:M(),config:t}),await Fe(t),{destroy:async()=>{$e(),await G()},getTools:V,isSupported:M()}}typeof window<"u"&&!window.__AUTO_WEBMCP_NO_AUTOINIT&&Oe();return De(Ht);})();
|
|
1
|
+
"use strict";var AutoWebMCP=(()=>{var V=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var Ye=(e,t)=>{for(var o in t)V(e,o,{get:t[o],enumerable:!0})},Xe=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ge(t))!Ke.call(e,i)&&i!==o&&V(e,i,{get:()=>t[i],enumerable:!(n=ze(t,i))||n.enumerable});return e};var Qe=e=>Xe(V({},"__esModule",{value:!0}),e);var _t={};Ye(_t,{autoWebMCP:()=>Ve});function ce(e){return{exclude:e?.exclude??[],autoSubmit:e?.autoSubmit??!1,overrides:e?.overrides??{},debug:e?.debug??!1}}var k=["textbox","combobox","checkbox","radio","switch","spinbutton","searchbox","slider"];function G(e){return e instanceof HTMLInputElement?Ze(e):e instanceof HTMLTextAreaElement?{type:"string"}:e instanceof HTMLSelectElement?tt(e):null}function Ze(e){switch(e.type.toLowerCase()){case"text":case"search":case"tel":return z(e);case"email":return{...z(e),format:"email"};case"url":return{...z(e),format:"uri"};case"number":case"range":{let o={type:"number"};return e.min!==""&&(o.minimum=parseFloat(e.min)),e.max!==""&&(o.maximum=parseFloat(e.max)),o}case"date":return{type:"string",format:"date"};case"datetime-local":return{type:"string",format:"date-time"};case"time":return{type:"string",format:"time"};case"month":return{type:"string",pattern:"^\\d{4}-\\d{2}$"};case"week":return{type:"string",pattern:"^\\d{4}-W\\d{2}$"};case"color":return{type:"string",pattern:"^#[0-9a-fA-F]{6}$"};case"checkbox":return{type:"boolean"};case"radio":return{type:"string"};case"file":case"hidden":case"submit":case"reset":case"button":case"image":return null;case"password":return null;default:return{type:"string"}}}function z(e){let t={type:"string"};e.minLength>0&&(t.minLength=e.minLength),e.maxLength>0&&e.maxLength!==524288&&(t.maxLength=e.maxLength),e.pattern&&(t.pattern=e.pattern);let o=e.getAttribute("list");if(o){let n=e.ownerDocument.getElementById(o);if(n instanceof HTMLDataListElement){let i=Array.from(n.options).filter(s=>!s.disabled&&s.value.trim()!=="");i.length>0&&(t.enum=i.map(s=>s.value.trim()),t.oneOf=i.map(s=>({const:s.value.trim(),title:s.textContent?.trim()||s.value.trim()})))}}return t}var et=/^(select|choose|pick)\b|^--+|---/i;function ue(e){return e.disabled?!0:e.value!==""?!1:et.test(e.text.trim())}function tt(e){let t=[],o=[];for(let n of Array.from(e.children))if(n instanceof HTMLOptGroupElement){if(n.disabled)continue;let i=n.label?.trim()??"";for(let s of Array.from(n.children)){if(!(s instanceof HTMLOptionElement)||ue(s))continue;t.push(s.value);let r={const:s.value,title:s.text.trim()||s.value};i&&(r.group=i),o.push(r)}}else if(n instanceof HTMLOptionElement){if(ue(n))continue;t.push(n.value),o.push({const:n.value,title:n.text.trim()||n.value})}return t.length===0?{type:"string"}:e.multiple?{type:"array",items:{type:"string",enum:t}}:{type:"string",enum:t,oneOf:o}}function me(e,t){return Array.from(e.elements).filter(o=>o instanceof HTMLInputElement&&o.type==="checkbox"&&o.name===t).map(o=>o.value).filter(o=>o!==""&&o!=="on")}function de(e,t){return Array.from(e.elements).filter(n=>n instanceof HTMLInputElement&&n.type==="radio"&&n.name===t).map(n=>n.value).filter(n=>n!=="")}function fe(e,t){return Array.from(e.elements).filter(n=>n instanceof HTMLInputElement&&n.type==="radio"&&n.name===t).filter(n=>n.value!=="").map(n=>{let i=nt(n);return{const:n.value,title:i||n.value}})}function pe(e,t){switch(t){case"checkbox":case"switch":return{type:"boolean"};case"spinbutton":case"slider":{let o={type:"number"},n=e.getAttribute("aria-valuemin"),i=e.getAttribute("aria-valuemax");return n!==null&&(o.minimum=parseFloat(n)),i!==null&&(o.maximum=parseFloat(i)),o}case"combobox":{let o=e.getAttribute("aria-owns")??e.getAttribute("aria-controls");if(o){let n=document.getElementById(o);if(n){let i=Array.from(n.querySelectorAll('[role="option"]')).filter(s=>s.getAttribute("aria-disabled")!=="true");if(i.length>0){let s=i.map(c=>(c.getAttribute("data-value")??c.textContent??"").trim()).filter(Boolean),r=i.map(c=>({const:(c.getAttribute("data-value")??c.textContent??"").trim(),title:(c.textContent??"").trim()}));return{type:"string",enum:s,oneOf:r}}}}return{type:"string"}}case"textbox":case"searchbox":case"radio":default:return{type:"string"}}}function nt(e){let t=e.closest("label");if(t){let o=t.cloneNode(!0);o.querySelectorAll("input, select, textarea, button").forEach(i=>i.remove());let n=o.textContent?.trim()??"";if(n)return n}if(e.id){let o=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(o){let n=o.textContent?.trim()??"";if(n)return n}}return""}var be=0;function Ee(e,t){let o=t?.name??ot(e),n=t?.description??rt(e),{schema:i,fieldElements:s}=ut(e),r=at(e);return{name:o,description:n,inputSchema:i,annotations:r,fieldElements:s}}function ot(e){let t=e.getAttribute("toolname");if(t)return E(t);let o=e.dataset.webmcpName;if(o)return E(o);let n=K(e);if(n)return E(n);let i=he(e);if(i)return E(i);if(e.id)return E(e.id);if(e.name)return E(e.name);if(e.action){let s=it(e.action);if(s)return E(s)}return`form_${++be}`}function E(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)||"form"}function K(e){let t=[...Array.from(e.querySelectorAll('button[type="submit"], button:not([type])')),...Array.from(e.querySelectorAll('input[type="submit"]'))];for(let o of t){let n=o instanceof HTMLInputElement?o.value.trim():o.textContent?.trim()??"";if(n&&n.length>0&&n.length<80)return n}return""}function he(e){let t=e;for(;t;){let o=t.previousElementSibling;for(;o;){if(/^H[1-3]$/i.test(o.tagName)){let n=o.textContent?.trim()??"";if(n)return n}o=o.previousElementSibling}if(t=t.parentElement,!t||t===document.body)break}return""}function it(e){try{let o=new URL(e,window.location.href).pathname.split("/").filter(Boolean);return o[o.length-1]??""}catch{return""}}function rt(e){let t=e.getAttribute("tooldescription");if(t)return t.trim();let o=e.dataset.webmcpDescription;if(o)return o.trim();let n=e.querySelector("legend");if(n?.textContent?.trim())return n.textContent.trim();let i=e.getAttribute("aria-label");if(i?.trim())return i.trim();let s=e.getAttribute("aria-describedby");if(s){let a=document.getElementById(s);if(a?.textContent?.trim())return a.textContent.trim()}let r=he(e),c=document.title?.trim();return r&&c?`${r}: ${c}`:r||c||"Submit form"}var Te=/^(search|find|look|filter|browse|view|show|check|preview|get|fetch|retrieve|load)\b/i,ye=/^(delete|remove|cancel|terminate|destroy|purge|revoke|unsubscribe|deactivate)\b/i,st=/\/(delete|remove|cancel|destroy)\b/i;function at(e){let t={};if(e.dataset.webmcpReadonly!==void 0&&(t.readOnlyHint=e.dataset.webmcpReadonly!=="false"),e.dataset.webmcpDestructive!==void 0&&(t.destructiveHint=e.dataset.webmcpDestructive!=="false"),e.dataset.webmcpIdempotent!==void 0&&(t.idempotentHint=e.dataset.webmcpIdempotent!=="false"),e.dataset.webmcpOpenworld!==void 0&&(t.openWorldHint=e.dataset.webmcpOpenworld!=="false"),t.readOnlyHint===void 0){let n=e.method.toLowerCase()==="get",i=K(e),s=i?Te.test(i.trim()):!1;(n||s)&&(t.readOnlyHint=!0)}if(t.destructiveHint===void 0){let n=K(e),i=n?ye.test(n.trim()):!1,s=e.action?st.test(e.action):!1;(i||s)&&(t.destructiveHint=!0)}return t.idempotentHint===void 0&&(t.readOnlyHint===!0||e.method.toLowerCase()==="get")&&(t.idempotentHint=!0),t.openWorldHint===void 0&&(t.openWorldHint=t.readOnlyHint!==!0),t.readOnlyHint===!0||t.destructiveHint===!0||t.idempotentHint===!0||t.openWorldHint===!1?t:{}}function lt(e){if(e instanceof HTMLInputElement){let t=e.type.toLowerCase();return t==="checkbox"?e.checked?!0:void 0:t==="radio"?void 0:t==="number"||t==="range"?e.value!==""?parseFloat(e.value):void 0:e.value!==""?e.value:void 0}if(e instanceof HTMLTextAreaElement)return e.value!==""?e.value:void 0;if(e instanceof HTMLSelectElement){if(e.multiple){let t=Array.from(e.options).filter(o=>o.selected).map(o=>o.value);return t.length>0?t:void 0}return e.value!==""?e.value:void 0}}function Le(e,t=new Set){if(t.has(e))return[];t.add(e);let o=[];for(let n of Array.from(e.querySelectorAll("*")))if(n.shadowRoot){let i=Array.from(n.shadowRoot.querySelectorAll("input, textarea, select"));i.length>0&&console.log(`[auto-webmcp] shadow: found ${i.length} control(s) in ${n.tagName.toLowerCase()} shadow root:`,i.map(s=>`${s.tagName.toLowerCase()}[type=${s.type??"?"}][name="${s.name}"][id="${s.id}"]`)),o.push(...i,...Le(n.shadowRoot,t))}return o}function ct(e){let t=Array.from(e.elements).filter(n=>n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement),o=new Set(t);for(let n of Le(e))o.has(n)||(t.push(n),o.add(n));return t}function ut(e){let t={},o=[],n=new Map,i=new Set,s=new Set,r=ct(e);for(let l of r){let u=l.name,m=u||Me(l);if(!m)continue;if(l instanceof HTMLInputElement&&l.type==="radio"){if(i.has(m))continue;i.add(m)}if(l instanceof HTMLInputElement&&l.type==="checkbox"){if(s.has(m))continue;s.add(m)}let d=G(l);if(!d||!X(l))continue;d.title=xe(l);let b=He(l);b&&(d.description=b);let T=lt(l);if(T!==void 0&&(d.default=T),l instanceof HTMLInputElement&&l.type==="radio"){d.enum=de(e,m);let M=fe(e,m);M.length>0&&(d.oneOf=M);let f=Array.from(e.elements).find(p=>p instanceof HTMLInputElement&&p.type==="radio"&&p.name===m&&p.checked);f?.value&&(d.default=f.value)}if(l instanceof HTMLInputElement&&l.type==="checkbox"){let M=me(e,m);if(M.length>1){let f={type:"array",items:{type:"string",enum:M},title:d.title};d.description&&(f.description=d.description);let p=Array.from(e.elements).filter(h=>h instanceof HTMLInputElement&&h.type==="checkbox"&&h.name===m&&h.checked).map(h=>h.value);p.length>0&&(f.default=p),t[m]=f,l.required&&o.push(m);continue}}t[m]=d,u||n.set(m,l);let w=l.required;if(!w){let M=l;for(;;){let f=M.getRootNode();if(!(f instanceof ShadowRoot))break;let p=f.host;if(p.hasAttribute("required")||p.getAttribute("aria-required")==="true"){w=!0;break}M=p}}w&&o.push(m)}let c=ft(e),a=new Set;for(let{el:l,role:u,key:m,enumValues:d,enumOneOf:b}of c){if(t[m])continue;if(u==="radio"){if(a.has(m))continue;a.add(m)}let T=pe(l,u);d&&d.length>0&&(T.enum=d,b&&b.length>0&&(T.oneOf=b)),T.title=pt(l);let w=gt(l);w&&(T.description=w),t[m]=T,n.set(m,l),l.getAttribute("aria-required")==="true"&&o.push(m)}return{schema:{$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:t,required:o},fieldElements:n}}var we=/^_r_[0-9a-z]+_$|^:[a-z0-9]+:$/i;function Me(e){let t=e;if(t.dataset.webmcpName)return E(t.dataset.webmcpName);if(e.id&&!we.test(e.id))return E(e.id);let o=e.getAttribute("aria-label");if(o)return E(o);if((e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim())return E(e.placeholder.trim());let n=mt(e);return n||(e instanceof HTMLInputElement&&e.type!=="text"?e.type:null)}function mt(e){let t=e;for(;;){let o=t.getRootNode();if(!(o instanceof ShadowRoot))break;let n=o.host,i=n.getAttribute("field-name");if(i)return console.log("[auto-webmcp] shadow host key: field-name=",i),E(i);let s=n.getAttribute("label")||n.getAttribute("aria-label");if(s)return console.log("[auto-webmcp] shadow host key: label=",s),E(s);let r=n.getAttribute("name");if(r)return console.log("[auto-webmcp] shadow host key: name=",r),E(r);t=n}return null}function dt(e){if(e.dataset.webmcpName)return E(e.dataset.webmcpName);if(e.id&&!we.test(e.id))return E(e.id);let t=e.getAttribute("aria-label");if(t)return E(t);let o=e.getAttribute("placeholder");return o?E(o):null}function ft(e){let t=k.map(a=>`[role="${a}"]`).join(", "),o=[];for(let a of Array.from(e.querySelectorAll(t))){if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement||a instanceof HTMLSelectElement||a.getAttribute("aria-hidden")==="true"||a.hidden)continue;let l=a.getAttribute("role"),u=ge(a);u&&o.push({el:a,role:l,key:u})}let n=o.filter(a=>a.role==="radio"),i=o.filter(a=>a.role!=="radio"),s=new Map,r=[];for(let a of n){let l=a.el.closest('[role="radiogroup"]');l?(s.has(l)||s.set(l,[]),s.get(l).push(a.el)):r.push(a)}let c=[];for(let[a,l]of s){let u=ge(a);if(!u)continue;let m=l.map(b=>(b.getAttribute("data-value")??b.getAttribute("aria-label")??b.textContent??"").trim()).filter(Boolean),d=l.map(b=>{let T=(b.getAttribute("data-value")??b.getAttribute("aria-label")??b.textContent??"").trim(),w=(b.getAttribute("aria-label")??b.textContent??"").trim();return{const:T,title:w||T}}).filter(b=>b.const!=="");m.length>0&&c.push({el:a,role:"radio",key:u,enumValues:m,enumOneOf:d})}return[...i,...c,...r]}function ge(e){let t=e;if(t.dataset?.webmcpName)return E(t.dataset.webmcpName);if(e.id)return E(e.id);let o=e.getAttribute("aria-label");if(o)return E(o);let n=e.getAttribute("aria-labelledby");if(n){let i=document.getElementById(n)?.textContent?.trim();if(i)return E(i)}return null}function pt(e){let t=e;if(t.dataset?.webmcpTitle)return t.dataset.webmcpTitle;let o=e.getAttribute("aria-label");if(o)return o.trim();let n=e.getAttribute("aria-labelledby");if(n){let i=document.getElementById(n)?.textContent?.trim();if(i)return i}return e.id?Y(e.id):""}function gt(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let o=e;if(o.dataset?.webmcpDescription)return o.dataset.webmcpDescription;let n=e.getAttribute("aria-description");if(n)return n;let i=e.getAttribute("aria-describedby");if(i){let r=document.getElementById(i)?.textContent?.trim();if(r)return r}let s=e.getAttribute("placeholder")??e.dataset?.placeholder;return s?s.trim():""}function xe(e){if("dataset"in e&&e.dataset.webmcpTitle)return e.dataset.webmcpTitle;let t=bt(e);return t||(e.name?Y(e.name):e.id?Y(e.id):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?e.placeholder.trim():"")}function He(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let o=e;if(o.dataset.webmcpDescription)return o.dataset.webmcpDescription;let n=e.getAttribute("aria-description");if(n)return n;let i=e.getAttribute("aria-describedby");if(i){let s=document.getElementById(i);if(s?.textContent?.trim())return s.textContent.trim()}if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement){let s=e.placeholder?.trim();if(s&&s.length>0)return s}return""}function bt(e){if(e.id){let i=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(i){let s=B(i);if(s)return s}}let t=e.getRootNode();if(t instanceof ShadowRoot){if(e.id){let s=t.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(s){let r=B(s);if(r)return r}}let i=t.querySelector("label");if(i){let s=B(i);if(s)return s}}let o=e.closest("label");if(o){let i=B(o);if(i)return i}let n=e;for(;;){let i=n.getRootNode();if(!(i instanceof ShadowRoot))break;let s=i.host,r=s.getAttribute("label")||s.getAttribute("aria-label");if(r)return r;n=s}return""}function B(e){let t=e.cloneNode(!0);return t.querySelectorAll("input, select, textarea, button").forEach(o=>o.remove()),t.textContent?.trim()??""}function Y(e){return e.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim().replace(/\b\w/g,t=>t.toUpperCase())}function X(e){let t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||e.offsetParent===null&&t.position!=="fixed")return!1;let o=e;for(;o&&o!==document.body;){if(o.getAttribute("aria-hidden")==="true")return!1;o=o.parentElement}return!e.closest("fieldset")?.disabled}function Ae(e,t,o){let n=ht(e,o),i=Tt(e),{schema:s,fieldElements:r}=yt(t),c=Et(o);return{name:n,description:i,inputSchema:s,annotations:c,fieldElements:r}}function Et(e){let t={},o=e instanceof HTMLInputElement?e.value.trim():e?.textContent?.trim()??"";return Te.test(o)&&(t.readOnlyHint=!0,t.idempotentHint=!0),ye.test(o)&&(t.destructiveHint=!0),t.readOnlyHint!==!0&&(t.openWorldHint=!0),t.readOnlyHint===!0||t.destructiveHint===!0||t.idempotentHint===!0||t.openWorldHint===!1?t:{}}function ht(e,t){if(t){let i=t instanceof HTMLInputElement?t.value.trim():t.textContent?.trim()??"";if(i&&i.length>0&&i.length<80)return E(i)}let o=ve(e);if(o)return E(o);let n=document.title?.trim();return n?E(n):`form_${++be}`}function Tt(e){let t=ve(e),o=document.title?.trim();return t&&o&&t!==o?`${t} on ${o}`:t||o||"Submit form"}function ve(e){let t=e.querySelector("h1, h2, h3");if(t?.textContent?.trim())return t.textContent.trim();let o=e;for(;o;){let n=o.previousElementSibling;for(;n;){if(/^H[1-3]$/i.test(n.tagName)){let i=n.textContent?.trim()??"";if(i)return i}n=n.previousElementSibling}if(o=o.parentElement,!o||o===document.body)break}return""}function yt(e){let t={},o=[],n=new Map,i=new Set,s=new Set;for(let r of e){if(!(r instanceof HTMLInputElement)&&!(r instanceof HTMLTextAreaElement)&&!(r instanceof HTMLSelectElement)){let m=dt(r);if(!m||!X(r))continue;let d={type:"string"};d.title=r.getAttribute("aria-label")??m;let b=(r.getAttribute("aria-description")??r.getAttribute("aria-describedby"),null);b&&(d.description=b),t[m]=d,n.set(m,r),o.push(m);continue}let c=r.name,a=(c?E(c):null)||Me(r);if(!a)continue;if(r instanceof HTMLInputElement&&r.type==="radio"){if(i.has(a))continue;i.add(a)}if(r instanceof HTMLInputElement&&r.type==="checkbox"){if(s.has(a))continue;s.add(a)}let l=G(r);if(!l||!X(r))continue;l.title=xe(r);let u=He(r);if(u&&(l.description=u),r instanceof HTMLInputElement&&r.type==="checkbox"){let m=e.filter(d=>d instanceof HTMLInputElement&&d.type==="checkbox"&&d.name===a).map(d=>d.value).filter(d=>d!==""&&d!=="on");if(m.length>1){let d={type:"array",items:{type:"string",enum:m},title:l.title};l.description&&(d.description=l.description),t[a]=d,r.required&&o.push(a);continue}}t[a]=l,c||n.set(a,r),r.required&&o.push(a)}return{schema:{$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:t,required:o},fieldElements:n}}var A=new Map,Q=new Map;function v(){return typeof navigator<"u"&&typeof navigator.modelContext<"u"}async function Se(e,t,o){if(!v())return;A.get(e)&&await _(e);let i={name:t.name,description:t.description,inputSchema:t.inputSchema,execute:o};t.annotations&&Object.keys(t.annotations).length>0&&(i.annotations=t.annotations);let s=new AbortController;Q.set(e,s);try{await navigator.modelContext.registerTool(i,{signal:s.signal})}catch{try{await navigator.modelContext.unregisterTool?.(t.name),await navigator.modelContext.registerTool(i,{signal:s.signal})}catch{}}A.set(e,t.name)}async function _(e){if(!v())return;let t=A.get(e);if(!t)return;let o=Q.get(e);o&&(o.abort(),Q.delete(e));try{await navigator.modelContext.unregisterTool?.(t)}catch{}A.delete(e)}function Z(e){return A.get(e)}function P(){return Array.from(A.entries()).map(([e,t])=>({form:e,name:t}))}async function Ce(){let e=Array.from(A.entries());await Promise.all(e.map(([t])=>_(t)))}var N=new WeakMap,Fe=new WeakMap,q=new WeakMap,H=new WeakMap,S=new WeakMap,D=new WeakMap,Lt=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set,wt=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set,C=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked")?.set;function Oe(e,t,o,n){return n?.fieldElements&&q.set(e,n.fieldElements),ke(e,o),async(i,s)=>{let r=s;if(t.autoSubmit&&n?.annotations?.destructiveHint===!0&&typeof r?.requestUserInteraction=="function"&&!await r.requestUserInteraction(async()=>new Promise(l=>{let u=window.confirm(`Agent requested a destructive action via "${o}". Continue?`);l(u)})))return window.dispatchEvent(new CustomEvent("toolcancel",{detail:{toolName:o}})),{content:[{type:"text",text:`Cancelled "${o}" by user.`}]};S.set(e,[]),H.delete(e),ee(e,i);let c=Ht(n,i);return c.length>0&&H.set(e,c),window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:o}})),new Promise((a,l)=>{N.set(e,{resolve:a,reject:l}),(t.autoSubmit||e.hasAttribute("toolautosubmit")||e.dataset.webmcpAutosubmit!==void 0)&&Ie(e).then(async()=>{try{ee(e,i);for(let m=0;m<2&&xt(e,i,q.get(e)).length!==0;m++)ee(e,i),await Ie(e,400,100);let u=e;if(!e.isConnected){let d=document.querySelector('button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])')?.closest("form");d&&(u=d,N.set(u,{resolve:a,reject:l}),ke(u,o))}u!==e&&H.has(e)&&(H.set(u,H.get(e)),H.delete(e)),u.requestSubmit()}catch(u){l(u instanceof Error?u:new Error(String(u)))}})})}}function ke(e,t){e.__awmcp_intercepted||(e.__awmcp_intercepted=!0,e.addEventListener("submit",o=>{let n=N.get(e);if(!n)return;let{resolve:i}=n;N.delete(e);let s=Mt(e,Fe.get(e),q.get(e));D.delete(e);let r=H.get(e)??[];H.delete(e);let c=S.get(e)??[];S.delete(e);let a=c.filter(T=>T.type==="not_filled").map(T=>T.field),l={status:r.length>0||a.length>0?"partial":"success",filled_fields:s,skipped_fields:a,missing_required:r,warnings:[...r.map(T=>({field:T,type:"missing_required",message:`required field "${T}" was not provided`})),...c]},u=[...r.length?[`required fields were not filled: ${r.join(", ")}`]:[],...c.map(T=>T.message)],m=u.length?` Note: ${u.join("; ")}.`:"",b={content:[{type:"text",text:`Form submitted. Fields: ${JSON.stringify(s)}${m}`},{type:"text",text:JSON.stringify(l)}]};o.agentInvoked&&typeof o.respondWith=="function"&&(o.preventDefault(),o.respondWith(Promise.resolve(b))),i(b)}),e.addEventListener("reset",()=>{D.delete(e),window.dispatchEvent(new CustomEvent("toolcancel",{detail:{toolName:t}}))}))}function R(e,t){if(e.focus(),e.select?.(),document.execCommand("insertText",!1,t)&&e.value===t)return;let o=e instanceof HTMLTextAreaElement?wt:Lt;o?o.call(e,t):e.value=t,e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:t})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function te(e,t){C?C.call(e,t):e.checked=t,e.dispatchEvent(new Event("change",{bubbles:!0}))}function W(e,t){for(let o of Array.from(e.querySelectorAll("*"))){let n=o.shadowRoot;if(!n)continue;let i=n.querySelector(t);if(i)return i;let s=W(n,t);if(s)return s}return null}function ne(e,t,o){return Array.from(e.elements).filter(n=>n instanceof HTMLInputElement&&n.type===t&&n.name===o)}function ie(e,t){let o=e.elements.namedItem(t);if(typeof o=="object"&&o!==null&&(o instanceof HTMLInputElement||o instanceof HTMLTextAreaElement||o instanceof HTMLSelectElement))return o;if(o instanceof RadioNodeList){let r=o[0];if(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement)return r}let n=CSS.escape(t),i=e.querySelector(`[name="${n}"]`)??e.querySelector(`input#${n}, textarea#${n}, select#${n}`);return i||(W(document,`[name="${n}"]`)??W(document,`input#${n}, textarea#${n}, select#${n}`))}function ee(e,t){Fe.set(e,t);let o=q.get(e),n={};for(let[i,s]of Object.entries(t)){let r=ie(e,i);if(r){r instanceof HTMLInputElement?(Re(r,e,i,s),r.type==="checkbox"?Array.isArray(s)?n[i]=ne(e,"checkbox",i).filter(a=>a.checked).map(a=>a.value):n[i]=r.checked:n[i]=r.value):r instanceof HTMLTextAreaElement?(R(r,String(s??"")),n[i]=r.value):r instanceof HTMLSelectElement&&(oe(r,s,e,i),n[i]=r.multiple?Array.from(r.options).filter(a=>a.selected).map(a=>a.value):r.value);continue}let c=o?.get(i);if(c){let a=c;if(!c.isConnected){let l=c.id;if(l){let u=document.getElementById(l)??W(document,`#${CSS.escape(l)}`);u&&(a=u)}}a instanceof HTMLInputElement?(Re(a,e,i,s),n[i]=a.type==="checkbox"?a.checked:a.value):a instanceof HTMLTextAreaElement?(R(a,String(s??"")),n[i]=a.value):a instanceof HTMLSelectElement?(oe(a,s,e,i),n[i]=a.multiple?Array.from(a.options).filter(l=>l.selected).map(l=>l.value):a.value):($e(a,s),n[i]=s)}}D.set(e,n),window.__lastFillWarnings=S.get(e)??[]}function Re(e,t,o,n){let i=e.type.toLowerCase();if(i==="checkbox"){if(Array.isArray(n)){let s=ne(t,"checkbox",o);for(let r of s)te(r,n.map(String).includes(r.value));return}te(e,!!n);return}if(i==="number"||i==="range"){let s=String(n??""),r=Number(s);if(s===""||isNaN(r)){S.get(t)?.push({field:o,type:"type_mismatch",message:`"${o}" expects a number, got: ${JSON.stringify(n)}`,original:n});return}let c=e.min!==""?parseFloat(e.min):-1/0,a=e.max!==""?parseFloat(e.max):1/0;if(r<c||r>a){let l=Math.min(Math.max(r,c),a);S.get(t)?.push({field:o,type:"clamped",message:`"${o}" value ${r} is outside allowed range [${e.min||"?"}, ${e.max||"?"}], clamped to ${l}`,original:r,actual:l}),e.value=String(l)}else e.value=String(r);e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:String(r)})),e.dispatchEvent(new Event("change",{bubbles:!0}));return}if(i==="radio"){let s=ne(t,"radio",o);for(let r of s)if(r.value===String(n)){C?C.call(r,!0):r.checked=!0,r.dispatchEvent(new Event("change",{bubbles:!0}));break}return}R(e,String(n??""))}function oe(e,t,o,n){if(e.multiple){let s=Array.isArray(t)?t.map(String):[String(t??"")];for(let r of Array.from(e.options))r.selected=s.includes(r.value);e.dispatchEvent(new Event("change",{bubbles:!0}));return}let i=String(t??"");if(e.value=i,e.value!==i){let s=i.toLowerCase(),r=Array.from(e.options).find(c=>c.text.trim().toLowerCase()===s||c.label.trim().toLowerCase()===s);r?e.value=r.value:o&&n&&S.get(o)?.push({field:n,type:"not_filled",message:`"${n}" value "${i}" did not match any option in the select`,original:i})}e.dispatchEvent(new Event("change",{bubbles:!0}))}function $e(e,t){let o=e.getAttribute("role");if(o==="checkbox"||o==="switch"){e.setAttribute("aria-checked",String(!!t)),e.dispatchEvent(new MouseEvent("click",{bubbles:!0}));return}if(o==="radio"){e.setAttribute("aria-checked","true"),e.dispatchEvent(new MouseEvent("click",{bubbles:!0}));return}if(o==="radiogroup"){let i=Array.from(e.querySelectorAll('[role="radio"]'));for(let s of i)if((s.getAttribute("data-value")??s.getAttribute("aria-label")??s.textContent??"").trim()===String(t)){s.setAttribute("aria-checked","true"),s.dispatchEvent(new MouseEvent("click",{bubbles:!0}));for(let c of i)c!==s&&c.setAttribute("aria-checked","false");break}return}let n=e;if(console.log("[auto-webmcp] fillAriaField",{tag:e.tagName,role:o,isContentEditable:n.isContentEditable,id:e.id,ariaLabel:e.getAttribute("aria-label"),textContentBefore:(n.textContent??"").slice(0,80)}),n.isContentEditable){n.focus();let i=document.createRange();i.selectNodeContents(n);let s=window.getSelection();s?.removeAllRanges(),s?.addRange(i);let r=String(t??"");console.log("[auto-webmcp] fillAriaField: text to insert:",JSON.stringify(r));let c=!1;try{let a=new DataTransfer;a.setData("text/plain",r),n.dispatchEvent(new ClipboardEvent("paste",{bubbles:!0,cancelable:!0,composed:!0,clipboardData:a})),c=(n.textContent??"").trim().length>0,console.log("[auto-webmcp] fillAriaField: S1 paste result:",c,JSON.stringify((n.textContent??"").slice(0,80)))}catch(a){console.log("[auto-webmcp] fillAriaField: S1 paste threw:",a)}if(!c){let a=document.execCommand("insertText",!1,r);c=(n.textContent??"").trim().length>0,console.log("[auto-webmcp] fillAriaField: S2 execCommand result:",a,"inserted:",c,JSON.stringify((n.textContent??"").slice(0,80)))}if(!c)try{n.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,composed:!0,inputType:"insertText",data:r})),c=(n.textContent??"").trim().length>0,console.log("[auto-webmcp] fillAriaField: S3 beforeinput result:",c,JSON.stringify((n.textContent??"").slice(0,80)))}catch(a){console.log("[auto-webmcp] fillAriaField: S3 beforeinput threw:",a)}if(!c){n.textContent=r;let a=document.createRange();a.selectNodeContents(n),a.collapse(!1),s?.removeAllRanges(),s?.addRange(a),console.log("[auto-webmcp] fillAriaField: S4 textContent assignment done, textContent:",JSON.stringify((n.textContent??"").slice(0,80)))}n.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:r})),console.log("[auto-webmcp] fillAriaField: done, final textContent:",JSON.stringify((n.textContent??"").slice(0,80)))}else console.log("[auto-webmcp] fillAriaField: not contentEditable, dispatching input/change only"),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function Mt(e,t,o){let n={},i=new FormData(e),s=D.get(e);for(let[r,c]of i.entries())if(n[r]!==void 0){let a=n[r];Array.isArray(a)?a.push(c):n[r]=[a,c]}else n[r]=c;if(t)for(let r of Object.keys(t)){if(r in n)continue;if(s&&r in s){n[r]=s[r];continue}let c=ie(e,r)??o?.get(r)??null;if(c)if(c instanceof HTMLInputElement&&c.type==="checkbox")n[r]=c.checked;else if(c instanceof HTMLInputElement||c instanceof HTMLTextAreaElement||c instanceof HTMLSelectElement)n[r]=c.value;else{let a=c.getAttribute("role");a==="checkbox"||a==="switch"?n[r]=c.getAttribute("aria-checked")==="true":n[r]=c.textContent?.trim()??""}}return n}function Be(e,t){if(e instanceof HTMLInputElement){let o=e.type.toLowerCase();o==="checkbox"?te(e,!!t):o==="radio"?e.value===String(t)&&(C?C.call(e,!0):e.checked=!0,e.dispatchEvent(new Event("change",{bubbles:!0}))):R(e,String(t??""))}else e instanceof HTMLTextAreaElement?R(e,String(t??"")):e instanceof HTMLSelectElement?oe(e,t):$e(e,t)}function Ie(e,t=800,o=150){return new Promise(n=>{let i=!1,s=null,r=()=>{i||(i=!0,c.disconnect(),s!==null&&clearTimeout(s),n())},c=new MutationObserver(()=>{s!==null&&clearTimeout(s),s=setTimeout(r,o)});c.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),setTimeout(r,t),s=setTimeout(r,o)})}function xt(e,t,o){let n=[];for(let[i,s]of Object.entries(t)){let r=ie(e,i)??o?.get(i)??null;r&&(r instanceof HTMLInputElement&&r.type==="checkbox"?r.checked!==!!s&&n.push(i):(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement)&&r.value!==String(s??"")&&n.push(i))}return n}function Ht(e,t){return e?.inputSchema?.required?.length?e.inputSchema.required.filter(o=>!(o in t)):[]}async function _e(e,t){let o=String(t??"").trim();console.log("[auto-webmcp] fillComboboxButton: clicking button, value=",JSON.stringify(o)),e.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0}));let n=await new Promise(c=>{let a=Date.now()+1e3,l=()=>{let u=document.querySelector('[role="listbox"]')??document.querySelector('[role="option"]')?.closest('[role="listbox"]')??null;if(u){c(u);return}if(Date.now()>=a){c(null);return}setTimeout(l,50)};l()});if(!n){console.warn("[auto-webmcp] fillComboboxButton: listbox did not appear after 1s");return}let i=Array.from(n.querySelectorAll('[role="option"]'));console.log("[auto-webmcp] fillComboboxButton: listbox has",i.length,"options");let s=o.toLowerCase(),r=i.find(c=>{let a=(c.getAttribute("data-value")??"").toLowerCase(),l=(c.getAttribute("aria-label")??"").toLowerCase(),u=(c.textContent??"").trim().toLowerCase();return a===s||l===s||u===s});r?(console.log("[auto-webmcp] fillComboboxButton: clicking option",r.textContent?.trim()),r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0}))):console.warn("[auto-webmcp] fillComboboxButton: no option matched",JSON.stringify(o),"available:",i.map(c=>c.textContent?.trim()))}function qe(e,t,o){window.dispatchEvent(new CustomEvent(e,{detail:{form:t,toolName:o}}))}function At(e,t){if(e.dataset.noWebmcp!==void 0)return!0;for(let o of t.exclude)try{if(e.matches(o))return!0}catch{}return!1}function Pe(e,t){let o=`_${t}`;return`${e.slice(0,Math.max(1,64-o.length))}${o}`}function vt(e){let t=new Set(j);for(let{form:o,name:n}of P())e&&o===e||t.add(n);return t}function De(e,t){let o=vt(t);if(!o.has(e))return e;let n=2,i=Pe(e,n);for(;o.has(i);)n++,i=Pe(e,n);return i}async function F(e,t){if(At(e,t))return;let o=Z(e),n;for(let[l,u]of Object.entries(t.overrides))try{if(e.matches(l)){n=u;break}}catch{}let i=Ee(e,n),s=De(i.name,e);s!==i.name&&t.debug&&console.warn(`[auto-webmcp] tool name collision: "${i.name}" renamed to "${s}"`),i.name=s,t.debug&&Bt(i.name,i.description);let r=Oe(e,t,i.name,i);await Se(e,i,r),$.add(e),We++;let c=e.querySelector('[type="submit"], button[data-variant="primary"], button:not([type])')??null,a=window.__pendingSubmitBtns??={};o&&o!==i.name&&delete a[o],a[i.name]=c,t.debug&&console.log(`[auto-webmcp] Registered: ${i.name}`,i),qe("form:registered",e,i.name)}async function St(e,t){let o=Z(e);if(!o)return;await _(e),$.delete(e);let n=window.__pendingSubmitBtns;n&&delete n[o],t.debug&&console.log(`[auto-webmcp] Unregistered: ${o}`),qe("form:unregistered",e,o)}var O=null,$=new WeakSet,We=0,re=new Map,Ct=300,J=null,kt=500,j=new Set;function Ne(e){J&&clearTimeout(J),J=setTimeout(()=>{J=null,Je(e)},kt)}function se(e){let t=e.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select")return!0;let o=e.getAttribute("role");if(o&&k.includes(o)||e.querySelector("input, textarea, select"))return!0;for(let n of k)if(e.querySelector(`[role="${n}"]`))return!0;return!1}function ae(e,t){let o=re.get(e);o&&clearTimeout(o),re.set(e,setTimeout(()=>{re.delete(e),F(e,t)},Ct))}function Rt(e,t){let o=document.getElementById(e);o instanceof HTMLFormElement&&$.has(o)&&ae(o,t)}function It(e){let t=e.closest("form");if(t instanceof HTMLFormElement)return t;let o=e.form;if(o instanceof HTMLFormElement)return o;let n=e.getAttribute("form");if(n){let i=document.getElementById(n);if(i instanceof HTMLFormElement)return i}return null}function Ft(e){O||(O=new MutationObserver(t=>{for(let o of t){if(o.type==="attributes"&&o.target instanceof Element){let n=o.target,i=It(n);i&&$.has(i)?ae(i,e):n instanceof HTMLFormElement?F(n,e):se(n)&&!n.closest("form")&&Ne(e),o.attributeName==="form"&&o.oldValue&&Rt(o.oldValue,e);continue}for(let n of o.addedNodes){if(!(n instanceof Element))continue;if(n instanceof HTMLFormElement){F(n,e);continue}let i=n.closest("form");i instanceof HTMLFormElement&&$.has(i)&&se(n)&&ae(i,e);for(let s of Array.from(n.querySelectorAll("form")))F(s,e);se(n)&&!n.closest("form")&&Ne(e)}for(let n of o.removedNodes){if(!(n instanceof Element))continue;let i=n instanceof HTMLFormElement?[n]:Array.from(n.querySelectorAll("form"));for(let s of i)St(s,e)}}}),O.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0}))}function Ot(e){window.addEventListener("hashchange",()=>I(e));let t={pushState:history.pushState.bind(history),replaceState:history.replaceState.bind(history)};history.pushState=function(...o){t.pushState(...o),I(e)},history.replaceState=function(...o){t.replaceState(...o),I(e)},window.addEventListener("popstate",()=>I(e))}async function I(e){let t=Array.from(document.querySelectorAll("form"));await Promise.allSettled(t.map(o=>F(o,e)))}var $t=new Set(["password","hidden","file","submit","reset","button","image"]);async function Je(e){if(!v())return;let t='[type="submit"]:not([disabled]), button[data-variant="primary"]:not([disabled])',o='[type="submit"], button[data-variant="primary"]',n=/subscribe|submit|sign[\s-]?up|send|join|go|search|post|tweet|publish|save/i,i=Array.from(document.querySelectorAll('input:not(form input), textarea:not(form textarea), select:not(form select), [role="textbox"]:not(form [role="textbox"]):not(input):not(textarea), [role="searchbox"]:not(form [role="searchbox"]):not(input):not(textarea), [contenteditable="true"]:not(form [contenteditable="true"]):not(input):not(textarea), button[role="combobox"]:not(form button[role="combobox"])')).filter(r=>{if(r instanceof HTMLInputElement&&$t.has(r.type.toLowerCase()))return console.log(`[auto-webmcp] orphan: skipping excluded type "${r.type}" (name="${r.name}" id="${r.id}")`),!1;let c=r.getBoundingClientRect();return c.width===0||c.height===0?(console.log(`[auto-webmcp] orphan: skipping invisible input (name="${r.name}" id="${r.id}")`),!1):!0});if(console.log(`[auto-webmcp] orphan: found ${i.length} visible orphan input(s)`),i.length===0)return;let s=new Map;for(let r of i){let c=r.parentElement,a=r.parentElement??document.body;for(;c&&c!==document.body;){if(c.querySelector(o)!==null||Array.from(c.querySelectorAll("button")).some(u=>n.test(u.textContent??""))){a=c;break}c=c.parentElement}console.log(`[auto-webmcp] orphan: input (name="${r.name}" id="${r.id}") grouped into container`,a),s.has(a)||s.set(a,[]),s.get(a).push(r)}console.log(`[auto-webmcp] orphan: ${s.size} group(s) found`);for(let[r,c]of s){let a=Array.from(r.querySelectorAll(t)).filter(f=>{let p=f.getBoundingClientRect();return p.width>0&&p.height>0}),l=a[a.length-1]??null;if(!l){let f=Array.from(r.querySelectorAll(o)).filter(p=>{let h=p.getBoundingClientRect();return h.width>0&&h.height>0&&p.disabled});l=f[f.length-1]??null,l&&console.log(`[auto-webmcp] orphan: using disabled submit button as reference: "${l.textContent?.trim()}"`)}if(!l){let f=Array.from(r.querySelectorAll('button, [role="button"]')).filter(p=>{let h=p.getBoundingClientRect();return h.width>0&&h.height>0&&!p.disabled&&p.getAttribute("aria-disabled")!=="true"&&n.test(p.textContent??"")});l=f[f.length-1]??null,l&&console.log(`[auto-webmcp] orphan: using text-matched button in container: "${l.textContent?.trim()}"`)}if(!l){let f=r.closest('[role="dialog"], [aria-modal="true"]');if(f){let p=Array.from(f.querySelectorAll('button, [role="button"]')).filter(g=>{let x=g.getBoundingClientRect();return x.width>0&&x.height>0&&n.test(g.textContent??"")});console.log("[auto-webmcp] orphan: dialog buttons matching submit text:",p.map(g=>`"${g.textContent?.trim().slice(0,30)}" disabled=${g.disabled} aria-disabled=${g.getAttribute("aria-disabled")}`));let h=p.filter(g=>g.disabled||g.getAttribute("aria-disabled")==="true"),L=p.filter(g=>!g.disabled&&g.getAttribute("aria-disabled")!=="true"),y=h.length>0?h:L;l=y[y.length-1]??null,l&&console.log(`[auto-webmcp] orphan: using text-matched button in dialog: "${l.textContent?.trim().slice(0,40)}" disabled=${l.disabled} aria-disabled=${l.getAttribute("aria-disabled")}`)}}if(!l){let f=Array.from(document.querySelectorAll('button, [role="button"]')).filter(p=>{let h=p.getBoundingClientRect();return h.width>0&&h.height>0&&p.getAttribute("aria-disabled")!=="true"&&n.test(p.textContent??"")});l=f[f.length-1]??null,l&&console.log(`[auto-webmcp] orphan: using page-wide fallback submit button: "${l.textContent?.trim()}"`)}console.log("[auto-webmcp] orphan: submit button for group:",l?`"${l.textContent?.trim()}" disabled=${l.disabled}`:"none");let u=Ae(r,c,l);if(j.has(u.name)){console.log(`[auto-webmcp] orphan: "${u.name}" already registered, skipping`);continue}let m=De(u.name);m!==u.name&&e.debug&&console.warn(`[auto-webmcp] orphan tool name collision: "${u.name}" renamed to "${m}"`),u.name=m,console.log(`[auto-webmcp] orphan: tool="${u.name}" schema keys:`,Object.keys(u.inputSchema.properties));let d=[],b=u.inputSchema.properties,T=/^_r_[0-9a-z]+_$/i;for(let f of c){let p=f.id&&!T.test(f.id)?f.id:null,h=f.name||f.getAttribute("name")||f.dataset.webmcpName||p||f.getAttribute("aria-label")||f.getAttribute("placeholder")||null,L=h?h.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64):null,y=!!(L&&b[L]);console.log(`[auto-webmcp] orphan: field (name="${f.name??""}" id="${f.id}") rawKey="${h}" safeKey="${L}" matched=${y}`),y&&d.push({key:L,el:f})}if(console.log(`[auto-webmcp] orphan: ${d.length}/${c.length} input(s) mapped to schema keys`),d.length===0){console.log(`[auto-webmcp] orphan: skipping group "${u.name}" \u2014 no inputs mapped to schema keys`);continue}let w=u.name,M=async(f,p)=>{console.log(`[auto-webmcp] orphan execute: tool="${w}" params=`,f),console.log("[auto-webmcp] orphan execute: inputPairs=",d.map(y=>y.key));for(let{key:y,el:g}of d)f[y]!==void 0?(console.log(`[auto-webmcp] orphan execute: filling key="${y}" value=`,f[y],"element=",g),g.getAttribute("role")==="combobox"&&g.tagName.toLowerCase()==="button"?await _e(g,f[y]):Be(g,f[y]),console.log("[auto-webmcp] orphan execute: after fill, element value=",g.value)):console.log(`[auto-webmcp] orphan execute: key="${y}" not in params, skipping`);if(window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:w}})),!(e.autoSubmit||!!l?.hasAttribute("toolautosubmit")||l instanceof HTMLElement&&l.dataset.webmcpAutosubmit!==void 0||r.hasAttribute("toolautosubmit")||r instanceof HTMLElement&&r.dataset.webmcpAutosubmit!==void 0))return console.log("[auto-webmcp] orphan execute: autoSubmit=false, returning without clicking submit"),{content:[{type:"text",text:"Fields filled. Ready to submit."}]};console.log("[auto-webmcp] orphan execute: resolving submit button (up to 2s)...");let L=null;if(l&&document.contains(l)){let y=!l.disabled&&l.getAttribute("aria-disabled")!=="true",g=l.getBoundingClientRect();y&&g.width>0&&g.height>0&&(L=l,console.log(`[auto-webmcp] orphan execute: using captured submit button "${L.textContent?.trim()}"`))}if(!L){let y=Date.now()+2e3;for(;Date.now()<y;){let g=Array.from(r.querySelectorAll(t)).filter(U=>{let le=U.getBoundingClientRect();return le.width>0&&le.height>0}),x=g[g.length-1]??null;if(x){L=x;break}await new Promise(U=>setTimeout(U,100))}}if(!L){let y=Array.from((r!==document.body?r:document).querySelectorAll('button, [role="button"]')).filter(g=>{let x=g.getBoundingClientRect();return x.width>0&&x.height>0&&!g.disabled&&g.getAttribute("aria-disabled")!=="true"&&n.test(g.textContent??"")});L=y[y.length-1]??null,L&&console.log(`[auto-webmcp] orphan execute: using text-matched fallback button "${L.textContent?.trim()}"`)}return L?(console.log(`[auto-webmcp] orphan execute: clicking submit button "${L.textContent?.trim()}"`),L.click(),{content:[{type:"text",text:"Fields filled and form submitted."}]}):(console.warn("[auto-webmcp] orphan execute: submit button still disabled after 2s"),{content:[{type:"text",text:"Fields filled but the submit button is still disabled. The page may require additional input before submitting."}]})};try{let f={name:u.name,description:u.description,inputSchema:u.inputSchema,execute:M};u.annotations&&Object.keys(u.annotations).length>0&&(f.annotations=u.annotations),await navigator.modelContext.registerTool(f),j.add(u.name);let p=window.__pendingSubmitBtns??={};p[u.name]=l,e.debug&&console.log(`[auto-webmcp] Orphan tool registered: ${u.name}`,u)}catch{}}}function Bt(e,t){/^form_\d+$|^submit$|^form$/.test(e)&&console.warn(`[auto-webmcp] Tool "${e}" has a generic name. Consider adding a toolname or data-webmcp-name attribute.`),(!t||t==="Submit form")&&console.warn(`[auto-webmcp] Tool "${e}" has no meaningful description.`),/don'?t|do not|never|avoid|not for/i.test(t)&&console.warn(`[auto-webmcp] Tool "${e}" description contains negative instructions. Per spec best practices, prefer positive descriptions.`)}async function je(e){document.readyState==="loading"&&await new Promise(t=>document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})),We=0,j.clear(),Ft(e),Ot(e),await I(e),await Je(e)}function Ue(){O?.disconnect(),O=null}async function Ve(e){let t=ce(e);return t.debug&&console.debug("[auto-webmcp] Initializing",{webmcpSupported:v(),config:t}),await je(t),{destroy:async()=>{Ue(),await Ce()},getTools:P,isSupported:v()}}typeof window<"u"&&!window.__AUTO_WEBMCP_NO_AUTOINIT&&Ve();return Qe(_t);})();
|
|
2
2
|
//# sourceMappingURL=auto-webmcp.iife.js.map
|