auto-webmcp 0.2.7 → 0.2.9

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 R=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var J=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},Le=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of he(t))!ye.call(e,o)&&o!==n&&R(e,o,{get:()=>t[o],enumerable:!(r=Te(t,o))||r.enumerable});return e};var xe=e=>Le(R({},"__esModule",{value:!0}),e);var oe={};J(oe,{getAllRegisteredTools:()=>$,getRegisteredToolName:()=>Be,isWebMCPSupported:()=>E,registerFormTool:()=>O,unregisterAll:()=>_,unregisterFormTool:()=>M});function E(){return typeof navigator<"u"&&typeof navigator.modelContext<"u"}async function O(e,t,n){if(!E())return;T.get(e)&&await M(e);try{await navigator.modelContext.registerTool({name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n})}catch{try{await navigator.modelContext.unregisterTool(t.name),await navigator.modelContext.registerTool({name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n})}catch{}}T.set(e,t.name)}async function M(e){if(!E())return;let t=T.get(e);if(t){try{await navigator.modelContext.unregisterTool(t)}catch{}T.delete(e)}}function Be(e){return T.get(e)}function $(){return Array.from(T.entries()).map(([e,t])=>({form:e,name:t}))}async function _(){let e=Array.from(T.entries());await Promise.all(e.map(([t])=>M(t)))}var T,H=Me(()=>{"use strict";T=new Map});var st={};J(st,{autoWebMCP:()=>be});function z(e){return{exclude:e?.exclude??[],autoSubmit:e?.autoSubmit??!1,enhance:e?.enhance??null,overrides:e?.overrides??{},debug:e?.debug??!1}}var y=["textbox","combobox","checkbox","radio","switch","spinbutton","searchbox","slider"];function k(e){return e instanceof HTMLInputElement?Se(e):e instanceof HTMLTextAreaElement?{type:"string"}:e instanceof HTMLSelectElement?ve(e):null}function Se(e){switch(e.type.toLowerCase()){case"text":case"search":case"tel":return F(e);case"email":return{...F(e),format:"email"};case"url":return{...F(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 F(e){let t={type:"string"};return e.minLength>0&&(t.minLength=e.minLength),e.maxLength>0&&e.maxLength!==524288&&(t.maxLength=e.maxLength),e.pattern&&(t.pattern=e.pattern),t}function ve(e){let t=Array.from(e.options).filter(o=>o.value!==""&&!o.disabled);if(t.length===0)return{type:"string"};let n=t.map(o=>o.value),r=t.map(o=>({const:o.value,title:o.text.trim()||o.value}));return{type:"string",enum:n,oneOf:r}}function U(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).map(r=>r.value).filter(r=>r!=="")}function G(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).filter(r=>r.value!=="").map(r=>{let o=He(r);return{const:r.value,title:o||r.value}})}function K(e,t){switch(t){case"checkbox":case"switch":return{type:"boolean"};case"spinbutton":case"slider":{let n={type:"number"},r=e.getAttribute("aria-valuemin"),o=e.getAttribute("aria-valuemax");return r!==null&&(n.minimum=parseFloat(r)),o!==null&&(n.maximum=parseFloat(o)),n}case"combobox":{let n=e.getAttribute("aria-owns")??e.getAttribute("aria-controls");if(n){let r=document.getElementById(n);if(r){let o=Array.from(r.querySelectorAll('[role="option"]')).filter(i=>i.getAttribute("aria-disabled")!=="true");if(o.length>0){let i=o.map(a=>(a.getAttribute("data-value")??a.textContent??"").trim()).filter(Boolean),s=o.map(a=>({const:(a.getAttribute("data-value")??a.textContent??"").trim(),title:(a.textContent??"").trim()}));return{type:"string",enum:i,oneOf:s}}}}return{type:"string"}}case"textbox":case"searchbox":case"radio":default:return{type:"string"}}}function He(e){let t=e.closest("label");if(t){let n=t.cloneNode(!0);n.querySelectorAll("input, select, textarea, button").forEach(o=>o.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 Y=0;function X(e,t){let n=t?.name??we(e),r=t?.description??Ie(e),{schema:o,fieldElements:i}=Re(e);return{name:n,description:r,inputSchema:o,fieldElements:i}}function we(e){let t=e.getAttribute("toolname");if(t)return m(t);let n=e.dataset.webmcpName;if(n)return m(n);let r=Ae(e);if(r)return m(r);let o=Q(e);if(o)return m(o);if(e.id)return m(e.id);if(e.name)return m(e.name);if(e.action){let i=Ce(e.action);if(i)return m(i)}return`form_${++Y}`}function m(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)||"form"}function Ae(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 Q(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 Ce(e){try{let n=new URL(e,window.location.href).pathname.split("/").filter(Boolean);return n[n.length-1]??""}catch{return""}}function Ie(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 o=e.getAttribute("aria-label");if(o?.trim())return o.trim();let i=e.getAttribute("aria-describedby");if(i){let l=document.getElementById(i);if(l?.textContent?.trim())return l.textContent.trim()}let s=Q(e),a=document.title?.trim();return s&&a?`${s} \u2014 ${a}`:s||a||"Submit form"}function Re(e){let t={},n=[],r=new Map,o=new Set,i=Array.from(e.querySelectorAll("input, textarea, select"));for(let l of i){let c=l.name,u=c||Z(l);if(!u)continue;if(l instanceof HTMLInputElement&&l.type==="radio"){if(o.has(u))continue;o.add(u)}let p=k(l);if(!p)continue;p.title=ee(l);let b=te(l);if(b&&(p.description=b),l instanceof HTMLInputElement&&l.type==="radio"){p.enum=U(e,u);let v=G(e,u);v.length>0&&(p.oneOf=v)}t[u]=p,c||r.set(u,l),l.required&&n.push(u)}let s=Fe(e),a=new Set;for(let{el:l,role:c,key:u}of s){if(t[u])continue;if(c==="radio"){if(a.has(u))continue;a.add(u)}let p=K(l,c);p.title=Pe(l);let b=Oe(l);b&&(p.description=b),t[u]=p,r.set(u,l),l.getAttribute("aria-required")==="true"&&n.push(u)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}function Z(e){let t=e;if(t.dataset.webmcpName)return m(t.dataset.webmcpName);if(e.id)return m(e.id);let n=e.getAttribute("aria-label");return n?m(n):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?m(e.placeholder.trim()):e instanceof HTMLInputElement&&e.type!=="text"?e.type:null}function Fe(e){let t=y.map(r=>`[role="${r}"]`).join(", "),n=[];for(let r of Array.from(e.querySelectorAll(t))){if(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement||r.getAttribute("aria-hidden")==="true"||r.hidden)continue;let o=r.getAttribute("role"),i=ke(r);i&&n.push({el:r,role:o,key:i})}return n}function ke(e){let t=e;if(t.dataset?.webmcpName)return m(t.dataset.webmcpName);if(e.id)return m(e.id);let n=e.getAttribute("aria-label");if(n)return m(n);let r=e.getAttribute("aria-labelledby");if(r){let o=document.getElementById(r)?.textContent?.trim();if(o)return m(o)}return null}function Pe(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 o=document.getElementById(r)?.textContent?.trim();if(o)return o}return e.id?P(e.id):""}function Oe(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 o=e.getAttribute("aria-describedby");if(o){let s=document.getElementById(o)?.textContent?.trim();if(s)return s}let i=e.getAttribute("placeholder")??e.dataset?.placeholder;return i?i.trim():""}function ee(e){if("dataset"in e&&e.dataset.webmcpTitle)return e.dataset.webmcpTitle;let t=$e(e);return t||(e.name?P(e.name):e.id?P(e.id):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?e.placeholder.trim():"")}function te(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 o=e.getAttribute("aria-describedby");if(o){let i=document.getElementById(o);if(i?.textContent?.trim())return i.textContent.trim()}if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement){let i=e.placeholder?.trim();if(i&&i.length>0)return i}return""}function $e(e){if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let r=V(n);if(r)return r}}let t=e.closest("label");if(t){let n=V(t);if(n)return n}return""}function V(e){let t=e.cloneNode(!0);return t.querySelectorAll("input, select, textarea, button").forEach(n=>n.remove()),t.textContent?.trim()??""}function P(e){return e.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim().replace(/\b\w/g,t=>t.toUpperCase())}function ne(e,t,n){let r=_e(e,n),o=Ne(e),{schema:i,fieldElements:s}=qe(t);return{name:r,description:o,inputSchema:i,fieldElements:s}}function _e(e,t){if(t){let o=t instanceof HTMLInputElement?t.value.trim():t.textContent?.trim()??"";if(o&&o.length>0&&o.length<80)return m(o)}let n=re(e);if(n)return m(n);let r=document.title?.trim();return r?m(r):`form_${++Y}`}function Ne(e){let t=re(e),n=document.title?.trim();return t&&n&&t!==n?`${t} on ${n}`:t||n||"Submit form"}function re(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 o=r.textContent?.trim()??"";if(o)return o}r=r.previousElementSibling}if(n=n.parentElement,!n||n===document.body)break}return""}function qe(e){let t={},n=[],r=new Map,o=new Set;for(let i of e){let s=i.name,a=s||Z(i);if(!a)continue;if(i instanceof HTMLInputElement&&i.type==="radio"){if(o.has(a))continue;o.add(a)}let l=k(i);if(!l)continue;l.title=ee(i);let c=te(i);c&&(l.description=c),t[a]=l,s||r.set(a,i),i.required&&n.push(a)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}H();var w=new WeakMap,le=new WeakMap,A=new WeakMap,q=new WeakMap,De=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set,je=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set,h=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked")?.set;function ce(e,t,n,r){return r?.fieldElements&&A.set(e,r.fieldElements),ie(e,n),async o=>(N(e,o),window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:n}})),new Promise((i,s)=>{w.set(e,{resolve:i,reject:s}),(t.autoSubmit||e.hasAttribute("toolautosubmit")||e.dataset.webmcpAutosubmit!==void 0)&&ae(e).then(async()=>{try{N(e,o);for(let c=0;c<2&&Je(e,o,A.get(e)).length!==0;c++)N(e,o),await ae(e,400,100);let a=e;if(!e.isConnected){let u=document.querySelector('button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])')?.closest("form");u&&(a=u,w.set(a,{resolve:i,reject:s}),ie(a,n))}let l=ze(r,o);l.length>0&&q.set(a,l),a.requestSubmit()}catch(a){s(a instanceof Error?a:new Error(String(a)))}})}))}function ie(e,t){e.__awmcp_intercepted||(e.__awmcp_intercepted=!0,e.addEventListener("submit",n=>{let r=w.get(e);if(!r)return;let{resolve:o}=r;w.delete(e);let i=We(e,le.get(e),A.get(e)),s=q.get(e);q.delete(e);let a=s?.length?` Note: required fields were not filled: ${s.join(", ")}.`:"",c={content:[{type:"text",text:`Form submitted. Fields: ${JSON.stringify(i)}${a}`}]};n.agentInvoked&&typeof n.respondWith=="function"&&(n.preventDefault(),n.respondWith(Promise.resolve(c))),o(c)}),e.addEventListener("reset",()=>{window.dispatchEvent(new CustomEvent("toolcancel",{detail:{toolName:t}}))}))}function L(e,t){if(e.focus(),e.select?.(),document.execCommand("insertText",!1,t)&&e.value===t)return;let n=e instanceof HTMLTextAreaElement?je:De;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 ue(e,t){h?h.call(e,t):e.checked=t,e.dispatchEvent(new Event("change",{bubbles:!0}))}function C(e,t){for(let n of Array.from(e.querySelectorAll("*"))){let r=n.shadowRoot;if(!r)continue;let o=r.querySelector(t);if(o)return o;let i=C(r,t);if(i)return i}return null}function B(e,t){let n=CSS.escape(t),r=e.querySelector(`[name="${n}"]`)??e.querySelector(`input#${n}, textarea#${n}, select#${n}`);return r||(C(document,`[name="${n}"]`)??C(document,`input#${n}, textarea#${n}, select#${n}`))}function N(e,t){le.set(e,t);let n=A.get(e);for(let[r,o]of Object.entries(t)){let i=B(e,r);if(i){i instanceof HTMLInputElement?se(i,e,r,o):i instanceof HTMLTextAreaElement?L(i,String(o??"")):i instanceof HTMLSelectElement&&(i.value=String(o??""),i.dispatchEvent(new Event("change",{bubbles:!0})));continue}let s=n?.get(r);if(s){let a=s;if(!s.isConnected){let l=s.id;if(l){let c=document.getElementById(l)??C(document,`#${CSS.escape(l)}`);c&&(a=c)}}a instanceof HTMLInputElement?se(a,e,r,o):a instanceof HTMLTextAreaElement?L(a,String(o??"")):a instanceof HTMLSelectElement?(a.value=String(o??""),a.dispatchEvent(new Event("change",{bubbles:!0}))):me(a,o)}}}function se(e,t,n,r){let o=e.type.toLowerCase();if(o==="checkbox"){ue(e,!!r);return}if(o==="radio"){let i=CSS.escape(n),s=t.querySelectorAll(`input[type="radio"][name="${i}"]`);for(let a of s)if(a.value===String(r)){h?h.call(a,!0):a.checked=!0,a.dispatchEvent(new Event("change",{bubbles:!0}));break}return}L(e,String(r??""))}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}let r=e;r.isContentEditable&&(r.textContent=String(t??"")),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function We(e,t,n){let r={},o=new FormData(e);for(let[i,s]of o.entries())if(r[i]!==void 0){let a=r[i];Array.isArray(a)?a.push(s):r[i]=[a,s]}else r[i]=s;if(t)for(let i of Object.keys(t)){if(i in r)continue;let s=B(e,i)??n?.get(i)??null;if(s)if(s instanceof HTMLInputElement&&s.type==="checkbox")r[i]=s.checked;else if(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)r[i]=s.value;else{let a=s.getAttribute("role");a==="checkbox"||a==="switch"?r[i]=s.getAttribute("aria-checked")==="true":r[i]=s.textContent?.trim()??""}}return r}function de(e,t){if(e instanceof HTMLInputElement){let n=e.type.toLowerCase();n==="checkbox"?ue(e,!!t):n==="radio"?e.value===String(t)&&(h?h.call(e,!0):e.checked=!0,e.dispatchEvent(new Event("change",{bubbles:!0}))):L(e,String(t??""))}else e instanceof HTMLTextAreaElement?L(e,String(t??"")):e instanceof HTMLSelectElement?(e.value=String(t??""),e.dispatchEvent(new Event("change",{bubbles:!0}))):me(e,t)}function ae(e,t=800,n=150){return new Promise(r=>{let o=!1,i=null,s=()=>{o||(o=!0,a.disconnect(),i!==null&&clearTimeout(i),r())},a=new MutationObserver(()=>{i!==null&&clearTimeout(i),i=setTimeout(s,n)});a.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),setTimeout(s,t),i=setTimeout(s,n)})}function Je(e,t,n){let r=[];for(let[o,i]of Object.entries(t)){let s=B(e,o)??n?.get(o)??null;s&&(s instanceof HTMLInputElement&&s.type==="checkbox"?s.checked!==!!i&&r.push(o):(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)&&s.value!==String(i??"")&&r.push(o))}return r}function ze(e,t){return e?.inputSchema?.required?.length?e.inputSchema.required.filter(n=>!(n in t)):[]}async function pe(e,t){try{let n=await Ue(e,t);return{...e,description:n}}catch(n){return console.warn("[auto-webmcp] Enrichment failed, using heuristic description:",n),e}}async function Ue(e,t){let n=Ge(e);return t.provider==="claude"?Ke(n,t):Ve(n,t)}function Ge(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 R=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var ve=(e,t)=>()=>(e&&(t=e(e=0)),t);var G=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},He=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xe(t))!Se.call(e,o)&&o!==n&&R(e,o,{get:()=>t[o],enumerable:!(r=Le(t,o))||r.enumerable});return e};var we=e=>He(R({},"__esModule",{value:!0}),e);var ce={};G(ce,{getAllRegisteredTools:()=>N,getRegisteredToolName:()=>je,isWebMCPSupported:()=>h,registerFormTool:()=>$,unregisterAll:()=>_,unregisterFormTool:()=>L});function h(){return typeof navigator<"u"&&typeof navigator.modelContext<"u"}async function $(e,t,n){if(!h())return;T.get(e)&&await L(e);try{await navigator.modelContext.registerTool({name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n})}catch{try{await navigator.modelContext.unregisterTool(t.name),await navigator.modelContext.registerTool({name:t.name,description:t.description,inputSchema:t.inputSchema,execute:n})}catch{}}T.set(e,t.name)}async function L(e){if(!h())return;let t=T.get(e);if(t){try{await navigator.modelContext.unregisterTool(t)}catch{}T.delete(e)}}function je(e){return T.get(e)}function N(){return Array.from(T.entries()).map(([e,t])=>({form:e,name:t}))}async function _(){let e=Array.from(T.entries());await Promise.all(e.map(([t])=>L(t)))}var T,w=ve(()=>{"use strict";T=new Map});var ct={};G(ct,{autoWebMCP:()=>Me});function V(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 P(e){return e instanceof HTMLInputElement?Ae(e):e instanceof HTMLTextAreaElement?{type:"string"}:e instanceof HTMLSelectElement?Ce(e):null}function Ae(e){switch(e.type.toLowerCase()){case"text":case"search":case"tel":return k(e);case"email":return{...k(e),format:"email"};case"url":return{...k(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 k(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 o=Array.from(r.options).filter(i=>!i.disabled&&i.value.trim()!=="");o.length>0&&(t.enum=o.map(i=>i.value.trim()),t.oneOf=o.map(i=>({const:i.value.trim(),title:i.textContent?.trim()||i.value.trim()})))}}return t}function Ce(e){let t=[],n=[];for(let r of Array.from(e.children))if(r instanceof HTMLOptGroupElement){if(r.disabled)continue;let o=r.label?.trim()??"";for(let i of Array.from(r.children)){if(!(i instanceof HTMLOptionElement)||i.disabled||i.value==="")continue;t.push(i.value);let s={const:i.value,title:i.text.trim()||i.value};o&&(s.group=o),n.push(s)}}else if(r instanceof HTMLOptionElement){if(r.disabled||r.value==="")continue;t.push(r.value),n.push({const:r.value,title:r.text.trim()||r.value})}return t.length===0?{type:"string"}:{type:"string",enum:t,oneOf:n}}function U(e,t){return Array.from(e.querySelectorAll(`input[type="checkbox"][name="${CSS.escape(t)}"]`)).map(n=>n.value).filter(n=>n!==""&&n!=="on")}function K(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).map(r=>r.value).filter(r=>r!=="")}function Y(e,t){return Array.from(e.querySelectorAll(`input[type="radio"][name="${CSS.escape(t)}"]`)).filter(r=>r.value!=="").map(r=>{let o=Ie(r);return{const:r.value,title:o||r.value}})}function X(e,t){switch(t){case"checkbox":case"switch":return{type:"boolean"};case"spinbutton":case"slider":{let n={type:"number"},r=e.getAttribute("aria-valuemin"),o=e.getAttribute("aria-valuemax");return r!==null&&(n.minimum=parseFloat(r)),o!==null&&(n.maximum=parseFloat(o)),n}case"combobox":{let n=e.getAttribute("aria-owns")??e.getAttribute("aria-controls");if(n){let r=document.getElementById(n);if(r){let o=Array.from(r.querySelectorAll('[role="option"]')).filter(i=>i.getAttribute("aria-disabled")!=="true");if(o.length>0){let i=o.map(a=>(a.getAttribute("data-value")??a.textContent??"").trim()).filter(Boolean),s=o.map(a=>({const:(a.getAttribute("data-value")??a.textContent??"").trim(),title:(a.textContent??"").trim()}));return{type:"string",enum:i,oneOf:s}}}}return{type:"string"}}case"textbox":case"searchbox":case"radio":default:return{type:"string"}}}function Ie(e){let t=e.closest("label");if(t){let n=t.cloneNode(!0);n.querySelectorAll("input, select, textarea, button").forEach(o=>o.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 ee=0;function te(e,t){let n=t?.name??Fe(e),r=t?.description??Pe(e),{schema:o,fieldElements:i}=Oe(e);return{name:n,description:r,inputSchema:o,fieldElements:i}}function Fe(e){let t=e.getAttribute("toolname");if(t)return E(t);let n=e.dataset.webmcpName;if(n)return E(n);let r=Re(e);if(r)return E(r);let o=ne(e);if(o)return E(o);if(e.id)return E(e.id);if(e.name)return E(e.name);if(e.action){let i=ke(e.action);if(i)return E(i)}return`form_${++ee}`}function E(e){return e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64)||"form"}function Re(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 ne(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 ke(e){try{let n=new URL(e,window.location.href).pathname.split("/").filter(Boolean);return n[n.length-1]??""}catch{return""}}function Pe(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 o=e.getAttribute("aria-label");if(o?.trim())return o.trim();let i=e.getAttribute("aria-describedby");if(i){let c=document.getElementById(i);if(c?.textContent?.trim())return c.textContent.trim()}let s=ne(e),a=document.title?.trim();return s&&a?`${s} \u2014 ${a}`:s||a||"Submit form"}function Oe(e){let t={},n=[],r=new Map,o=new Set,i=new Set,s=Array.from(e.querySelectorAll("input, textarea, select"));for(let l of s){let f=l.name,u=f||re(l);if(!u)continue;if(l instanceof HTMLInputElement&&l.type==="radio"){if(o.has(u))continue;o.add(u)}if(l instanceof HTMLInputElement&&l.type==="checkbox"){if(i.has(u))continue;i.add(u)}let m=P(l);if(!m||!se(l))continue;m.title=ie(l);let p=oe(l);if(p&&(m.description=p),l instanceof HTMLInputElement&&l.type==="radio"){m.enum=K(e,u);let d=Y(e,u);d.length>0&&(m.oneOf=d)}if(l instanceof HTMLInputElement&&l.type==="checkbox"){let d=U(e,u);if(d.length>1){let g={type:"array",items:{type:"string",enum:d},title:m.title};m.description&&(g.description=m.description),t[u]=g,l.required&&n.push(u);continue}}t[u]=m,f||r.set(u,l),l.required&&n.push(u)}let a=$e(e),c=new Set;for(let{el:l,role:f,key:u,enumValues:m,enumOneOf:p}of a){if(t[u])continue;if(f==="radio"){if(c.has(u))continue;c.add(u)}let d=X(l,f);m&&m.length>0&&(d.enum=m,p&&p.length>0&&(d.oneOf=p)),d.title=Ne(l);let g=_e(l);g&&(d.description=g),t[u]=d,r.set(u,l),l.getAttribute("aria-required")==="true"&&n.push(u)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}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");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 $e(e){let t=M.map(c=>`[role="${c}"]`).join(", "),n=[];for(let c of Array.from(e.querySelectorAll(t))){if(c instanceof HTMLInputElement||c instanceof HTMLTextAreaElement||c instanceof HTMLSelectElement||c.getAttribute("aria-hidden")==="true"||c.hidden)continue;let l=c.getAttribute("role"),f=Q(c);f&&n.push({el:c,role:l,key:f})}let r=n.filter(c=>c.role==="radio"),o=n.filter(c=>c.role!=="radio"),i=new Map,s=[];for(let c of r){let l=c.el.closest('[role="radiogroup"]');l?(i.has(l)||i.set(l,[]),i.get(l).push(c.el)):s.push(c)}let a=[];for(let[c,l]of i){let f=Q(c);if(!f)continue;let u=l.map(p=>(p.getAttribute("data-value")??p.getAttribute("aria-label")??p.textContent??"").trim()).filter(Boolean),m=l.map(p=>{let d=(p.getAttribute("data-value")??p.getAttribute("aria-label")??p.textContent??"").trim(),g=(p.getAttribute("aria-label")??p.textContent??"").trim();return{const:d,title:g||d}}).filter(p=>p.const!=="");u.length>0&&a.push({el:c,role:"radio",key:f,enumValues:u,enumOneOf:m})}return[...o,...a,...s]}function Q(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 o=document.getElementById(r)?.textContent?.trim();if(o)return E(o)}return null}function Ne(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 o=document.getElementById(r)?.textContent?.trim();if(o)return o}return e.id?O(e.id):""}function _e(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 o=e.getAttribute("aria-describedby");if(o){let s=document.getElementById(o)?.textContent?.trim();if(s)return s}let i=e.getAttribute("placeholder")??e.dataset?.placeholder;return i?i.trim():""}function ie(e){if("dataset"in e&&e.dataset.webmcpTitle)return e.dataset.webmcpTitle;let t=qe(e);return t||(e.name?O(e.name):e.id?O(e.id):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.placeholder?.trim()?e.placeholder.trim():"")}function oe(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 o=e.getAttribute("aria-describedby");if(o){let i=document.getElementById(o);if(i?.textContent?.trim())return i.textContent.trim()}if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement){let i=e.placeholder?.trim();if(i&&i.length>0)return i}return""}function qe(e){if(e.id){let n=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(n){let r=Z(n);if(r)return r}}let t=e.closest("label");if(t){let n=Z(t);if(n)return n}return""}function Z(e){let t=e.cloneNode(!0);return t.querySelectorAll("input, select, textarea, button").forEach(n=>n.remove()),t.textContent?.trim()??""}function O(e){return e.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim().replace(/\b\w/g,t=>t.toUpperCase())}function se(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 ae(e,t,n){let r=Be(e,n),o=De(e),{schema:i,fieldElements:s}=We(t);return{name:r,description:o,inputSchema:i,fieldElements:s}}function Be(e,t){if(t){let o=t instanceof HTMLInputElement?t.value.trim():t.textContent?.trim()??"";if(o&&o.length>0&&o.length<80)return E(o)}let n=le(e);if(n)return E(n);let r=document.title?.trim();return r?E(r):`form_${++ee}`}function De(e){let t=le(e),n=document.title?.trim();return t&&n&&t!==n?`${t} on ${n}`:t||n||"Submit form"}function le(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 o=r.textContent?.trim()??"";if(o)return o}r=r.previousElementSibling}if(n=n.parentElement,!n||n===document.body)break}return""}function We(e){let t={},n=[],r=new Map,o=new Set,i=new Set;for(let s of e){let a=s.name,c=a||re(s);if(!c)continue;if(s instanceof HTMLInputElement&&s.type==="radio"){if(o.has(c))continue;o.add(c)}if(s instanceof HTMLInputElement&&s.type==="checkbox"){if(i.has(c))continue;i.add(c)}let l=P(s);if(!l||!se(s))continue;l.title=ie(s);let f=oe(s);if(f&&(l.description=f),s instanceof HTMLInputElement&&s.type==="checkbox"){let u=e.filter(m=>m instanceof HTMLInputElement&&m.type==="checkbox"&&m.name===c).map(m=>m.value).filter(m=>m!==""&&m!=="on");if(u.length>1){let m={type:"array",items:{type:"string",enum:u},title:l.title};l.description&&(m.description=l.description),t[c]=m,s.required&&n.push(c);continue}}t[c]=l,a||r.set(c,s),s.required&&n.push(c)}return{schema:{type:"object",properties:t,required:n},fieldElements:r}}w();var A=new WeakMap,fe=new WeakMap,C=new WeakMap,B=new WeakMap,x=new WeakMap,Je=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set,ze=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set,y=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked")?.set;function pe(e,t,n,r){return r?.fieldElements&&C.set(e,r.fieldElements),ue(e,n),async o=>(x.set(e,[]),q(e,o),window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:n}})),new Promise((i,s)=>{A.set(e,{resolve:i,reject:s}),(t.autoSubmit||e.hasAttribute("toolautosubmit")||e.dataset.webmcpAutosubmit!==void 0)&&de(e).then(async()=>{try{q(e,o);for(let l=0;l<2&&Ve(e,o,C.get(e)).length!==0;l++)q(e,o),await de(e,400,100);let a=e;if(!e.isConnected){let f=document.querySelector('button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])')?.closest("form");f&&(a=f,A.set(a,{resolve:i,reject:s}),ue(a,n))}let c=Ue(r,o);c.length>0&&B.set(a,c),a.requestSubmit()}catch(a){s(a instanceof Error?a:new Error(String(a)))}})}))}function ue(e,t){e.__awmcp_intercepted||(e.__awmcp_intercepted=!0,e.addEventListener("submit",n=>{let r=A.get(e);if(!r)return;let{resolve:o}=r;A.delete(e);let i=Ge(e,fe.get(e),C.get(e)),s=B.get(e);B.delete(e);let a=x.get(e)??[];x.delete(e);let c=[...s?.length?[`required fields were not filled: ${s.join(", ")}`]:[],...a],l=c.length?` Note: ${c.join("; ")}.`:"",u={content:[{type:"text",text:`Form submitted. Fields: ${JSON.stringify(i)}${l}`}]};n.agentInvoked&&typeof n.respondWith=="function"&&(n.preventDefault(),n.respondWith(Promise.resolve(u))),o(u)}),e.addEventListener("reset",()=>{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?ze:Je;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 D(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 o=r.querySelector(t);if(o)return o;let i=I(r,t);if(i)return i}return null}function W(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 q(e,t){fe.set(e,t);let n=C.get(e);for(let[r,o]of Object.entries(t)){let i=W(e,r);if(i){i instanceof HTMLInputElement?me(i,e,r,o):i instanceof HTMLTextAreaElement?S(i,String(o??"")):i instanceof HTMLSelectElement&&(i.value=String(o??""),i.dispatchEvent(new Event("change",{bubbles:!0})));continue}let s=n?.get(r);if(s){let a=s;if(!s.isConnected){let c=s.id;if(c){let l=document.getElementById(c)??I(document,`#${CSS.escape(c)}`);l&&(a=l)}}a instanceof HTMLInputElement?me(a,e,r,o):a instanceof HTMLTextAreaElement?S(a,String(o??"")):a instanceof HTMLSelectElement?(a.value=String(o??""),a.dispatchEvent(new Event("change",{bubbles:!0}))):ge(a,o)}}}function me(e,t,n,r){let o=e.type.toLowerCase();if(o==="checkbox"){if(Array.isArray(r)){let i=CSS.escape(n),s=t.querySelectorAll(`input[type="checkbox"][name="${i}"]`);for(let a of s)D(a,r.map(String).includes(a.value));return}D(e,!!r);return}if(o==="number"||o==="range"){let i=String(r??""),s=Number(i);if(i===""||isNaN(s)){x.get(t)?.push(`"${n}" expects a number, got: ${JSON.stringify(r)}`);return}let a=e.min!==""?parseFloat(e.min):-1/0,c=e.max!==""?parseFloat(e.max):1/0;s<a||s>c?(x.get(t)?.push(`"${n}" value ${s} is outside allowed range [${e.min||"?"}, ${e.max||"?"}]`),e.value=String(Math.min(Math.max(s,a),c))):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(o==="radio"){let i=CSS.escape(n),s=t.querySelectorAll(`input[type="radio"][name="${i}"]`);for(let a of s)if(a.value===String(r)){y?y.call(a,!0):a.checked=!0,a.dispatchEvent(new Event("change",{bubbles:!0}));break}return}S(e,String(r??""))}function ge(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 o=Array.from(e.querySelectorAll('[role="radio"]'));for(let i of o)if((i.getAttribute("data-value")??i.getAttribute("aria-label")??i.textContent??"").trim()===String(t)){i.setAttribute("aria-checked","true"),i.dispatchEvent(new MouseEvent("click",{bubbles:!0}));for(let a of o)a!==i&&a.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 Ge(e,t,n){let r={},o=new FormData(e);for(let[i,s]of o.entries())if(r[i]!==void 0){let a=r[i];Array.isArray(a)?a.push(s):r[i]=[a,s]}else r[i]=s;if(t)for(let i of Object.keys(t)){if(i in r)continue;let s=W(e,i)??n?.get(i)??null;if(s)if(s instanceof HTMLInputElement&&s.type==="checkbox")r[i]=s.checked;else if(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)r[i]=s.value;else{let a=s.getAttribute("role");a==="checkbox"||a==="switch"?r[i]=s.getAttribute("aria-checked")==="true":r[i]=s.textContent?.trim()??""}}return r}function Ee(e,t){if(e instanceof HTMLInputElement){let n=e.type.toLowerCase();n==="checkbox"?D(e,!!t):n==="radio"?e.value===String(t)&&(y?y.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?(e.value=String(t??""),e.dispatchEvent(new Event("change",{bubbles:!0}))):ge(e,t)}function de(e,t=800,n=150){return new Promise(r=>{let o=!1,i=null,s=()=>{o||(o=!0,a.disconnect(),i!==null&&clearTimeout(i),r())},a=new MutationObserver(()=>{i!==null&&clearTimeout(i),i=setTimeout(s,n)});a.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),setTimeout(s,t),i=setTimeout(s,n)})}function Ve(e,t,n){let r=[];for(let[o,i]of Object.entries(t)){let s=W(e,o)??n?.get(o)??null;s&&(s instanceof HTMLInputElement&&s.type==="checkbox"?s.checked!==!!i&&r.push(o):(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)&&s.value!==String(i??"")&&r.push(o))}return r}function Ue(e,t){return e?.inputSchema?.required?.length?e.inputSchema.required.filter(n=>!(n in t)):[]}async function be(e,t){try{let n=await Ke(e,t);return{...e,description:n}}catch(n){return console.warn("[auto-webmcp] Enrichment failed, using heuristic description:",n),e}}async function Ke(e,t){let n=Ye(e);return t.provider==="claude"?Xe(n,t):Qe(n,t)}function Ye(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 Ke(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(i=>i.type==="text").map(i=>i.text).join("").trim()}async function Ve(e,t){let r=`https://generativelanguage.googleapis.com/v1beta/models/${t.model??"gemini-1.5-flash"}:generateContent?key=${t.apiKey}`,o=await fetch(r,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:e}]}],generationConfig:{maxOutputTokens:150,temperature:.2}})});if(!o.ok)throw new Error(`Gemini API error: ${o.status}`);return(await o.json()).candidates[0]?.content.parts.map(s=>s.text).join("").trim()??""}function fe(e,t,n){window.dispatchEvent(new CustomEvent(e,{detail:{form:t,toolName:n}}))}function Ye(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 I(e,t){if(Ye(e,t))return;let n;for(let[i,s]of Object.entries(t.overrides))try{if(e.matches(i)){n=s;break}}catch{}let r=X(e,n);t.enhance&&(t.debug&&console.debug(`[auto-webmcp] Enriching: ${r.name}\u2026`),r=await pe(r,t.enhance)),t.debug&&it(r.name,r.description);let o=ce(e,t,r.name,r);await O(e,r,o),W.add(e),j++,t.debug&&console.debug(`[auto-webmcp] Registered: ${r.name}`,r),fe("form:registered",e,r.name)}async function Xe(e,t){let{getRegisteredToolName:n}=await Promise.resolve().then(()=>(H(),oe)),r=n(e);r&&(await M(e),W.delete(e),t.debug&&console.debug(`[auto-webmcp] Unregistered: ${r}`),fe("form:unregistered",e,r))}var S=null,W=new WeakSet,j=0,D=new Map,Qe=300;function Ze(e){let t=e.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select")return!0;let n=e.getAttribute("role");if(n&&y.includes(n)||e.querySelector("input, textarea, select"))return!0;for(let r of y)if(e.querySelector(`[role="${r}"]`))return!0;return!1}function et(e,t){let n=D.get(e);n&&clearTimeout(n),D.set(e,setTimeout(()=>{D.delete(e),I(e,t)},Qe))}function tt(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){I(r,e);continue}let o=r.closest("form");o instanceof HTMLFormElement&&W.has(o)&&Ze(r)&&et(o,e);for(let i of Array.from(r.querySelectorAll("form")))I(i,e)}for(let r of n.removedNodes){if(!(r instanceof Element))continue;let o=r instanceof HTMLFormElement?[r]:Array.from(r.querySelectorAll("form"));for(let i of o)Xe(i,e)}}}),S.observe(document.body,{childList:!0,subtree:!0}))}function nt(e){window.addEventListener("hashchange",()=>x(e));let t={pushState:history.pushState.bind(history),replaceState:history.replaceState.bind(history)};history.pushState=function(...n){t.pushState(...n),x(e)},history.replaceState=function(...n){t.replaceState(...n),x(e)},window.addEventListener("popstate",()=>x(e))}async function x(e){let t=Array.from(document.querySelectorAll("form"));await Promise.allSettled(t.map(n=>I(n,e)))}var rt=new Set(["password","hidden","file","submit","reset","button","image"]);async function ot(e){if(!E())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(i=>{if(i instanceof HTMLInputElement&&rt.has(i.type.toLowerCase()))return!1;let s=i.getBoundingClientRect();return s.width>0&&s.height>0});if(r.length===0)return;let o=new Map;for(let i of r){let s=i.parentElement,a=i.parentElement??document.body;for(;s&&s!==document.body;){if(s.querySelector(t)!==null||Array.from(s.querySelectorAll("button")).some(c=>n.test(c.textContent??""))){a=s;break}s=s.parentElement}o.has(a)||o.set(a,[]),o.get(a).push(i)}for(let[i,s]of o){let a=Array.from(i.querySelectorAll(t)).filter(d=>{let f=d.getBoundingClientRect();return f.width>0&&f.height>0}),l=a[a.length-1]??null;if(!l){let d=Array.from(document.querySelectorAll("button")).filter(f=>{let g=f.getBoundingClientRect();return g.width>0&&g.height>0&&n.test(f.textContent??"")});l=d[d.length-1]??null}let c=ne(i,s,l),u=[],p=c.inputSchema.properties;for(let d of s){let f=d.name||d.dataset.webmcpName||d.id||d.getAttribute("aria-label")||null,g=f?f.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64):null;g&&p[g]&&u.push({key:g,el:d})}let b=c.name,v=async d=>{for(let{key:f,el:g}of u)d[f]!==void 0&&de(g,d[f]);return window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:b}})),{content:[{type:"text",text:"Fields filled. Ready to submit."}]}};try{await navigator.modelContext.registerTool({name:c.name,description:c.description,inputSchema:c.inputSchema,execute:v}),e.debug&&console.debug(`[auto-webmcp] Orphan tool registered: ${c.name}`,c)}catch{}}}function it(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 ge(e){document.readyState==="loading"&&await new Promise(t=>document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})),j=0,tt(e),nt(e),await x(e),j===0&&await ot(e)}function Ee(){S?.disconnect(),S=null}H();async function be(e){let t=z(e);return t.debug&&console.debug("[auto-webmcp] Initializing",{webmcpSupported:E(),config:t}),await ge(t),{destroy:async()=>{Ee(),await _()},getTools:$,isSupported:E()}}typeof window<"u"&&!window.__AUTO_WEBMCP_NO_AUTOINIT&&be();return xe(st);})();
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 Xe(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(i=>i.type==="text").map(i=>i.text).join("").trim()}async function Qe(e,t){let r=`https://generativelanguage.googleapis.com/v1beta/models/${t.model??"gemini-1.5-flash"}:generateContent?key=${t.apiKey}`,o=await fetch(r,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:e}]}],generationConfig:{maxOutputTokens:150,temperature:.2}})});if(!o.ok)throw new Error(`Gemini API error: ${o.status}`);return(await o.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 Ze(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(Ze(e,t))return;let n;for(let[i,s]of Object.entries(t.overrides))try{if(e.matches(i)){n=s;break}}catch{}let r=te(e,n);t.enhance&&(t.debug&&console.debug(`[auto-webmcp] Enriching: ${r.name}\u2026`),r=await be(r,t.enhance)),t.debug&&lt(r.name,r.description);let o=pe(e,t,r.name,r);await $(e,r,o),z.add(e),J++,t.debug&&console.debug(`[auto-webmcp] Registered: ${r.name}`,r),he("form:registered",e,r.name)}async function et(e,t){let{getRegisteredToolName:n}=await Promise.resolve().then(()=>(w(),ce)),r=n(e);r&&(await L(e),z.delete(e),t.debug&&console.debug(`[auto-webmcp] Unregistered: ${r}`),he("form:unregistered",e,r))}var H=null,z=new WeakSet,J=0,j=new Map,tt=300;function nt(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 rt(e,t){let n=j.get(e);n&&clearTimeout(n),j.set(e,setTimeout(()=>{j.delete(e),F(e,t)},tt))}function it(e){H||(H=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 o=r.closest("form");o instanceof HTMLFormElement&&z.has(o)&&nt(r)&&rt(o,e);for(let i of Array.from(r.querySelectorAll("form")))F(i,e)}for(let r of n.removedNodes){if(!(r instanceof Element))continue;let o=r instanceof HTMLFormElement?[r]:Array.from(r.querySelectorAll("form"));for(let i of o)et(i,e)}}}),H.observe(document.body,{childList:!0,subtree:!0}))}function ot(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=>F(n,e)))}var st=new Set(["password","hidden","file","submit","reset","button","image"]);async function at(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(i=>{if(i instanceof HTMLInputElement&&st.has(i.type.toLowerCase()))return!1;let s=i.getBoundingClientRect();return s.width>0&&s.height>0});if(r.length===0)return;let o=new Map;for(let i of r){let s=i.parentElement,a=i.parentElement??document.body;for(;s&&s!==document.body;){if(s.querySelector(t)!==null||Array.from(s.querySelectorAll("button")).some(l=>n.test(l.textContent??""))){a=s;break}s=s.parentElement}o.has(a)||o.set(a,[]),o.get(a).push(i)}for(let[i,s]of o){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(document.querySelectorAll("button")).filter(g=>{let b=g.getBoundingClientRect();return b.width>0&&b.height>0&&n.test(g.textContent??"")});c=d[d.length-1]??null}let l=ae(i,s,c),f=[],u=l.inputSchema.properties;for(let d of s){let g=d.name||d.dataset.webmcpName||d.id||d.getAttribute("aria-label")||null,b=g?g.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,64):null;b&&u[b]&&f.push({key:b,el:d})}let m=l.name,p=async d=>{for(let{key:g,el:b}of f)d[g]!==void 0&&Ee(b,d[g]);return window.dispatchEvent(new CustomEvent("toolactivated",{detail:{toolName:m}})),{content:[{type:"text",text:"Fields filled. Ready to submit."}]}};try{await navigator.modelContext.registerTool({name:l.name,description:l.description,inputSchema:l.inputSchema,execute:p}),e.debug&&console.debug(`[auto-webmcp] Orphan tool registered: ${l.name}`,l)}catch{}}}function lt(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 Te(e){document.readyState==="loading"&&await new Promise(t=>document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})),J=0,it(e),ot(e),await v(e),J===0&&await at(e)}function ye(){H?.disconnect(),H=null}w();async function Me(e){let t=V(e);return t.debug&&console.debug("[auto-webmcp] Initializing",{webmcpSupported:h(),config:t}),await Te(t),{destroy:async()=>{ye(),await _()},getTools:N,isSupported:h()}}typeof window<"u"&&!window.__AUTO_WEBMCP_NO_AUTOINIT&&Me();return we(ct);})();
10
10
  //# sourceMappingURL=auto-webmcp.iife.js.map