auto-webmcp 0.3.0 → 0.3.1

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.
@@ -1,4 +1,4 @@
1
- "use strict";var AutoWebMCP=(()=>{var F=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var ke=Object.prototype.hasOwnProperty;var Ie=(e,t)=>()=>(e&&(t=e(e=0)),t);var Y=(e,t)=>{for(var n in t)F(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ce(t))!ke.call(e,i)&&i!==n&&F(e,i,{get:()=>t[i],enumerable:!(r=Ae(t,i))||r.enumerable});return e};var Fe=e=>Re(F({},"__esModule",{value:!0}),e);var pe={};Y(pe,{getAllRegisteredTools:()=>q,getRegisteredToolName:()=>et,isWebMCPSupported:()=>T,registerFormTool:()=>_,unregisterAll:()=>D,unregisterFormTool:()=>L});function T(){return typeof navigator<"u"&&typeof navigator.modelContext<"u"}async function _(e,t,n){if(!T())return;h.get(e)&&await L(e);let i={name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n};t.annotations&&Object.keys(t.annotations).length>0&&(i.annotations=t.annotations);try{await navigator.modelContext.registerTool(i)}catch{try{await navigator.modelContext.unregisterTool(t.name),await navigator.modelContext.registerTool(i)}catch{}}h.set(e,t.name)}async function L(e){if(!T())return;let t=h.get(e);if(t){try{await navigator.modelContext.unregisterTool(t)}catch{}h.delete(e)}}function et(e){return h.get(e)}function q(){return Array.from(h.entries()).map(([e,t])=>({form:e,name:t}))}async function D(){let e=Array.from(h.entries());await Promise.all(e.map(([t])=>L(t)))}var h,w=Ie(()=>{"use strict";h=new Map});var yt={};Y(yt,{autoWebMCP:()=>Se});function X(e){return{exclude:e?.exclude??[],autoSubmit:e?.autoSubmit??!1,enhance:e?.enhance??null,overrides:e?.overrides??{},debug:e?.debug??!1}}var M=["textbox","combobox","checkbox","radio","switch","spinbutton","searchbox","slider"];function O(e){return e instanceof HTMLInputElement?Pe(e):e instanceof HTMLTextAreaElement?{type:"string"}:e instanceof HTMLSelectElement?$e(e):null}function Pe(e){switch(e.type.toLowerCase()){case"text":case"search":case"tel":return P(e);case"email":return{...P(e),format:"email"};case"url":return{...P(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 P(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 r=e.ownerDocument.getElementById(n);if(r instanceof HTMLDataListElement){let i=Array.from(r.options).filter(o=>!o.disabled&&o.value.trim()!=="");i.length>0&&(t.enum=i.map(o=>o.value.trim()),t.oneOf=i.map(o=>({const:o.value.trim(),title:o.textContent?.trim()||o.value.trim()})))}}return t}var Oe=/^(select|choose|pick)\b|^--+|---/i;function Q(e){return e.disabled?!0:e.value!==""?!1:Oe.test(e.text.trim())}function $e(e){let t=[],n=[];for(let r of Array.from(e.children))if(r instanceof HTMLOptGroupElement){if(r.disabled)continue;let i=r.label?.trim()??"";for(let o of Array.from(r.children)){if(!(o instanceof HTMLOptionElement)||Q(o))continue;t.push(o.value);let s={const:o.value,title:o.text.trim()||o.value};i&&(s.group=i),n.push(s)}}else if(r instanceof HTMLOptionElement){if(Q(r))continue;t.push(r.value),n.push({const:r.value,title:r.text.trim()||r.value})}return t.length===0?{type:"string"}:e.multiple?{type:"array",items:{type:"string",enum:t}}:{type:"string",enum:t,oneOf:n}}function Z(e,t){return Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(t)}"]`)).map(n=>n.value).filter(n=>n!==""&&n!=="on")}function ee(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).map(r=>r.value).filter(r=>r!=="")}function te(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).filter(r=>r.value!=="").map(r=>{let i=Ne(r);return{const:r.value,title:i||r.value}})}function ne(e,t){switch(t){case"checkbox":case"switch":return{type:"boolean"};case"spinbutton":case"slider":{let n={type:"number"},r=e.getAttribute("aria-valuemin"),i=e.getAttribute("aria-valuemax");return r!==null&&(n.minimum=parseFloat(r)),i!==null&&(n.maximum=parseFloat(i)),n}case"combobox":{let n=e.getAttribute("aria-owns")??e.getAttribute("aria-controls");if(n){let r=document.getElementById(n);if(r){let i=Array.from(r.querySelectorAll('[role="option"]')).filter(o=>o.getAttribute("aria-disabled")!=="true");if(i.length>0){let o=i.map(l=>(l.getAttribute("data-value")??l.textContent??"").trim()).filter(Boolean),s=i.map(l=>({const:(l.getAttribute("data-value")??l.textContent??"").trim(),title:(l.textContent??"").trim()}));return{type:"string",enum:o,oneOf:s}}}}return{type:"string"}}case"textbox":case"searchbox":case"radio":default:return{type:"string"}}}function Ne(e){let t=e.closest("label");if(t){let n=t.cloneNode(!0);n.querySelectorAll("input, select, textarea, button").forEach(i=>i.remove());let r=n.textContent?.trim()??"";if(r)return r}if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let r=n.textContent?.trim()??"";if(r)return r}}return""}var oe=0;function se(e,t){let n=t?.name??_e(e),r=t?.description??De(e),{schema:i,fieldElements:o}=Ve(e),s=Je(e);return{name:n,description:r,inputSchema:i,annotations:s,fieldElements:o}}function _e(e){let t=e.getAttribute("toolname");if(t)return b(t);let n=e.dataset.webmcpName;if(n)return b(n);let r=$(e);if(r)return b(r);let i=ae(e);if(i)return b(i);if(e.id)return b(e.id);if(e.name)return b(e.name);if(e.action){let o=qe(e.action);if(o)return b(o)}return`form_${++oe}`}function b(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)||"form"}function $(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 r=n instanceof HTMLInputElement?n.value.trim():n.textContent?.trim()??"";if(r&&r.length>0&&r.length<80)return r}return""}function ae(e){let t=e;for(;t;){let n=t.previousElementSibling;for(;n;){if(/^H[1-3]$/i.test(n.tagName)){let r=n.textContent?.trim()??"";if(r)return r}n=n.previousElementSibling}if(t=t.parentElement,!t||t===document.body)break}return""}function qe(e){try{let n=new URL(e,window.location.href).pathname.split("/").filter(Boolean);return n[n.length-1]??""}catch{return""}}function De(e){let t=e.getAttribute("tooldescription");if(t)return t.trim();let n=e.dataset.webmcpDescription;if(n)return n.trim();let r=e.querySelector("legend");if(r?.textContent?.trim())return r.textContent.trim();let i=e.getAttribute("aria-label");if(i?.trim())return i.trim();let o=e.getAttribute("aria-describedby");if(o){let a=document.getElementById(o);if(a?.textContent?.trim())return a.textContent.trim()}let s=ae(e),l=document.title?.trim();return s&&l?`${s} \u2014 ${l}`:s||l||"Submit form"}var Be=/^(search|find|look|filter|browse|view|show|check|preview|get|fetch|retrieve|load)\b/i,We=/^(delete|remove|cancel|terminate|destroy|purge|revoke|unsubscribe|deactivate)\b/i,je=/\/(delete|remove|cancel|destroy)\b/i;function Je(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 r=e.method.toLowerCase()==="get",i=$(e),o=i?Be.test(i.trim()):!1;(r||o)&&(t.readOnlyHint=!0)}if(t.destructiveHint===void 0){let r=$(e),i=r?We.test(r.trim()):!1,o=e.action?je.test(e.action):!1;(i||o)&&(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 Ue(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 Ve(e){let t={},n=[],r=new Map,i=new Set,o=new Set,s=Array.from(e.querySelectorAll("input, textarea, select"));for(let c of s){let d=c.name,u=d||le(c);if(!u)continue;if(c instanceof HTMLInputElement&&c.type==="radio"){if(i.has(u))continue;i.add(u)}if(c instanceof HTMLInputElement&&c.type==="checkbox"){if(o.has(u))continue;o.add(u)}let m=O(c);if(!m||!me(c))continue;m.title=ce(c);let g=ue(c);g&&(m.description=g);let f=Ue(c);if(f!==void 0&&(m.default=f),c instanceof HTMLInputElement&&c.type==="radio"){m.enum=ee(e,u);let p=te(e,u);p.length>0&&(m.oneOf=p);let E=e.querySelector(`input[type="radio"][name="${CSS.escape(u)}"]:checked`);E?.value&&(m.default=E.value)}if(c instanceof HTMLInputElement&&c.type==="checkbox"){let p=Z(e,u);if(p.length>1){let E={type:"array",items:{type:"string",enum:p},title:m.title};m.description&&(E.description=m.description);let K=Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(u)}"]:checked`)).map(we=>we.value);K.length>0&&(E.default=K),t[u]=E,c.required&&n.push(u);continue}}t[u]=m,d||r.set(u,c),c.required&&n.push(u)}let l=ze(e),a=new Set;for(let{el:c,role:d,key:u,enumValues:m,enumOneOf:g}of l){if(t[u])continue;if(d==="radio"){if(a.has(u))continue;a.add(u)}let f=ne(c,d);m&&m.length>0&&(f.enum=m,g&&g.length>0&&(f.oneOf=g)),f.title=Ge(c);let p=Ke(c);p&&(f.description=p),t[u]=f,r.set(u,c),c.getAttribute("aria-required")==="true"&&n.push(u)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}function le(e){let t=e;if(t.dataset.webmcpName)return b(t.dataset.webmcpName);if(e.id)return b(e.id);let n=e.getAttribute("aria-label");return n?b(n):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?b(e.placeholder.trim()):e instanceof HTMLInputElement&&e.type!=="text"?e.type:null}function ze(e){let t=M.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"),d=re(a);d&&n.push({el:a,role:c,key:d})}let r=n.filter(a=>a.role==="radio"),i=n.filter(a=>a.role!=="radio"),o=new Map,s=[];for(let a of r){let c=a.el.closest('[role="radiogroup"]');c?(o.has(c)||o.set(c,[]),o.get(c).push(a.el)):s.push(a)}let l=[];for(let[a,c]of o){let d=re(a);if(!d)continue;let u=c.map(g=>(g.getAttribute("data-value")??g.getAttribute("aria-label")??g.textContent??"").trim()).filter(Boolean),m=c.map(g=>{let f=(g.getAttribute("data-value")??g.getAttribute("aria-label")??g.textContent??"").trim(),p=(g.getAttribute("aria-label")??g.textContent??"").trim();return{const:f,title:p||f}}).filter(g=>g.const!=="");u.length>0&&l.push({el:a,role:"radio",key:d,enumValues:u,enumOneOf:m})}return[...i,...l,...s]}function re(e){let t=e;if(t.dataset?.webmcpName)return b(t.dataset.webmcpName);if(e.id)return b(e.id);let n=e.getAttribute("aria-label");if(n)return b(n);let r=e.getAttribute("aria-labelledby");if(r){let i=document.getElementById(r)?.textContent?.trim();if(i)return b(i)}return null}function Ge(e){let t=e.getAttribute("toolparamtitle");if(t?.trim())return t.trim();let n=e;if(n.dataset?.webmcpTitle)return n.dataset.webmcpTitle;let r=e.getAttribute("aria-label");if(r)return r.trim();let i=e.getAttribute("aria-labelledby");if(i){let o=document.getElementById(i)?.textContent?.trim();if(o)return o}return e.id?N(e.id):""}function Ke(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let n=e;if(n.dataset?.webmcpDescription)return n.dataset.webmcpDescription;let r=e.getAttribute("aria-description");if(r)return r;let i=e.getAttribute("aria-describedby");if(i){let s=document.getElementById(i)?.textContent?.trim();if(s)return s}let o=e.getAttribute("placeholder")??e.dataset?.placeholder;return o?o.trim():""}function ce(e){let t=e.getAttribute("toolparamtitle");if(t?.trim())return t.trim();if("dataset"in e&&e.dataset.webmcpTitle)return e.dataset.webmcpTitle;let n=Ye(e);return n||(e.name?N(e.name):e.id?N(e.id):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?e.placeholder.trim():"")}function ue(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let n=e;if(n.dataset.webmcpDescription)return n.dataset.webmcpDescription;let r=e.getAttribute("aria-description");if(r)return r;let i=e.getAttribute("aria-describedby");if(i){let o=document.getElementById(i);if(o?.textContent?.trim())return o.textContent.trim()}if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement){let o=e.placeholder?.trim();if(o&&o.length>0)return o}return""}function Ye(e){if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let r=ie(n);if(r)return r}}let t=e.closest("label");if(t){let n=ie(t);if(n)return n}return""}function ie(e){let t=e.cloneNode(!0);return t.querySelectorAll("input, select, textarea, button").forEach(n=>n.remove()),t.textContent?.trim()??""}function N(e){return e.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim().replace(/\b\w/g,t=>t.toUpperCase())}function me(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 de(e,t,n){let r=Xe(e,n),i=Qe(e),{schema:o,fieldElements:s}=Ze(t);return{name:r,description:i,inputSchema:o,fieldElements:s}}function Xe(e,t){if(t){let i=t instanceof HTMLInputElement?t.value.trim():t.textContent?.trim()??"";if(i&&i.length>0&&i.length<80)return b(i)}let n=fe(e);if(n)return b(n);let r=document.title?.trim();return r?b(r):`form_${++oe}`}function Qe(e){let t=fe(e),n=document.title?.trim();return t&&n&&t!==n?`${t} on ${n}`:t||n||"Submit form"}function fe(e){let t=e.querySelector("h1, h2, h3");if(t?.textContent?.trim())return t.textContent.trim();let n=e;for(;n;){let r=n.previousElementSibling;for(;r;){if(/^H[1-3]$/i.test(r.tagName)){let i=r.textContent?.trim()??"";if(i)return i}r=r.previousElementSibling}if(n=n.parentElement,!n||n===document.body)break}return""}function Ze(e){let t={},n=[],r=new Map,i=new Set,o=new Set;for(let s of e){let l=s.name,a=l||le(s);if(!a)continue;if(s instanceof HTMLInputElement&&s.type==="radio"){if(i.has(a))continue;i.add(a)}if(s instanceof HTMLInputElement&&s.type==="checkbox"){if(o.has(a))continue;o.add(a)}let c=O(s);if(!c||!me(s))continue;c.title=ce(s);let d=ue(s);if(d&&(c.description=d),s instanceof HTMLInputElement&&s.type==="checkbox"){let u=e.filter(m=>m instanceof HTMLInputElement&&m.type==="checkbox"&&m.name===a).map(m=>m.value).filter(m=>m!==""&&m!=="on");if(u.length>1){let m={type:"array",items:{type:"string",enum:u},title:c.title};c.description&&(m.description=c.description),t[a]=m,s.required&&n.push(a);continue}}t[a]=c,l||r.set(a,s),s.required&&n.push(a)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}w();var A=new WeakMap,Te=new WeakMap,C=new WeakMap,W=new WeakMap,x=new WeakMap,k=new WeakMap,tt=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set,nt=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set,y=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked")?.set;function he(e,t,n,r){return r?.fieldElements&&C.set(e,r.fieldElements),ge(e,n),async i=>(x.set(e,[]),B(e,i),window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:n}})),new Promise((o,s)=>{A.set(e,{resolve:o,reject:s}),(t.autoSubmit||e.hasAttribute("toolautosubmit")||e.dataset.webmcpAutosubmit!==void 0)&&Ee(e).then(async()=>{try{B(e,i);for(let c=0;c<2&&it(e,i,C.get(e)).length!==0;c++)B(e,i),await Ee(e,400,100);let l=e;if(!e.isConnected){let d=document.querySelector('button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])')?.closest("form");d&&(l=d,A.set(l,{resolve:o,reject:s}),ge(l,n))}let a=ot(r,i);a.length>0&&W.set(l,a),l.requestSubmit()}catch(l){s(l instanceof Error?l:new Error(String(l)))}})}))}function ge(e,t){e.__awmcp_intercepted||(e.__awmcp_intercepted=!0,e.addEventListener("submit",n=>{let r=A.get(e);if(!r)return;let{resolve:i}=r;A.delete(e);let o=rt(e,Te.get(e),C.get(e));k.delete(e);let s=W.get(e);W.delete(e);let l=x.get(e)??[];x.delete(e);let a=[...s?.length?[`required fields were not filled: ${s.join(", ")}`]:[],...l],c=a.length?` Note: ${a.join("; ")}.`:"",u={content:[{type:"text",text:`Form submitted. Fields: ${JSON.stringify(o)}${c}`}]};n.agentInvoked&&typeof n.respondWith=="function"&&(n.preventDefault(),n.respondWith(Promise.resolve(u))),i(u)}),e.addEventListener("reset",()=>{k.delete(e),window.dispatchEvent(new CustomEvent("toolcancel",{detail:{toolName:t}}))}))}function H(e,t){if(e.focus(),e.select?.(),document.execCommand("insertText",!1,t)&&e.value===t)return;let n=e instanceof HTMLTextAreaElement?nt:tt;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 j(e,t){y?y.call(e,t):e.checked=t,e.dispatchEvent(new Event("change",{bubbles:!0}))}function I(e,t){for(let n of Array.from(e.querySelectorAll("*"))){let r=n.shadowRoot;if(!r)continue;let i=r.querySelector(t);if(i)return i;let o=I(r,t);if(o)return o}return null}function U(e,t){let n=CSS.escape(t),r=e.querySelector(`[name="${n}"]`)??e.querySelector(`input#${n}, textarea#${n}, select#${n}`);return r||(I(document,`[name="${n}"]`)??I(document,`input#${n}, textarea#${n}, select#${n}`))}function B(e,t){Te.set(e,t);let n=C.get(e),r={};for(let[i,o]of Object.entries(t)){let s=U(e,i);if(s){if(s instanceof HTMLInputElement)if(be(s,e,i,o),s.type==="checkbox")if(Array.isArray(o)){let a=CSS.escape(i);r[i]=Array.from(e.querySelectorAll(`input[type="checkbox"][name="${a}"]`)).filter(c=>c.checked).map(c=>c.value)}else r[i]=s.checked;else r[i]=s.value;else s instanceof HTMLTextAreaElement?(H(s,String(o??"")),r[i]=s.value):s instanceof HTMLSelectElement&&(J(s,o),r[i]=s.multiple?Array.from(s.options).filter(a=>a.selected).map(a=>a.value):s.value);continue}let l=n?.get(i);if(l){let a=l;if(!l.isConnected){let c=l.id;if(c){let d=document.getElementById(c)??I(document,`#${CSS.escape(c)}`);d&&(a=d)}}a instanceof HTMLInputElement?(be(a,e,i,o),r[i]=a.type==="checkbox"?a.checked:a.value):a instanceof HTMLTextAreaElement?(H(a,String(o??"")),r[i]=a.value):a instanceof HTMLSelectElement?(J(a,o),r[i]=a.multiple?Array.from(a.options).filter(c=>c.selected).map(c=>c.value):a.value):(ye(a,o),r[i]=o)}}k.set(e,r)}function be(e,t,n,r){let i=e.type.toLowerCase();if(i==="checkbox"){if(Array.isArray(r)){let o=CSS.escape(n),s=t.querySelectorAll(`input[type="checkbox"][name="${o}"]`);for(let l of s)j(l,r.map(String).includes(l.value));return}j(e,!!r);return}if(i==="number"||i==="range"){let o=String(r??""),s=Number(o);if(o===""||isNaN(s)){x.get(t)?.push(`"${n}" expects a number, got: ${JSON.stringify(r)}`);return}let l=e.min!==""?parseFloat(e.min):-1/0,a=e.max!==""?parseFloat(e.max):1/0;s<l||s>a?(x.get(t)?.push(`"${n}" value ${s} is outside allowed range [${e.min||"?"}, ${e.max||"?"}]`),e.value=String(Math.min(Math.max(s,l),a))):e.value=String(s),e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:String(s)})),e.dispatchEvent(new Event("change",{bubbles:!0}));return}if(i==="radio"){let o=CSS.escape(n),s=t.querySelectorAll(`input[type="radio"][name="${o}"]`);for(let l of s)if(l.value===String(r)){y?y.call(l,!0):l.checked=!0,l.dispatchEvent(new Event("change",{bubbles:!0}));break}return}H(e,String(r??""))}function J(e,t){if(e.multiple){let n=Array.isArray(t)?t.map(String):[String(t??"")];for(let r of Array.from(e.options))r.selected=n.includes(r.value);e.dispatchEvent(new Event("change",{bubbles:!0}));return}e.value=String(t??""),e.dispatchEvent(new Event("change",{bubbles:!0}))}function ye(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 i=Array.from(e.querySelectorAll('[role="radio"]'));for(let o of i)if((o.getAttribute("data-value")??o.getAttribute("aria-label")??o.textContent??"").trim()===String(t)){o.setAttribute("aria-checked","true"),o.dispatchEvent(new MouseEvent("click",{bubbles:!0}));for(let l of i)l!==o&&l.setAttribute("aria-checked","false");break}return}let r=e;r.isContentEditable&&(r.textContent=String(t??"")),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function rt(e,t,n){let r={},i=new FormData(e),o=k.get(e);for(let[s,l]of i.entries())if(r[s]!==void 0){let a=r[s];Array.isArray(a)?a.push(l):r[s]=[a,l]}else r[s]=l;if(t)for(let s of Object.keys(t)){if(s in r)continue;if(o&&s in o){r[s]=o[s];continue}let l=U(e,s)??n?.get(s)??null;if(l)if(l instanceof HTMLInputElement&&l.type==="checkbox")r[s]=l.checked;else if(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement)r[s]=l.value;else{let a=l.getAttribute("role");a==="checkbox"||a==="switch"?r[s]=l.getAttribute("aria-checked")==="true":r[s]=l.textContent?.trim()??""}}return r}function Me(e,t){if(e instanceof HTMLInputElement){let n=e.type.toLowerCase();n==="checkbox"?j(e,!!t):n==="radio"?e.value===String(t)&&(y?y.call(e,!0):e.checked=!0,e.dispatchEvent(new Event("change",{bubbles:!0}))):H(e,String(t??""))}else e instanceof HTMLTextAreaElement?H(e,String(t??"")):e instanceof HTMLSelectElement?J(e,t):ye(e,t)}function Ee(e,t=800,n=150){return new Promise(r=>{let i=!1,o=null,s=()=>{i||(i=!0,l.disconnect(),o!==null&&clearTimeout(o),r())},l=new MutationObserver(()=>{o!==null&&clearTimeout(o),o=setTimeout(s,n)});l.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),setTimeout(s,t),o=setTimeout(s,n)})}function it(e,t,n){let r=[];for(let[i,o]of Object.entries(t)){let s=U(e,i)??n?.get(i)??null;s&&(s instanceof HTMLInputElement&&s.type==="checkbox"?s.checked!==!!o&&r.push(i):(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)&&s.value!==String(o??"")&&r.push(i))}return r}function ot(e,t){return e?.inputSchema?.required?.length?e.inputSchema.required.filter(n=>!(n in t)):[]}async function Le(e,t){try{let n=await st(e,t);return{...e,description:n}}catch(n){return console.warn("[auto-webmcp] Enrichment failed, using heuristic description:",n),e}}async function st(e,t){let n=at(e);return t.provider==="claude"?lt(n,t):ct(n,t)}function at(e){let t=Object.entries(e.inputSchema.properties).map(([n,r])=>`- ${r.title??n} (${r.type}): ${r.description??""}`).join(`
1
+ "use strict";var AutoWebMCP=(()=>{var P=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var Re=(e,t)=>()=>(e&&(t=e(e=0)),t);var Y=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},Fe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ke(t))!Ie.call(e,i)&&i!==n&&P(e,i,{get:()=>t[i],enumerable:!(r=Ce(t,i))||r.enumerable});return e};var Pe=e=>Fe(P({},"__esModule",{value:!0}),e);var ge={};Y(ge,{getAllRegisteredTools:()=>D,getRegisteredToolName:()=>tt,isWebMCPSupported:()=>h,registerFormTool:()=>q,unregisterAll:()=>B,unregisterFormTool:()=>x});function h(){return typeof navigator<"u"&&typeof navigator.modelContext<"u"}async function q(e,t,n){if(!h())return;T.get(e)&&await x(e);let i={name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n};t.annotations&&Object.keys(t.annotations).length>0&&(i.annotations=t.annotations);try{await navigator.modelContext.registerTool(i)}catch{try{await navigator.modelContext.unregisterTool(t.name),await navigator.modelContext.registerTool(i)}catch{}}T.set(e,t.name)}async function x(e){if(!h())return;let t=T.get(e);if(t){try{await navigator.modelContext.unregisterTool(t)}catch{}T.delete(e)}}function tt(e){return T.get(e)}function D(){return Array.from(T.entries()).map(([e,t])=>({form:e,name:t}))}async function B(){let e=Array.from(T.entries());await Promise.all(e.map(([t])=>x(t)))}var T,A=Re(()=>{"use strict";T=new Map});var Mt={};Y(Mt,{autoWebMCP:()=>ve});function X(e){return{exclude:e?.exclude??[],autoSubmit:e?.autoSubmit??!1,enhance:e?.enhance??null,overrides:e?.overrides??{},debug:e?.debug??!1}}var L=["textbox","combobox","checkbox","radio","switch","spinbutton","searchbox","slider"];function $(e){return e instanceof HTMLInputElement?Oe(e):e instanceof HTMLTextAreaElement?{type:"string"}:e instanceof HTMLSelectElement?_e(e):null}function Oe(e){switch(e.type.toLowerCase()){case"text":case"search":case"tel":return O(e);case"email":return{...O(e),format:"email"};case"url":return{...O(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 O(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 r=e.ownerDocument.getElementById(n);if(r instanceof HTMLDataListElement){let i=Array.from(r.options).filter(o=>!o.disabled&&o.value.trim()!=="");i.length>0&&(t.enum=i.map(o=>o.value.trim()),t.oneOf=i.map(o=>({const:o.value.trim(),title:o.textContent?.trim()||o.value.trim()})))}}return t}var $e=/^(select|choose|pick)\b|^--+|---/i;function Q(e){return e.disabled?!0:e.value!==""?!1:$e.test(e.text.trim())}function _e(e){let t=[],n=[];for(let r of Array.from(e.children))if(r instanceof HTMLOptGroupElement){if(r.disabled)continue;let i=r.label?.trim()??"";for(let o of Array.from(r.children)){if(!(o instanceof HTMLOptionElement)||Q(o))continue;t.push(o.value);let s={const:o.value,title:o.text.trim()||o.value};i&&(s.group=i),n.push(s)}}else if(r instanceof HTMLOptionElement){if(Q(r))continue;t.push(r.value),n.push({const:r.value,title:r.text.trim()||r.value})}return t.length===0?{type:"string"}:e.multiple?{type:"array",items:{type:"string",enum:t}}:{type:"string",enum:t,oneOf:n}}function Z(e,t){return Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(t)}"]`)).map(n=>n.value).filter(n=>n!==""&&n!=="on")}function ee(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).map(r=>r.value).filter(r=>r!=="")}function te(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).filter(r=>r.value!=="").map(r=>{let i=Ne(r);return{const:r.value,title:i||r.value}})}function ne(e,t){switch(t){case"checkbox":case"switch":return{type:"boolean"};case"spinbutton":case"slider":{let n={type:"number"},r=e.getAttribute("aria-valuemin"),i=e.getAttribute("aria-valuemax");return r!==null&&(n.minimum=parseFloat(r)),i!==null&&(n.maximum=parseFloat(i)),n}case"combobox":{let n=e.getAttribute("aria-owns")??e.getAttribute("aria-controls");if(n){let r=document.getElementById(n);if(r){let i=Array.from(r.querySelectorAll('[role="option"]')).filter(o=>o.getAttribute("aria-disabled")!=="true");if(i.length>0){let o=i.map(c=>(c.getAttribute("data-value")??c.textContent??"").trim()).filter(Boolean),s=i.map(c=>({const:(c.getAttribute("data-value")??c.textContent??"").trim(),title:(c.textContent??"").trim()}));return{type:"string",enum:o,oneOf:s}}}}return{type:"string"}}case"textbox":case"searchbox":case"radio":default:return{type:"string"}}}function Ne(e){let t=e.closest("label");if(t){let n=t.cloneNode(!0);n.querySelectorAll("input, select, textarea, button").forEach(i=>i.remove());let r=n.textContent?.trim()??"";if(r)return r}if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let r=n.textContent?.trim()??"";if(r)return r}}return""}var oe=0;function se(e,t){let n=t?.name??qe(e),r=t?.description??Be(e),{schema:i,fieldElements:o}=ze(e),s=Ue(e);return{name:n,description:r,inputSchema:i,annotations:s,fieldElements:o}}function qe(e){let t=e.getAttribute("toolname");if(t)return E(t);let n=e.dataset.webmcpName;if(n)return E(n);let r=_(e);if(r)return E(r);let i=ae(e);if(i)return E(i);if(e.id)return E(e.id);if(e.name)return E(e.name);if(e.action){let o=De(e.action);if(o)return E(o)}return`form_${++oe}`}function E(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)||"form"}function _(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 r=n instanceof HTMLInputElement?n.value.trim():n.textContent?.trim()??"";if(r&&r.length>0&&r.length<80)return r}return""}function ae(e){let t=e;for(;t;){let n=t.previousElementSibling;for(;n;){if(/^H[1-3]$/i.test(n.tagName)){let r=n.textContent?.trim()??"";if(r)return r}n=n.previousElementSibling}if(t=t.parentElement,!t||t===document.body)break}return""}function De(e){try{let n=new URL(e,window.location.href).pathname.split("/").filter(Boolean);return n[n.length-1]??""}catch{return""}}function Be(e){let t=e.getAttribute("tooldescription");if(t)return t.trim();let n=e.dataset.webmcpDescription;if(n)return n.trim();let r=e.querySelector("legend");if(r?.textContent?.trim())return r.textContent.trim();let i=e.getAttribute("aria-label");if(i?.trim())return i.trim();let o=e.getAttribute("aria-describedby");if(o){let a=document.getElementById(o);if(a?.textContent?.trim())return a.textContent.trim()}let s=ae(e),c=document.title?.trim();return s&&c?`${s} \u2014 ${c}`:s||c||"Submit form"}var We=/^(search|find|look|filter|browse|view|show|check|preview|get|fetch|retrieve|load)\b/i,je=/^(delete|remove|cancel|terminate|destroy|purge|revoke|unsubscribe|deactivate)\b/i,Je=/\/(delete|remove|cancel|destroy)\b/i;function Ue(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 r=e.method.toLowerCase()==="get",i=_(e),o=i?We.test(i.trim()):!1;(r||o)&&(t.readOnlyHint=!0)}if(t.destructiveHint===void 0){let r=_(e),i=r?je.test(r.trim()):!1,o=e.action?Je.test(e.action):!1;(i||o)&&(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 Ve(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 le(e,t=new Set){if(t.has(e))return[];t.add(e);let n=[];for(let r of Array.from(e.querySelectorAll("*")))r.shadowRoot&&n.push(...Array.from(r.shadowRoot.querySelectorAll("input, textarea, select")),...le(r.shadowRoot,t));return n}function ze(e){let t={},n=[],r=new Map,i=new Set,o=new Set,s=[...Array.from(e.querySelectorAll("input, textarea, select")),...le(e)];for(let l of s){let p=l.name,m=p||ce(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(o.has(m))continue;o.add(m)}let d=$(l);if(!d||!de(l))continue;d.title=ue(l);let f=me(l);f&&(d.description=f);let u=Ve(l);if(u!==void 0&&(d.default=u),l instanceof HTMLInputElement&&l.type==="radio"){d.enum=ee(e,m);let g=te(e,m);g.length>0&&(d.oneOf=g);let b=e.querySelector(`input[type="radio"][name="${CSS.escape(m)}"]:checked`);b?.value&&(d.default=b.value)}if(l instanceof HTMLInputElement&&l.type==="checkbox"){let g=Z(e,m);if(g.length>1){let b={type:"array",items:{type:"string",enum:g},title:d.title};d.description&&(b.description=d.description);let K=Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(m)}"]:checked`)).map(Ae=>Ae.value);K.length>0&&(b.default=K),t[m]=b,l.required&&n.push(m);continue}}t[m]=d,p||r.set(m,l),l.required&&n.push(m)}let c=Ge(e),a=new Set;for(let{el:l,role:p,key:m,enumValues:d,enumOneOf:f}of c){if(t[m])continue;if(p==="radio"){if(a.has(m))continue;a.add(m)}let u=ne(l,p);d&&d.length>0&&(u.enum=d,f&&f.length>0&&(u.oneOf=f)),u.title=Ke(l);let g=Ye(l);g&&(u.description=g),t[m]=u,r.set(m,l),l.getAttribute("aria-required")==="true"&&n.push(m)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}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");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 Ge(e){let t=L.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 l=a.getAttribute("role"),p=re(a);p&&n.push({el:a,role:l,key:p})}let r=n.filter(a=>a.role==="radio"),i=n.filter(a=>a.role!=="radio"),o=new Map,s=[];for(let a of r){let l=a.el.closest('[role="radiogroup"]');l?(o.has(l)||o.set(l,[]),o.get(l).push(a.el)):s.push(a)}let c=[];for(let[a,l]of o){let p=re(a);if(!p)continue;let m=l.map(f=>(f.getAttribute("data-value")??f.getAttribute("aria-label")??f.textContent??"").trim()).filter(Boolean),d=l.map(f=>{let u=(f.getAttribute("data-value")??f.getAttribute("aria-label")??f.textContent??"").trim(),g=(f.getAttribute("aria-label")??f.textContent??"").trim();return{const:u,title:g||u}}).filter(f=>f.const!=="");m.length>0&&c.push({el:a,role:"radio",key:p,enumValues:m,enumOneOf:d})}return[...i,...c,...s]}function re(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 r=e.getAttribute("aria-labelledby");if(r){let i=document.getElementById(r)?.textContent?.trim();if(i)return E(i)}return null}function Ke(e){let t=e;if(t.dataset?.webmcpTitle)return t.dataset.webmcpTitle;let n=e.getAttribute("aria-label");if(n)return n.trim();let r=e.getAttribute("aria-labelledby");if(r){let i=document.getElementById(r)?.textContent?.trim();if(i)return i}return e.id?N(e.id):""}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 r=e.getAttribute("aria-description");if(r)return r;let i=e.getAttribute("aria-describedby");if(i){let s=document.getElementById(i)?.textContent?.trim();if(s)return s}let o=e.getAttribute("placeholder")??e.dataset?.placeholder;return o?o.trim():""}function ue(e){if("dataset"in e&&e.dataset.webmcpTitle)return e.dataset.webmcpTitle;let t=Xe(e);return t||(e.name?N(e.name):e.id?N(e.id):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?e.placeholder.trim():"")}function me(e){let t=e.getAttribute("toolparamdescription");if(t)return t.trim();let n=e;if(n.dataset.webmcpDescription)return n.dataset.webmcpDescription;let r=e.getAttribute("aria-description");if(r)return r;let i=e.getAttribute("aria-describedby");if(i){let o=document.getElementById(i);if(o?.textContent?.trim())return o.textContent.trim()}if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement){let o=e.placeholder?.trim();if(o&&o.length>0)return o}return""}function Xe(e){if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let r=ie(n);if(r)return r}}let t=e.closest("label");if(t){let n=ie(t);if(n)return n}return""}function ie(e){let t=e.cloneNode(!0);return t.querySelectorAll("input, select, textarea, button").forEach(n=>n.remove()),t.textContent?.trim()??""}function N(e){return e.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim().replace(/\b\w/g,t=>t.toUpperCase())}function de(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 pe(e,t,n){let r=Qe(e,n),i=Ze(e),{schema:o,fieldElements:s}=et(t);return{name:r,description:i,inputSchema:o,fieldElements:s}}function Qe(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 n=fe(e);if(n)return E(n);let r=document.title?.trim();return r?E(r):`form_${++oe}`}function Ze(e){let t=fe(e),n=document.title?.trim();return t&&n&&t!==n?`${t} on ${n}`:t||n||"Submit form"}function fe(e){let t=e.querySelector("h1, h2, h3");if(t?.textContent?.trim())return t.textContent.trim();let n=e;for(;n;){let r=n.previousElementSibling;for(;r;){if(/^H[1-3]$/i.test(r.tagName)){let i=r.textContent?.trim()??"";if(i)return i}r=r.previousElementSibling}if(n=n.parentElement,!n||n===document.body)break}return""}function et(e){let t={},n=[],r=new Map,i=new Set,o=new Set;for(let s of e){let c=s.name,a=c||ce(s);if(!a)continue;if(s instanceof HTMLInputElement&&s.type==="radio"){if(i.has(a))continue;i.add(a)}if(s instanceof HTMLInputElement&&s.type==="checkbox"){if(o.has(a))continue;o.add(a)}let l=$(s);if(!l||!de(s))continue;l.title=ue(s);let p=me(s);if(p&&(l.description=p),s instanceof HTMLInputElement&&s.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,s.required&&n.push(a);continue}}t[a]=l,c||r.set(a,s),s.required&&n.push(a)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}A();var C=new WeakMap,Te=new WeakMap,k=new WeakMap,y=new WeakMap,H=new WeakMap,I=new WeakMap,nt=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set,rt=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set,M=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked")?.set;function ye(e,t,n,r){return r?.fieldElements&&k.set(e,r.fieldElements),Ee(e,n),async i=>{H.set(e,[]),W(e,i);let o=st(r,i);return o.length>0&&y.set(e,o),window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:n}})),new Promise((s,c)=>{C.set(e,{resolve:s,reject:c}),(t.autoSubmit||e.hasAttribute("toolautosubmit")||e.dataset.webmcpAutosubmit!==void 0)&&he(e).then(async()=>{try{W(e,i);for(let l=0;l<2&&ot(e,i,k.get(e)).length!==0;l++)W(e,i),await he(e,400,100);let a=e;if(!e.isConnected){let p=document.querySelector('button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])')?.closest("form");p&&(a=p,C.set(a,{resolve:s,reject:c}),Ee(a,n))}a!==e&&y.has(e)&&(y.set(a,y.get(e)),y.delete(e)),a.requestSubmit()}catch(a){c(a instanceof Error?a:new Error(String(a)))}})})}}function Ee(e,t){e.__awmcp_intercepted||(e.__awmcp_intercepted=!0,e.addEventListener("submit",n=>{let r=C.get(e);if(!r)return;let{resolve:i}=r;C.delete(e);let o=it(e,Te.get(e),k.get(e));I.delete(e);let s=y.get(e)??[];y.delete(e);let c=H.get(e)??[];H.delete(e);let a=c.filter(u=>u.type==="not_filled").map(u=>u.field),l={status:s.length>0||a.length>0?"partial":"success",filled_fields:o,skipped_fields:a,missing_required:s,warnings:[...s.map(u=>({field:u,type:"missing_required",message:`required field "${u}" was not provided`})),...c]},p=[...s.length?[`required fields were not filled: ${s.join(", ")}`]:[],...c.map(u=>u.message)],m=p.length?` Note: ${p.join("; ")}.`:"",f={content:[{type:"text",text:`Form submitted. Fields: ${JSON.stringify(o)}${m}`},{type:"text",text:JSON.stringify(l)}]};n.agentInvoked&&typeof n.respondWith=="function"&&(n.preventDefault(),n.respondWith(Promise.resolve(f))),i(f)}),e.addEventListener("reset",()=>{I.delete(e),window.dispatchEvent(new CustomEvent("toolcancel",{detail:{toolName:t}}))}))}function S(e,t){if(e.focus(),e.select?.(),document.execCommand("insertText",!1,t)&&e.value===t)return;let n=e instanceof HTMLTextAreaElement?rt:nt;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 j(e,t){M?M.call(e,t):e.checked=t,e.dispatchEvent(new Event("change",{bubbles:!0}))}function R(e,t){for(let n of Array.from(e.querySelectorAll("*"))){let r=n.shadowRoot;if(!r)continue;let i=r.querySelector(t);if(i)return i;let o=R(r,t);if(o)return o}return null}function U(e,t){let n=CSS.escape(t),r=e.querySelector(`[name="${n}"]`)??e.querySelector(`input#${n}, textarea#${n}, select#${n}`);return r||(R(document,`[name="${n}"]`)??R(document,`input#${n}, textarea#${n}, select#${n}`))}function W(e,t){Te.set(e,t);let n=k.get(e),r={};for(let[i,o]of Object.entries(t)){let s=U(e,i);if(s){if(s instanceof HTMLInputElement)if(be(s,e,i,o),s.type==="checkbox")if(Array.isArray(o)){let a=CSS.escape(i);r[i]=Array.from(e.querySelectorAll(`input[type="checkbox"][name="${a}"]`)).filter(l=>l.checked).map(l=>l.value)}else r[i]=s.checked;else r[i]=s.value;else s instanceof HTMLTextAreaElement?(S(s,String(o??"")),r[i]=s.value):s instanceof HTMLSelectElement&&(J(s,o),r[i]=s.multiple?Array.from(s.options).filter(a=>a.selected).map(a=>a.value):s.value);continue}let c=n?.get(i);if(c){let a=c;if(!c.isConnected){let l=c.id;if(l){let p=document.getElementById(l)??R(document,`#${CSS.escape(l)}`);p&&(a=p)}}a instanceof HTMLInputElement?(be(a,e,i,o),r[i]=a.type==="checkbox"?a.checked:a.value):a instanceof HTMLTextAreaElement?(S(a,String(o??"")),r[i]=a.value):a instanceof HTMLSelectElement?(J(a,o),r[i]=a.multiple?Array.from(a.options).filter(l=>l.selected).map(l=>l.value):a.value):(Me(a,o),r[i]=o)}}I.set(e,r)}function be(e,t,n,r){let i=e.type.toLowerCase();if(i==="checkbox"){if(Array.isArray(r)){let o=CSS.escape(n),s=t.querySelectorAll(`input[type="checkbox"][name="${o}"]`);for(let c of s)j(c,r.map(String).includes(c.value));return}j(e,!!r);return}if(i==="number"||i==="range"){let o=String(r??""),s=Number(o);if(o===""||isNaN(s)){H.get(t)?.push({field:n,type:"type_mismatch",message:`"${n}" expects a number, got: ${JSON.stringify(r)}`,original:r});return}let c=e.min!==""?parseFloat(e.min):-1/0,a=e.max!==""?parseFloat(e.max):1/0;if(s<c||s>a){let l=Math.min(Math.max(s,c),a);H.get(t)?.push({field:n,type:"clamped",message:`"${n}" value ${s} is outside allowed range [${e.min||"?"}, ${e.max||"?"}], clamped to ${l}`,original:s,actual:l}),e.value=String(l)}else e.value=String(s);e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:String(s)})),e.dispatchEvent(new Event("change",{bubbles:!0}));return}if(i==="radio"){let o=CSS.escape(n),s=t.querySelectorAll(`input[type="radio"][name="${o}"]`);for(let c of s)if(c.value===String(r)){M?M.call(c,!0):c.checked=!0,c.dispatchEvent(new Event("change",{bubbles:!0}));break}return}S(e,String(r??""))}function J(e,t){if(e.multiple){let n=Array.isArray(t)?t.map(String):[String(t??"")];for(let r of Array.from(e.options))r.selected=n.includes(r.value);e.dispatchEvent(new Event("change",{bubbles:!0}));return}e.value=String(t??""),e.dispatchEvent(new Event("change",{bubbles:!0}))}function Me(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 i=Array.from(e.querySelectorAll('[role="radio"]'));for(let o of i)if((o.getAttribute("data-value")??o.getAttribute("aria-label")??o.textContent??"").trim()===String(t)){o.setAttribute("aria-checked","true"),o.dispatchEvent(new MouseEvent("click",{bubbles:!0}));for(let c of i)c!==o&&c.setAttribute("aria-checked","false");break}return}let r=e;r.isContentEditable&&(r.textContent=String(t??"")),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function it(e,t,n){let r={},i=new FormData(e),o=I.get(e);for(let[s,c]of i.entries())if(r[s]!==void 0){let a=r[s];Array.isArray(a)?a.push(c):r[s]=[a,c]}else r[s]=c;if(t)for(let s of Object.keys(t)){if(s in r)continue;if(o&&s in o){r[s]=o[s];continue}let c=U(e,s)??n?.get(s)??null;if(c)if(c instanceof HTMLInputElement&&c.type==="checkbox")r[s]=c.checked;else if(c instanceof HTMLInputElement||c instanceof HTMLTextAreaElement||c instanceof HTMLSelectElement)r[s]=c.value;else{let a=c.getAttribute("role");a==="checkbox"||a==="switch"?r[s]=c.getAttribute("aria-checked")==="true":r[s]=c.textContent?.trim()??""}}return r}function Le(e,t){if(e instanceof HTMLInputElement){let n=e.type.toLowerCase();n==="checkbox"?j(e,!!t):n==="radio"?e.value===String(t)&&(M?M.call(e,!0):e.checked=!0,e.dispatchEvent(new Event("change",{bubbles:!0}))):S(e,String(t??""))}else e instanceof HTMLTextAreaElement?S(e,String(t??"")):e instanceof HTMLSelectElement?J(e,t):Me(e,t)}function he(e,t=800,n=150){return new Promise(r=>{let i=!1,o=null,s=()=>{i||(i=!0,c.disconnect(),o!==null&&clearTimeout(o),r())},c=new MutationObserver(()=>{o!==null&&clearTimeout(o),o=setTimeout(s,n)});c.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),setTimeout(s,t),o=setTimeout(s,n)})}function ot(e,t,n){let r=[];for(let[i,o]of Object.entries(t)){let s=U(e,i)??n?.get(i)??null;s&&(s instanceof HTMLInputElement&&s.type==="checkbox"?s.checked!==!!o&&r.push(i):(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)&&s.value!==String(o??"")&&r.push(i))}return r}function st(e,t){return e?.inputSchema?.required?.length?e.inputSchema.required.filter(n=>!(n in t)):[]}async function xe(e,t){try{let n=await at(e,t);return{...e,description:n}}catch(n){return console.warn("[auto-webmcp] Enrichment failed, using heuristic description:",n),e}}async function at(e,t){let n=lt(e);return t.provider==="claude"?ct(n,t):ut(n,t)}function lt(e){let t=Object.entries(e.inputSchema.properties).map(([n,r])=>`- ${r.title??n} (${r.type}): ${r.description??""}`).join(`
2
2
  `);return`You are helping describe a web form as an AI tool. Given this form information:
3
3
 
4
4
  Name: ${e.name}
@@ -6,5 +6,5 @@ Current description: ${e.description}
6
6
  Fields:
7
7
  ${t}
8
8
 
9
- Write a concise (1-2 sentence) description of what this tool does and when an AI agent should use it. Be specific and actionable. Respond with only the description, no preamble.`}async function lt(e,t){let n=t.model??"claude-haiku-4-5-20251001",r=await fetch("https://api.anthropic.com/v1/messages",{method:"POST",headers:{"x-api-key":t.apiKey,"anthropic-version":"2023-06-01","content-type":"application/json"},body:JSON.stringify({model:n,max_tokens:150,messages:[{role:"user",content:e}]})});if(!r.ok)throw new Error(`Claude API error: ${r.status}`);return(await r.json()).content.filter(o=>o.type==="text").map(o=>o.text).join("").trim()}async function ct(e,t){let r=`https://generativelanguage.googleapis.com/v1beta/models/${t.model??"gemini-1.5-flash"}:generateContent?key=${t.apiKey}`,i=await fetch(r,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:e}]}],generationConfig:{maxOutputTokens:150,temperature:.2}})});if(!i.ok)throw new Error(`Gemini API error: ${i.status}`);return(await i.json()).candidates[0]?.content.parts.map(s=>s.text).join("").trim()??""}function xe(e,t,n){window.dispatchEvent(new CustomEvent(e,{detail:{form:t,toolName:n}}))}function ut(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 R(e,t){if(ut(e,t))return;let n;for(let[o,s]of Object.entries(t.overrides))try{if(e.matches(o)){n=s;break}}catch{}let r=se(e,n);t.enhance&&(t.debug&&console.debug(`[auto-webmcp] Enriching: ${r.name}\u2026`),r=await Le(r,t.enhance)),t.debug&&ht(r.name,r.description);let i=he(e,t,r.name,r);await _(e,r,i),G.add(e),z++,t.debug&&console.debug(`[auto-webmcp] Registered: ${r.name}`,r),xe("form:registered",e,r.name)}async function mt(e,t){let{getRegisteredToolName:n}=await Promise.resolve().then(()=>(w(),pe)),r=n(e);r&&(await L(e),G.delete(e),t.debug&&console.debug(`[auto-webmcp] Unregistered: ${r}`),xe("form:unregistered",e,r))}var S=null,G=new WeakSet,z=0,V=new Map,dt=300;function ft(e){let t=e.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select")return!0;let n=e.getAttribute("role");if(n&&M.includes(n)||e.querySelector("input, textarea, select"))return!0;for(let r of M)if(e.querySelector(`[role="${r}"]`))return!0;return!1}function pt(e,t){let n=V.get(e);n&&clearTimeout(n),V.set(e,setTimeout(()=>{V.delete(e),R(e,t)},dt))}function gt(e){S||(S=new MutationObserver(t=>{for(let n of t){for(let r of n.addedNodes){if(!(r instanceof Element))continue;if(r instanceof HTMLFormElement){R(r,e);continue}let i=r.closest("form");i instanceof HTMLFormElement&&G.has(i)&&ft(r)&&pt(i,e);for(let o of Array.from(r.querySelectorAll("form")))R(o,e)}for(let r of n.removedNodes){if(!(r instanceof Element))continue;let i=r instanceof HTMLFormElement?[r]:Array.from(r.querySelectorAll("form"));for(let o of i)mt(o,e)}}}),S.observe(document.body,{childList:!0,subtree:!0}))}function bt(e){window.addEventListener("hashchange",()=>v(e));let t={pushState:history.pushState.bind(history),replaceState:history.replaceState.bind(history)};history.pushState=function(...n){t.pushState(...n),v(e)},history.replaceState=function(...n){t.replaceState(...n),v(e)},window.addEventListener("popstate",()=>v(e))}async function v(e){let t=Array.from(document.querySelectorAll("form"));await Promise.allSettled(t.map(n=>R(n,e)))}var Et=new Set(["password","hidden","file","submit","reset","button","image"]);async function Tt(e){if(!T())return;let t='[type="submit"]:not([disabled]), button:not([type]):not([disabled])',n=/subscribe|submit|sign[\s-]?up|send|join|go|search/i,r=Array.from(document.querySelectorAll("input:not(form input), textarea:not(form textarea), select:not(form select)")).filter(o=>{if(o instanceof HTMLInputElement&&Et.has(o.type.toLowerCase()))return!1;let s=o.getBoundingClientRect();return s.width>0&&s.height>0});if(r.length===0)return;let i=new Map;for(let o of r){let s=o.parentElement,l=o.parentElement??document.body;for(;s&&s!==document.body;){if(s.querySelector(t)!==null||Array.from(s.querySelectorAll("button")).some(c=>n.test(c.textContent??""))){l=s;break}s=s.parentElement}i.has(l)||i.set(l,[]),i.get(l).push(o)}for(let[o,s]of i){let l=Array.from(o.querySelectorAll(t)).filter(f=>{let p=f.getBoundingClientRect();return p.width>0&&p.height>0}),a=l[l.length-1]??null;if(!a){let f=Array.from(document.querySelectorAll("button")).filter(p=>{let E=p.getBoundingClientRect();return E.width>0&&E.height>0&&n.test(p.textContent??"")});a=f[f.length-1]??null}let c=de(o,s,a),d=[],u=c.inputSchema.properties;for(let f of s){let p=f.name||f.dataset.webmcpName||f.id||f.getAttribute("aria-label")||null,E=p?p.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64):null;E&&u[E]&&d.push({key:E,el:f})}let m=c.name,g=async f=>{for(let{key:p,el:E}of d)f[p]!==void 0&&Me(E,f[p]);return window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:m}})),{content:[{type:"text",text:"Fields filled. Ready to submit."}]}};try{await navigator.modelContext.registerTool({name:c.name,description:c.description,inputSchema:c.inputSchema,execute:g}),e.debug&&console.debug(`[auto-webmcp] Orphan tool registered: ${c.name}`,c)}catch{}}}function ht(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 He(e){document.readyState==="loading"&&await new Promise(t=>document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})),z=0,gt(e),bt(e),await v(e),z===0&&await Tt(e)}function ve(){S?.disconnect(),S=null}w();async function Se(e){let t=X(e);return t.debug&&console.debug("[auto-webmcp] Initializing",{webmcpSupported:T(),config:t}),await He(t),{destroy:async()=>{ve(),await D()},getTools:q,isSupported:T()}}typeof window<"u"&&!window.__AUTO_WEBMCP_NO_AUTOINIT&&Se();return Fe(yt);})();
9
+ Write a concise (1-2 sentence) description of what this tool does and when an AI agent should use it. Be specific and actionable. Respond with only the description, no preamble.`}async function ct(e,t){let n=t.model??"claude-haiku-4-5-20251001",r=await fetch("https://api.anthropic.com/v1/messages",{method:"POST",headers:{"x-api-key":t.apiKey,"anthropic-version":"2023-06-01","content-type":"application/json"},body:JSON.stringify({model:n,max_tokens:150,messages:[{role:"user",content:e}]})});if(!r.ok)throw new Error(`Claude API error: ${r.status}`);return(await r.json()).content.filter(o=>o.type==="text").map(o=>o.text).join("").trim()}async function ut(e,t){let r=`https://generativelanguage.googleapis.com/v1beta/models/${t.model??"gemini-1.5-flash"}:generateContent?key=${t.apiKey}`,i=await fetch(r,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:e}]}],generationConfig:{maxOutputTokens:150,temperature:.2}})});if(!i.ok)throw new Error(`Gemini API error: ${i.status}`);return(await i.json()).candidates[0]?.content.parts.map(s=>s.text).join("").trim()??""}function He(e,t,n){window.dispatchEvent(new CustomEvent(e,{detail:{form:t,toolName:n}}))}function mt(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 F(e,t){if(mt(e,t))return;let n;for(let[o,s]of Object.entries(t.overrides))try{if(e.matches(o)){n=s;break}}catch{}let r=se(e,n);t.enhance&&(t.debug&&console.debug(`[auto-webmcp] Enriching: ${r.name}\u2026`),r=await xe(r,t.enhance)),t.debug&&yt(r.name,r.description);let i=ye(e,t,r.name,r);await q(e,r,i),G.add(e),z++,t.debug&&console.debug(`[auto-webmcp] Registered: ${r.name}`,r),He("form:registered",e,r.name)}async function dt(e,t){let{getRegisteredToolName:n}=await Promise.resolve().then(()=>(A(),ge)),r=n(e);r&&(await x(e),G.delete(e),t.debug&&console.debug(`[auto-webmcp] Unregistered: ${r}`),He("form:unregistered",e,r))}var v=null,G=new WeakSet,z=0,V=new Map,pt=300;function ft(e){let t=e.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select")return!0;let n=e.getAttribute("role");if(n&&L.includes(n)||e.querySelector("input, textarea, select"))return!0;for(let r of L)if(e.querySelector(`[role="${r}"]`))return!0;return!1}function gt(e,t){let n=V.get(e);n&&clearTimeout(n),V.set(e,setTimeout(()=>{V.delete(e),F(e,t)},pt))}function Et(e){v||(v=new MutationObserver(t=>{for(let n of t){for(let r of n.addedNodes){if(!(r instanceof Element))continue;if(r instanceof HTMLFormElement){F(r,e);continue}let i=r.closest("form");i instanceof HTMLFormElement&&G.has(i)&&ft(r)&&gt(i,e);for(let o of Array.from(r.querySelectorAll("form")))F(o,e)}for(let r of n.removedNodes){if(!(r instanceof Element))continue;let i=r instanceof HTMLFormElement?[r]:Array.from(r.querySelectorAll("form"));for(let o of i)dt(o,e)}}}),v.observe(document.body,{childList:!0,subtree:!0}))}function bt(e){window.addEventListener("hashchange",()=>w(e));let t={pushState:history.pushState.bind(history),replaceState:history.replaceState.bind(history)};history.pushState=function(...n){t.pushState(...n),w(e)},history.replaceState=function(...n){t.replaceState(...n),w(e)},window.addEventListener("popstate",()=>w(e))}async function w(e){let t=Array.from(document.querySelectorAll("form"));await Promise.allSettled(t.map(n=>F(n,e)))}var ht=new Set(["password","hidden","file","submit","reset","button","image"]);async function Tt(e){if(!h())return;let t='[type="submit"]:not([disabled]), button:not([type]):not([disabled])',n=/subscribe|submit|sign[\s-]?up|send|join|go|search/i,r=Array.from(document.querySelectorAll("input:not(form input), textarea:not(form textarea), select:not(form select)")).filter(o=>{if(o instanceof HTMLInputElement&&ht.has(o.type.toLowerCase()))return!1;let s=o.getBoundingClientRect();return s.width>0&&s.height>0});if(r.length===0)return;let i=new Map;for(let o of r){let s=o.parentElement,c=o.parentElement??document.body;for(;s&&s!==document.body;){if(s.querySelector(t)!==null||Array.from(s.querySelectorAll("button")).some(l=>n.test(l.textContent??""))){c=s;break}s=s.parentElement}i.has(c)||i.set(c,[]),i.get(c).push(o)}for(let[o,s]of i){let c=Array.from(o.querySelectorAll(t)).filter(u=>{let g=u.getBoundingClientRect();return g.width>0&&g.height>0}),a=c[c.length-1]??null;if(!a){let u=Array.from(document.querySelectorAll("button")).filter(g=>{let b=g.getBoundingClientRect();return b.width>0&&b.height>0&&n.test(g.textContent??"")});a=u[u.length-1]??null}let l=pe(o,s,a),p=[],m=l.inputSchema.properties;for(let u of s){let g=u.name||u.dataset.webmcpName||u.id||u.getAttribute("aria-label")||null,b=g?g.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64):null;b&&m[b]&&p.push({key:b,el:u})}let d=l.name,f=async u=>{for(let{key:g,el:b}of p)u[g]!==void 0&&Le(b,u[g]);return window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:d}})),{content:[{type:"text",text:"Fields filled. Ready to submit."}]}};try{await navigator.modelContext.registerTool({name:l.name,description:l.description,inputSchema:l.inputSchema,execute:f}),e.debug&&console.debug(`[auto-webmcp] Orphan tool registered: ${l.name}`,l)}catch{}}}function yt(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 Se(e){document.readyState==="loading"&&await new Promise(t=>document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})),z=0,Et(e),bt(e),await w(e),z===0&&await Tt(e)}function we(){v?.disconnect(),v=null}A();async function ve(e){let t=X(e);return t.debug&&console.debug("[auto-webmcp] Initializing",{webmcpSupported:h(),config:t}),await Se(t),{destroy:async()=>{we(),await B()},getTools:D,isSupported:h()}}typeof window<"u"&&!window.__AUTO_WEBMCP_NO_AUTOINIT&&ve();return Pe(Mt);})();
10
10
  //# sourceMappingURL=auto-webmcp.iife.js.map