@wp-playground/mcp 3.1.40 → 3.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.cjs +1 -1
- package/client.js +1 -1
- package/index.cjs +9 -9
- package/index.cjs.map +1 -1
- package/index.js +1181 -1176
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/{tool-executors-DtS6CH_z.cjs → tool-executors-DX_lR1Jc.cjs} +7 -6
- package/tool-executors-DX_lR1Jc.cjs.map +1 -0
- package/{tool-executors-CphtBrKd.js → tool-executors-DeiRNg9-.js} +34 -36
- package/tool-executors-DeiRNg9-.js.map +1 -0
- package/tools/tool-definitions.d.ts +1 -1
- package/tool-executors-CphtBrKd.js.map +0 -1
- package/tool-executors-DtS6CH_z.cjs.map +0 -1
package/client.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./tool-executors-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./tool-executors-DX_lR1Jc.cjs"),b=5e3;function h(r,o){const c=crypto.randomUUID();let e=null,n="",t=null,l=!1;function s(u){const d=r.list(),p=JSON.stringify(d);p!==n&&(n=p,u.send(JSON.stringify({type:"register",tabId:c,sites:d})))}async function a(){try{const u=await fetch(`http://127.0.0.1:${o}/bridge-token`);if(!u.ok){f();return}const{token:d}=await u.json();e=new WebSocket(`ws://127.0.0.1:${o}?token=${d}`)}catch{f();return}e.addEventListener("open",()=>{var u;n="",s(e),(u=r.onConnect)==null||u.call(r)}),e.addEventListener("message",async u=>{let d;try{d=JSON.parse(u.data)}catch{return}if(d.type!=="command")return;const{id:p,method:w,args:_,siteSlug:S}=d;try{const y=await E(r,w,_||[],S,o);(e==null?void 0:e.readyState)===WebSocket.OPEN&&e.send(JSON.stringify({id:p,type:"response",value:y}))}catch(y){const v=y instanceof Error?y.message:String(y);(e==null?void 0:e.readyState)===WebSocket.OPEN&&e.send(JSON.stringify({id:p,type:"response",error:v}))}}),e.addEventListener("close",()=>{e=null,f()}),e.addEventListener("error",()=>{})}function f(){l||(t=setTimeout(a,b))}return a(),{notifySitesChanged:()=>{(e==null?void 0:e.readyState)===WebSocket.OPEN&&s(e)},stop:()=>{l=!0,t!==null&&(clearTimeout(t),t=null),e&&(e.close(),e=null)}}}async function E(r,o,c,e,n){if(o==="__open_site_in_new_tab"){const a=new URL(window.location.href);if(a.searchParams.set("mcp-port",String(n)),a.searchParams.set("site-slug",e),!window.open(a.toString(),"_blank"))throw new Error("Pop-up blocked by browser. The user must allow pop-ups for this site.");return!0}if(o==="__rename_site"){const[a]=c;return await r.rename(a),!0}if(o==="__save_site")return await r.saveInBrowser();const t=r.getClient();if(!t)throw new Error(`No active client for site: ${e}`);const s=i.createToolClient(t)[o];if(typeof s!="function")throw new Error(`Unknown method: ${o}`);return await s(...c)}const m=i.getSiteToolDefinitions();let g=null;function N(r){const c=r.list().find(e=>e.isActive);if(!c)throw new Error("No active Playground site");return c}function T(r){if(typeof navigator>"u"||!navigator.modelContext)return;g==null||g.abort(),g=new AbortController;const o=g.signal;function c(){const n=r.getClient();if(!n)throw new Error("No client for active site");return n}const e=Object.entries(i.toolDefinitions).map(([n,t])=>({name:n,description:t.description,inputSchema:i.paramsToJsonSchema(t.params),annotations:t.annotations,execute:async l=>{try{const s=i.toolExecutors[n];if(!s)return{error:`No executor for "${n}"`};const a=i.createToolClient(c());return await s(a,l)}catch(s){return{error:`${t.errorPrefix}: ${i.stringifyError(s)}`}}}}));e.push(...x(r));for(const n of e)navigator.modelContext.registerTool(n,{signal:o})}function x(r){const o=m.playground_list_sites,c=m.playground_save_in_browser,e=m.playground_rename_site,n=m.playground_get_website_url;return[{name:"playground_list_sites",description:o.description,annotations:o.annotations,execute:async()=>{try{return{connectedTabs:1,sites:r.list().map(t=>({siteId:t.slug,name:t.name,storage:i.formatStorageLabel(t.storage),isActive:t.isActive}))}}catch(t){return{error:`${o.errorPrefix}: ${i.stringifyError(t)}`}}}},{name:"playground_save_in_browser",description:c.description,annotations:c.annotations,execute:async()=>{try{const t=N(r),l=i.formatStorageLabel(t.storage);if(l!=="temporary")return{success:!0,alreadySaved:!0,siteId:t.slug,name:t.name,storage:l};const s=await r.saveInBrowser();return{success:!0,alreadySaved:!1,siteId:s.slug,name:t.name??s.slug,storage:i.formatStorageLabel(s.storage)}}catch(t){return{error:`${c.errorPrefix}: ${i.stringifyError(t)}`}}}},{name:"playground_rename_site",description:e.description,inputSchema:i.paramsToJsonSchema(e.params),annotations:e.annotations,execute:async t=>{try{const l=t.newName,a=r.list().find(f=>f.isActive);return await r.rename(l),{success:!0,siteId:a==null?void 0:a.slug,newName:l}}catch(l){return{error:`${e.errorPrefix}: ${i.stringifyError(l)}`}}}},{name:"playground_get_website_url",description:n.description,annotations:n.annotations,execute:async()=>{try{return{url:window.location.href}}catch(t){return{error:`${n.errorPrefix}: ${i.stringifyError(t)}`}}}}]}exports.registerWebMCPTools=T;exports.startMcpBridge=h;
|
|
2
2
|
//# sourceMappingURL=client.cjs.map
|
package/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as _, t as N, a as x, s as m, b as S, f as w, g as $ } from "./tool-executors-
|
|
1
|
+
import { c as _, t as N, a as x, s as m, b as S, f as w, g as $ } from "./tool-executors-DeiRNg9-.js";
|
|
2
2
|
const T = 5e3;
|
|
3
3
|
function I(r, o) {
|
|
4
4
|
const a = crypto.randomUUID();
|