@wp-playground/mcp 3.1.61 → 3.1.62

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.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sources":["../../../../packages/playground/mcp/src/bridge-client.ts","../../../../packages/playground/mcp/src/webmcp.ts","../../../../packages/playground/mcp/src/webmcp-site-tools.ts"],"sourcesContent":["import type { PlaygroundClient } from '@wp-playground/remote';\nimport { createToolClient } from './tools/tool-executors';\nimport type { ToolClient } from './tools/tool-executors';\n\n/**\n * Configuration accepted by `startMcpBridge`. Only includes the\n * methods the bridge actually calls — callers can pass any wider\n * object (e.g. the full site-management API) and TypeScript will\n * accept it structurally.\n */\nexport interface PlaygroundBridgeConfig {\n\tlist(): Array<{\n\t\tslug: string;\n\t\tname: string;\n\t\tstorage: string;\n\t\tisActive: boolean;\n\t}>;\n\tgetClient(): PlaygroundClient | undefined;\n\trename(newName: string): Promise<void>;\n\tsaveInBrowser(): Promise<{ slug: string; storage: string }>;\n\tonConnect?: () => void;\n}\n\nexport interface McpBridgeHandle {\n\tnotifySitesChanged: () => void;\n\tstop: () => void;\n}\n\nconst RECONNECT_INTERVAL_MS = 5000;\n\nexport function startMcpBridge(\n\tconfig: PlaygroundBridgeConfig,\n\tport: number\n): McpBridgeHandle {\n\tconst tabId = crypto.randomUUID();\n\tlet ws: WebSocket | null = null;\n\tlet previousSitesSerialized = '';\n\tlet reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n\tlet stopped = false;\n\n\tfunction sendSitesRegistration(socket: WebSocket) {\n\t\tconst sites = config.list();\n\t\tconst serialized = JSON.stringify(sites);\n\t\tif (serialized === previousSitesSerialized) {\n\t\t\treturn;\n\t\t}\n\t\tpreviousSitesSerialized = serialized;\n\t\tsocket.send(JSON.stringify({ type: 'register', tabId, sites }));\n\t}\n\n\tasync function connect() {\n\t\ttry {\n\t\t\tconst response = await fetch(\n\t\t\t\t`http://127.0.0.1:${port}/bridge-token`\n\t\t\t);\n\t\t\tif (!response.ok) {\n\t\t\t\tscheduleReconnect();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { token } = await response.json();\n\t\t\tws = new WebSocket(`ws://127.0.0.1:${port}?token=${token}`);\n\t\t} catch {\n\t\t\tscheduleReconnect();\n\t\t\treturn;\n\t\t}\n\n\t\tws.addEventListener('open', () => {\n\t\t\tpreviousSitesSerialized = '';\n\t\t\tsendSitesRegistration(ws!);\n\t\t\tconfig.onConnect?.();\n\t\t});\n\n\t\tws.addEventListener('message', async (event) => {\n\t\t\tlet message;\n\t\t\ttry {\n\t\t\t\tmessage = JSON.parse(event.data as string);\n\t\t\t} catch {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (message.type !== 'command') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { id, method, args, siteSlug } = message;\n\t\t\ttry {\n\t\t\t\tconst value = await handleCommand(\n\t\t\t\t\tconfig,\n\t\t\t\t\tmethod,\n\t\t\t\t\targs || [],\n\t\t\t\t\tsiteSlug,\n\t\t\t\t\tport\n\t\t\t\t);\n\t\t\t\tif (ws?.readyState === WebSocket.OPEN) {\n\t\t\t\t\tws.send(JSON.stringify({ id, type: 'response', value }));\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst errorMsg =\n\t\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\t\tif (ws?.readyState === WebSocket.OPEN) {\n\t\t\t\t\tws.send(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\ttype: 'response',\n\t\t\t\t\t\t\terror: errorMsg,\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tws.addEventListener('close', () => {\n\t\t\tws = null;\n\t\t\tscheduleReconnect();\n\t\t});\n\n\t\tws.addEventListener('error', () => {\n\t\t\t// Error will be followed by close event,\n\t\t\t// which handles reconnect\n\t\t});\n\t}\n\n\tfunction scheduleReconnect() {\n\t\tif (stopped) {\n\t\t\treturn;\n\t\t}\n\t\treconnectTimer = setTimeout(connect, RECONNECT_INTERVAL_MS);\n\t}\n\n\tconnect();\n\n\treturn {\n\t\tnotifySitesChanged: () => {\n\t\t\tif (ws?.readyState === WebSocket.OPEN) {\n\t\t\t\tsendSitesRegistration(ws);\n\t\t\t}\n\t\t},\n\t\tstop: () => {\n\t\t\tstopped = true;\n\t\t\tif (reconnectTimer !== null) {\n\t\t\t\tclearTimeout(reconnectTimer);\n\t\t\t\treconnectTimer = null;\n\t\t\t}\n\t\t\tif (ws) {\n\t\t\t\tws.close();\n\t\t\t\tws = null;\n\t\t\t}\n\t\t},\n\t};\n}\n\nasync function handleCommand(\n\tconfig: PlaygroundBridgeConfig,\n\tmethod: string,\n\targs: unknown[],\n\tsiteSlug: string,\n\tport: number\n): Promise<unknown> {\n\tif (method === '__open_site_in_new_tab') {\n\t\tconst url = new URL(window.location.href);\n\t\turl.searchParams.set('mcp-port', String(port));\n\t\turl.searchParams.set('site-slug', siteSlug);\n\t\tconst newWindow = window.open(url.toString(), '_blank');\n\t\tif (!newWindow) {\n\t\t\tthrow new Error(\n\t\t\t\t'Pop-up blocked by browser. The user ' +\n\t\t\t\t\t'must allow pop-ups for this site.'\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (method === '__rename_site') {\n\t\tconst [newName] = args as [string];\n\t\tawait config.rename(newName);\n\t\treturn true;\n\t}\n\n\tif (method === '__save_site') {\n\t\treturn await config.saveInBrowser();\n\t}\n\n\tconst playgroundClient = config.getClient();\n\tif (!playgroundClient) {\n\t\tthrow new Error(`No active client for site: ${siteSlug}`);\n\t}\n\n\tconst client = createToolClient(playgroundClient);\n\tconst fn = client[method as keyof ToolClient];\n\tif (typeof fn !== 'function') {\n\t\tthrow new Error(`Unknown method: ${method}`);\n\t}\n\treturn await (fn as (...a: unknown[]) => Promise<unknown>)(...args);\n}\n","/**\n * WebMCP registration for WordPress Playground.\n *\n * Registers playground tools with `document.modelContext` (the\n * Chrome WebMCP API) so that browser-side AI agents can interact\n * with the running Playground site.\n */\n\nimport type { PlaygroundClient } from '@wp-playground/remote';\nimport {\n\ttoolDefinitions,\n\tgetSiteToolDefinitions,\n\tformatStorageLabel,\n\tparamsToJsonSchema,\n\tstringifyError,\n} from './tools/tool-definitions';\nimport { toolExecutors, createToolClient } from './tools/tool-executors';\nimport type { PlaygroundBridgeConfig } from './bridge-client';\n\nconst siteToolDefinitions = getSiteToolDefinitions();\n\n// -- WebMCP type declarations --\n\nexport interface ModelContextTool {\n\tname: string;\n\tdescription: string;\n\tinputSchema?: Record<string, unknown>;\n\texecute: (\n\t\tinput: Record<string, unknown>,\n\t\tclient: ModelContextClient\n\t) => Promise<unknown>;\n\tannotations?: { readOnlyHint?: boolean; destructiveHint?: boolean };\n}\n\ninterface ModelContextClient {\n\trequestUserInteraction(callback: () => Promise<unknown>): Promise<unknown>;\n}\n\ninterface ModelContext {\n\tprovideContext(options: { tools: ModelContextTool[] }): void;\n\tregisterTool(\n\t\ttool: ModelContextTool,\n\t\toptions?: { signal?: AbortSignal }\n\t): Promise<void> | void;\n\treadonly tools: ModelContextTool[];\n}\n\ndeclare global {\n\tinterface Document {\n\t\tmodelContext?: ModelContext;\n\t}\n}\n\n// -- Registration --\n\nlet registrationController: AbortController | null = null;\n\nfunction getActiveSite(config: PlaygroundBridgeConfig) {\n\tconst sites = config.list();\n\tconst active = sites.find((s) => s.isActive);\n\tif (!active) {\n\t\tthrow new Error('No active Playground site');\n\t}\n\treturn active;\n}\n\nexport async function registerWebMCPTools(\n\tconfig: PlaygroundBridgeConfig\n): Promise<void> {\n\tconst modelContext = getModelContext();\n\tif (!modelContext) {\n\t\treturn;\n\t}\n\n\t// Abort any previous registration before re-registering.\n\tregistrationController?.abort();\n\tregistrationController = new AbortController();\n\tconst controller = registrationController;\n\tconst signal = controller.signal;\n\n\tfunction getActiveClient(): PlaygroundClient {\n\t\tconst client = config.getClient();\n\t\tif (!client) {\n\t\t\tthrow new Error('No client for active site');\n\t\t}\n\t\treturn client;\n\t}\n\n\t// Per-site tools\n\tconst tools: ModelContextTool[] = Object.entries(toolDefinitions).map(\n\t\t([name, def]) => ({\n\t\t\tname,\n\t\t\tdescription: def.description,\n\t\t\tinputSchema: paramsToJsonSchema(def.params),\n\t\t\tannotations: def.annotations,\n\t\t\texecute: async (input) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst executor = toolExecutors[name];\n\t\t\t\t\tif (!executor) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\terror: `No executor for \"${name}\"`,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst adapter = createToolClient(getActiveClient());\n\t\t\t\t\treturn await executor(adapter, input);\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${def.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t);\n\n\t// Site management tools\n\ttools.push(...createSiteManagementTools(config));\n\n\tconst results = await Promise.allSettled(\n\t\ttools.map(async (tool) => {\n\t\t\tawait modelContext.registerTool(tool, { signal });\n\t\t})\n\t);\n\tconst failedRegistrations: Array<{ name: string; reason: unknown }> = [];\n\tfor (const [index, result] of results.entries()) {\n\t\tif (result.status === 'rejected') {\n\t\t\tfailedRegistrations.push({\n\t\t\t\tname: tools[index].name,\n\t\t\t\treason: result.reason,\n\t\t\t});\n\t\t}\n\t}\n\tif (failedRegistrations.length > 0) {\n\t\tcontroller.abort();\n\t\tif (registrationController === controller) {\n\t\t\tregistrationController = null;\n\t\t}\n\t\tthrow new Error(\n\t\t\t'Failed to register WebMCP tools: ' +\n\t\t\t\tfailedRegistrations\n\t\t\t\t\t.map(\n\t\t\t\t\t\t({ name, reason }) =>\n\t\t\t\t\t\t\t`${name} (${stringifyError(reason)})`\n\t\t\t\t\t)\n\t\t\t\t\t.join(', ')\n\t\t);\n\t}\n}\n\nexport function getModelContext(): ModelContext | undefined {\n\tif (typeof document === 'undefined') {\n\t\treturn undefined;\n\t}\n\tconst modelContext = document.modelContext;\n\treturn typeof modelContext?.registerTool === 'function'\n\t\t? modelContext\n\t\t: undefined;\n}\n\nfunction createSiteManagementTools(\n\tconfig: PlaygroundBridgeConfig\n): ModelContextTool[] {\n\tconst listDef = siteToolDefinitions['playground_list_sites'];\n\tconst saveDef = siteToolDefinitions['playground_save_in_browser'];\n\tconst renameDef = siteToolDefinitions['playground_rename_site'];\n\tconst websiteUrlDef = siteToolDefinitions['playground_get_website_url'];\n\n\treturn [\n\t\t{\n\t\t\tname: 'playground_list_sites',\n\t\t\tdescription: listDef.description,\n\t\t\tannotations: listDef.annotations,\n\t\t\texecute: async () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconnectedTabs: 1,\n\t\t\t\t\t\tsites: config.list().map((s) => ({\n\t\t\t\t\t\t\tsiteId: s.slug,\n\t\t\t\t\t\t\tname: s.name,\n\t\t\t\t\t\t\tstorage: formatStorageLabel(s.storage),\n\t\t\t\t\t\t\tisActive: s.isActive,\n\t\t\t\t\t\t})),\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${listDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'playground_save_in_browser',\n\t\t\tdescription: saveDef.description,\n\t\t\tannotations: saveDef.annotations,\n\t\t\texecute: async () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst site = getActiveSite(config);\n\t\t\t\t\tconst storage = formatStorageLabel(site.storage);\n\t\t\t\t\tif (storage !== 'temporary') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\talreadySaved: true,\n\t\t\t\t\t\t\tsiteId: site.slug,\n\t\t\t\t\t\t\tname: site.name,\n\t\t\t\t\t\t\tstorage,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst saved = await config.saveInBrowser();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\talreadySaved: false,\n\t\t\t\t\t\tsiteId: saved.slug,\n\t\t\t\t\t\tname: site.name ?? saved.slug,\n\t\t\t\t\t\tstorage: formatStorageLabel(saved.storage),\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${saveDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'playground_rename_site',\n\t\t\tdescription: renameDef.description,\n\t\t\tinputSchema: paramsToJsonSchema(renameDef.params),\n\t\t\tannotations: renameDef.annotations,\n\t\t\texecute: async (input) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst newName = input['newName'] as string;\n\t\t\t\t\tconst sites = config.list();\n\t\t\t\t\tconst activeSite = sites.find((s) => s.isActive);\n\t\t\t\t\tawait config.rename(newName);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\tsiteId: activeSite?.slug,\n\t\t\t\t\t\tnewName,\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${renameDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'playground_get_website_url',\n\t\t\tdescription: websiteUrlDef.description,\n\t\t\tannotations: websiteUrlDef.annotations,\n\t\t\texecute: async () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn {\n\t\t\t\t\t\turl: window.location.href,\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${websiteUrlDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t];\n}\n","/**\n * Re-advertises the WebMCP tools registered inside the WordPress document as\n * tools of the Playground page itself.\n *\n * A plugin running in Playground can register tools with\n * `document.modelContext`, but that registry lives in a nested,\n * service-worker-served iframe an agent never sees. This proxy mirrors those\n * tools onto the top-level `document.modelContext` and forwards each call back\n * into the WordPress document:\n *\n * agent → document.modelContext (this page)\n * → PlaygroundClient.callWebMCPTool() (Comlink)\n * → remote frame (postMessage)\n * → WordPress document (the plugin's execute())\n */\n\nimport type {\n\tPlaygroundClient,\n\tWebMCPToolDescriptor,\n} from '@wp-playground/remote';\nimport { logger } from '@php-wasm/logger';\nimport {\n\ttoolDefinitions,\n\tgetSiteToolDefinitions,\n\tstringifyError,\n} from './tools/tool-definitions';\nimport type { ModelContextTool } from './webmcp';\nimport { getModelContext } from './webmcp';\n\nexport interface WebMCPSiteToolProxy {\n\tstop(): void;\n}\n\n/**\n * Starts mirroring `client`'s in-site WebMCP tools onto this page.\n *\n * Every announcement carries the full tool list, so the previous registration\n * is aborted and the new list registered in its place. Returns a handle that\n * unregisters everything it registered.\n */\nexport function startWebMCPSiteToolProxy(\n\tclient: PlaygroundClient\n): WebMCPSiteToolProxy {\n\tconst maybeModelContext = getModelContext();\n\tif (!maybeModelContext) {\n\t\t// Nothing can be advertised, so there is nothing to observe for.\n\t\treturn { stop: () => {} };\n\t}\n\t// `register` is hoisted, so it does not inherit the narrowing above.\n\tconst modelContext = maybeModelContext;\n\n\tconst reserved = reservedToolNames();\n\tlet registration: AbortController | null = null;\n\tlet stopped = false;\n\tlet registeredDescriptors = '';\n\n\tasync function register(tools: WebMCPToolDescriptor[]) {\n\t\tif (stopped) {\n\t\t\treturn;\n\t\t}\n\t\t// Registration is asynchronous, so a burst of announcements could\n\t\t// otherwise re-register an unchanged list several times over.\n\t\tconst descriptors = JSON.stringify(tools);\n\t\tif (descriptors === registeredDescriptors) {\n\t\t\treturn;\n\t\t}\n\t\tregisteredDescriptors = descriptors;\n\n\t\tregistration?.abort();\n\t\tregistration = new AbortController();\n\t\tconst { signal } = registration;\n\n\t\tfor (const tool of tools) {\n\t\t\tif (reserved.has(tool.name)) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Skipping the WebMCP tool \"${tool.name}\" registered by ` +\n\t\t\t\t\t\t`the site: Playground already provides a tool under ` +\n\t\t\t\t\t\t`that name.`\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait modelContext.registerTool(proxyTool(client, tool), {\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Failed to register the site's WebMCP tool ` +\n\t\t\t\t\t\t`\"${tool.name}\": ${stringifyError(error)}`\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (signal.aborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tclient\n\t\t.onWebMCPToolsChanged((tools: WebMCPToolDescriptor[]) => {\n\t\t\tvoid register(tools);\n\t\t})\n\t\t.catch((error) => {\n\t\t\tlogger.warn(\"Failed to observe the site's WebMCP tools:\", error);\n\t\t});\n\n\treturn {\n\t\tstop() {\n\t\t\tstopped = true;\n\t\t\tregistration?.abort();\n\t\t\tregistration = null;\n\t\t\tregisteredDescriptors = '';\n\t\t},\n\t};\n}\n\n/**\n * Names Playground registers itself. A site tool may not take one of them\n * over, or an agent asking to execute PHP would reach the site's plugin\n * instead.\n */\nfunction reservedToolNames(): Set<string> {\n\treturn new Set([\n\t\t...Object.keys(toolDefinitions),\n\t\t...Object.keys(getSiteToolDefinitions()),\n\t]);\n}\n\nfunction proxyTool(\n\tclient: PlaygroundClient,\n\ttool: WebMCPToolDescriptor\n): ModelContextTool {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tinputSchema: tool.inputSchema,\n\t\tannotations: tool.annotations,\n\t\texecute: async (input) => {\n\t\t\ttry {\n\t\t\t\treturn await client.callWebMCPTool(tool.name, input ?? {});\n\t\t\t} catch (error) {\n\t\t\t\treturn {\n\t\t\t\t\terror:\n\t\t\t\t\t\t`Error running the WordPress site's \"${tool.name}\" ` +\n\t\t\t\t\t\t`tool: ${stringifyError(error)}`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n}\n"],"names":["RECONNECT_INTERVAL_MS","startMcpBridge","config","port","tabId","ws","previousSitesSerialized","reconnectTimer","stopped","sendSitesRegistration","socket","sites","serialized","connect","response","scheduleReconnect","token","_a","event","message","id","method","args","siteSlug","value","handleCommand","error","errorMsg","url","newName","playgroundClient","fn","createToolClient","siteToolDefinitions","getSiteToolDefinitions","registrationController","getActiveSite","active","s","registerWebMCPTools","modelContext","getModelContext","controller","signal","getActiveClient","client","tools","toolDefinitions","name","def","paramsToJsonSchema","input","executor","toolExecutors","adapter","stringifyError","createSiteManagementTools","results","tool","failedRegistrations","index","result","reason","listDef","saveDef","renameDef","websiteUrlDef","formatStorageLabel","site","storage","saved","activeSite","startWebMCPSiteToolProxy","maybeModelContext","reserved","reservedToolNames","registration","registeredDescriptors","register","descriptors","logger","proxyTool"],"mappings":";;AA4BA,MAAMA,IAAwB;AAEvB,SAASC,EACfC,GACAC,GACkB;AAClB,QAAMC,IAAQ,OAAO,WAAA;AACrB,MAAIC,IAAuB,MACvBC,IAA0B,IAC1BC,IAAuD,MACvDC,IAAU;AAEd,WAASC,EAAsBC,GAAmB;AACjD,UAAMC,IAAQT,EAAO,KAAA,GACfU,IAAa,KAAK,UAAUD,CAAK;AACvC,IAAIC,MAAeN,MAGnBA,IAA0BM,GAC1BF,EAAO,KAAK,KAAK,UAAU,EAAE,MAAM,YAAY,OAAAN,GAAO,OAAAO,EAAA,CAAO,CAAC;AAAA,EAC/D;AAEA,iBAAeE,IAAU;AACxB,QAAI;AACH,YAAMC,IAAW,MAAM;AAAA,QACtB,oBAAoBX,CAAI;AAAA,MAAA;AAEzB,UAAI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AA,UACN,8CACKtB,EAAK,IAAI,MAAMH,EAAe7B,CAAK,CAAC;AAAA,QAAA;AAAA,MAE3C;AACA,UAAIiB,EAAO;AACV;AAAA,IAEF;AAAA,EACD;AAEA,SAAAE,EACE,qBAAqB,CAACC,MAAkC;AACxD,IAAKgC,EAAShC,CAAK;AAAA,EACpB,CAAC,EACA,MAAM,CAACpB,MAAU;AACjB,IAAAsD,EAAO,KAAK,8CAA8CtD,CAAK;AAAA,EAChE,CAAC,GAEK;AAAA,IACN,OAAO;AACN,MAAAlB,IAAU,IACVoE,KAAA,QAAAA,EAAc,SACdA,IAAe,MACfC,IAAwB;AAAA,IACzB;AAAA,EAAA;AAEF;AAOA,SAASF,IAAiC;AACzC,6BAAW,IAAI;AAAA,IACd,GAAG,OAAO,KAAK5B,CAAe;AAAA,IAC9B,GAAG,OAAO,KAAKb,EAAA,CAAwB;AAAA,EAAA,CACvC;AACF;AAEA,SAAS+C,EACRpC,GACAa,GACmB;AACnB,SAAO;AAAA,IACN,MAAMA,EAAK;AAAA,IACX,aAAaA,EAAK;AAAA,IAClB,aAAaA,EAAK;AAAA,IAClB,aAAaA,EAAK;AAAA,IAClB,SAAS,OAAOP,MAAU;AACzB,UAAI;AACH,eAAO,MAAMN,EAAO,eAAea,EAAK,MAAMP,KAAS,EAAE;AAAA,MAC1D,SAASzB,GAAO;AACf,eAAO;AAAA,UACN,OACC,uCAAuCgC,EAAK,IAAI,WACvCH,EAAe7B,CAAK,CAAC;AAAA,QAAA;AAAA,MAEjC;AAAA,IACD;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"client.js","sources":["../../../../packages/playground/mcp/src/bridge-client.ts","../../../../packages/playground/mcp/src/webmcp.ts","../../../../packages/playground/mcp/src/webmcp-site-tools.ts"],"sourcesContent":["import type { PlaygroundClient } from '@wp-playground/remote';\nimport { createToolClient } from './tools/tool-executors';\nimport type { ToolClient } from './tools/tool-executors';\n\n/**\n * Configuration accepted by `startMcpBridge`. Only includes the\n * methods the bridge actually calls — callers can pass any wider\n * object (e.g. the full site-management API) and TypeScript will\n * accept it structurally.\n */\nexport interface PlaygroundBridgeConfig {\n\tlist(): Array<{\n\t\tslug: string;\n\t\tname: string;\n\t\tstorage: string;\n\t\tisActive: boolean;\n\t}>;\n\tgetClient(): PlaygroundClient | undefined;\n\trename(newName: string): Promise<void>;\n\tsaveInBrowser(): Promise<{ slug: string; storage: string }>;\n\tonConnect?: () => void;\n}\n\nexport interface McpBridgeHandle {\n\tnotifySitesChanged: () => void;\n\tstop: () => void;\n}\n\nconst RECONNECT_INTERVAL_MS = 5000;\n\nexport function startMcpBridge(\n\tconfig: PlaygroundBridgeConfig,\n\tport: number\n): McpBridgeHandle {\n\tconst tabId = crypto.randomUUID();\n\tlet ws: WebSocket | null = null;\n\tlet previousSitesSerialized = '';\n\tlet reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n\tlet stopped = false;\n\n\tfunction sendSitesRegistration(socket: WebSocket) {\n\t\tconst sites = config.list();\n\t\tconst serialized = JSON.stringify(sites);\n\t\tif (serialized === previousSitesSerialized) {\n\t\t\treturn;\n\t\t}\n\t\tpreviousSitesSerialized = serialized;\n\t\tsocket.send(JSON.stringify({ type: 'register', tabId, sites }));\n\t}\n\n\tasync function connect() {\n\t\ttry {\n\t\t\tconst response = await fetch(\n\t\t\t\t`http://127.0.0.1:${port}/bridge-token`\n\t\t\t);\n\t\t\tif (!response.ok) {\n\t\t\t\tscheduleReconnect();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { token } = await response.json();\n\t\t\tws = new WebSocket(`ws://127.0.0.1:${port}?token=${token}`);\n\t\t} catch {\n\t\t\tscheduleReconnect();\n\t\t\treturn;\n\t\t}\n\n\t\tws.addEventListener('open', () => {\n\t\t\tpreviousSitesSerialized = '';\n\t\t\tsendSitesRegistration(ws!);\n\t\t\tconfig.onConnect?.();\n\t\t});\n\n\t\tws.addEventListener('message', async (event) => {\n\t\t\tlet message;\n\t\t\ttry {\n\t\t\t\tmessage = JSON.parse(event.data as string);\n\t\t\t} catch {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (message.type !== 'command') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { id, method, args, siteSlug } = message;\n\t\t\ttry {\n\t\t\t\tconst value = await handleCommand(\n\t\t\t\t\tconfig,\n\t\t\t\t\tmethod,\n\t\t\t\t\targs || [],\n\t\t\t\t\tsiteSlug,\n\t\t\t\t\tport\n\t\t\t\t);\n\t\t\t\tif (ws?.readyState === WebSocket.OPEN) {\n\t\t\t\t\tws.send(JSON.stringify({ id, type: 'response', value }));\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst errorMsg =\n\t\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\t\tif (ws?.readyState === WebSocket.OPEN) {\n\t\t\t\t\tws.send(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\ttype: 'response',\n\t\t\t\t\t\t\terror: errorMsg,\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tws.addEventListener('close', () => {\n\t\t\tws = null;\n\t\t\tscheduleReconnect();\n\t\t});\n\n\t\tws.addEventListener('error', () => {\n\t\t\t// Error will be followed by close event,\n\t\t\t// which handles reconnect\n\t\t});\n\t}\n\n\tfunction scheduleReconnect() {\n\t\tif (stopped) {\n\t\t\treturn;\n\t\t}\n\t\treconnectTimer = setTimeout(connect, RECONNECT_INTERVAL_MS);\n\t}\n\n\tconnect();\n\n\treturn {\n\t\tnotifySitesChanged: () => {\n\t\t\tif (ws?.readyState === WebSocket.OPEN) {\n\t\t\t\tsendSitesRegistration(ws);\n\t\t\t}\n\t\t},\n\t\tstop: () => {\n\t\t\tstopped = true;\n\t\t\tif (reconnectTimer !== null) {\n\t\t\t\tclearTimeout(reconnectTimer);\n\t\t\t\treconnectTimer = null;\n\t\t\t}\n\t\t\tif (ws) {\n\t\t\t\tws.close();\n\t\t\t\tws = null;\n\t\t\t}\n\t\t},\n\t};\n}\n\nasync function handleCommand(\n\tconfig: PlaygroundBridgeConfig,\n\tmethod: string,\n\targs: unknown[],\n\tsiteSlug: string,\n\tport: number\n): Promise<unknown> {\n\tif (method === '__open_site_in_new_tab') {\n\t\tconst url = new URL(window.location.href);\n\t\turl.searchParams.set('mcp-port', String(port));\n\t\turl.searchParams.set('site-slug', siteSlug);\n\t\tconst newWindow = window.open(url.toString(), '_blank');\n\t\tif (!newWindow) {\n\t\t\tthrow new Error(\n\t\t\t\t'Pop-up blocked by browser. The user ' +\n\t\t\t\t\t'must allow pop-ups for this site.'\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (method === '__rename_site') {\n\t\tconst [newName] = args as [string];\n\t\tawait config.rename(newName);\n\t\treturn true;\n\t}\n\n\tif (method === '__save_site') {\n\t\treturn await config.saveInBrowser();\n\t}\n\n\tconst playgroundClient = config.getClient();\n\tif (!playgroundClient) {\n\t\tthrow new Error(`No active client for site: ${siteSlug}`);\n\t}\n\n\tconst client = createToolClient(playgroundClient);\n\tconst fn = client[method as keyof ToolClient];\n\tif (typeof fn !== 'function') {\n\t\tthrow new Error(`Unknown method: ${method}`);\n\t}\n\treturn await (fn as (...a: unknown[]) => Promise<unknown>)(...args);\n}\n","/**\n * WebMCP registration for WordPress Playground.\n *\n * Registers playground tools with `document.modelContext` (the\n * Chrome WebMCP API) so that browser-side AI agents can interact\n * with the running Playground site.\n */\n\nimport type { PlaygroundClient } from '@wp-playground/remote';\nimport {\n\ttoolDefinitions,\n\tgetSiteToolDefinitions,\n\tformatStorageLabel,\n\tparamsToJsonSchema,\n\tstringifyError,\n} from './tools/tool-definitions';\nimport { toolExecutors, createToolClient } from './tools/tool-executors';\nimport type { PlaygroundBridgeConfig } from './bridge-client';\n\nconst siteToolDefinitions = getSiteToolDefinitions();\n\n// -- WebMCP type declarations --\n\nexport interface ModelContextTool {\n\tname: string;\n\tdescription: string;\n\tinputSchema?: Record<string, unknown>;\n\texecute: (\n\t\tinput: Record<string, unknown>,\n\t\tclient?: ModelContextClient\n\t) => Promise<unknown>;\n\tannotations?: {\n\t\treadOnlyHint?: boolean;\n\t\tdestructiveHint?: boolean;\n\t\tconsequentialHint?: boolean;\n\t\tuntrustedContentHint?: boolean;\n\t\tdebugging?: boolean;\n\t};\n}\n\ninterface ModelContextClient {\n\tsignal?: AbortSignal;\n\trequestUserInteraction?(callback: () => Promise<unknown>): Promise<unknown>;\n}\n\ninterface ModelContext {\n\tprovideContext(options: { tools: ModelContextTool[] }): void;\n\tregisterTool(\n\t\ttool: ModelContextTool,\n\t\toptions?: { signal?: AbortSignal }\n\t): Promise<void> | void;\n\treadonly tools: ModelContextTool[];\n}\n\ndeclare global {\n\tinterface Document {\n\t\tmodelContext?: ModelContext;\n\t}\n}\n\n// -- Registration --\n\nlet registrationController: AbortController | null = null;\n\nfunction getActiveSite(config: PlaygroundBridgeConfig) {\n\tconst sites = config.list();\n\tconst active = sites.find((s) => s.isActive);\n\tif (!active) {\n\t\tthrow new Error('No active Playground site');\n\t}\n\treturn active;\n}\n\nexport async function registerWebMCPTools(\n\tconfig: PlaygroundBridgeConfig\n): Promise<void> {\n\tconst modelContext = getModelContext();\n\tif (!modelContext) {\n\t\treturn;\n\t}\n\n\t// Abort any previous registration before re-registering.\n\tregistrationController?.abort();\n\tregistrationController = new AbortController();\n\tconst controller = registrationController;\n\tconst signal = controller.signal;\n\n\tfunction getActiveClient(): PlaygroundClient {\n\t\tconst client = config.getClient();\n\t\tif (!client) {\n\t\t\tthrow new Error('No client for active site');\n\t\t}\n\t\treturn client;\n\t}\n\n\t// Per-site tools\n\tconst tools: ModelContextTool[] = Object.entries(toolDefinitions).map(\n\t\t([name, def]) => ({\n\t\t\tname,\n\t\t\tdescription: def.description,\n\t\t\tinputSchema: paramsToJsonSchema(def.params),\n\t\t\tannotations: def.annotations,\n\t\t\texecute: async (input, client) => {\n\t\t\t\ttry {\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\tconst executor = toolExecutors[name];\n\t\t\t\t\tif (!executor) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\terror: `No executor for \"${name}\"`,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst adapter = createToolClient(getActiveClient());\n\t\t\t\t\tconst result = await executor(\n\t\t\t\t\t\tadapter,\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\tclient?.signal\n\t\t\t\t\t);\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\treturn result;\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${def.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t);\n\n\t// Site management tools\n\ttools.push(...createSiteManagementTools(config));\n\n\tconst results = await Promise.allSettled(\n\t\ttools.map(async (tool) => {\n\t\t\tawait modelContext.registerTool(tool, { signal });\n\t\t})\n\t);\n\tconst failedRegistrations: Array<{ name: string; reason: unknown }> = [];\n\tfor (const [index, result] of results.entries()) {\n\t\tif (result.status === 'rejected') {\n\t\t\tfailedRegistrations.push({\n\t\t\t\tname: tools[index].name,\n\t\t\t\treason: result.reason,\n\t\t\t});\n\t\t}\n\t}\n\tif (failedRegistrations.length > 0) {\n\t\tcontroller.abort();\n\t\tif (registrationController === controller) {\n\t\t\tregistrationController = null;\n\t\t}\n\t\tthrow new Error(\n\t\t\t'Failed to register WebMCP tools: ' +\n\t\t\t\tfailedRegistrations\n\t\t\t\t\t.map(\n\t\t\t\t\t\t({ name, reason }) =>\n\t\t\t\t\t\t\t`${name} (${stringifyError(reason)})`\n\t\t\t\t\t)\n\t\t\t\t\t.join(', ')\n\t\t);\n\t}\n}\n\nexport function getModelContext(): ModelContext | undefined {\n\tif (typeof document === 'undefined') {\n\t\treturn undefined;\n\t}\n\tconst modelContext = document.modelContext;\n\treturn typeof modelContext?.registerTool === 'function'\n\t\t? modelContext\n\t\t: undefined;\n}\n\nfunction createSiteManagementTools(\n\tconfig: PlaygroundBridgeConfig\n): ModelContextTool[] {\n\tconst listDef = siteToolDefinitions['playground_list_sites'];\n\tconst saveDef = siteToolDefinitions['playground_save_in_browser'];\n\tconst renameDef = siteToolDefinitions['playground_rename_site'];\n\tconst websiteUrlDef = siteToolDefinitions['playground_get_website_url'];\n\n\treturn [\n\t\t{\n\t\t\tname: 'playground_list_sites',\n\t\t\tdescription: listDef.description,\n\t\t\tinputSchema: paramsToJsonSchema(listDef.params),\n\t\t\tannotations: listDef.annotations,\n\t\t\texecute: async (_input, client) => {\n\t\t\t\ttry {\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconnectedTabs: 1,\n\t\t\t\t\t\tsites: config.list().map((s) => ({\n\t\t\t\t\t\t\tsiteId: s.slug,\n\t\t\t\t\t\t\tname: s.name,\n\t\t\t\t\t\t\tstorage: formatStorageLabel(s.storage),\n\t\t\t\t\t\t\tisActive: s.isActive,\n\t\t\t\t\t\t})),\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${listDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'playground_save_in_browser',\n\t\t\tdescription: saveDef.description,\n\t\t\tinputSchema: paramsToJsonSchema(saveDef.params),\n\t\t\tannotations: saveDef.annotations,\n\t\t\texecute: async (_input, client) => {\n\t\t\t\ttry {\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\tconst site = getActiveSite(config);\n\t\t\t\t\tconst storage = formatStorageLabel(site.storage);\n\t\t\t\t\tif (storage !== 'temporary') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\talreadySaved: true,\n\t\t\t\t\t\t\tsiteId: site.slug,\n\t\t\t\t\t\t\tname: site.name,\n\t\t\t\t\t\t\tstorage,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\t// Storage operations do not currently expose an interrupt API.\n\t\t\t\t\tconst saved = await config.saveInBrowser();\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\talreadySaved: false,\n\t\t\t\t\t\tsiteId: saved.slug,\n\t\t\t\t\t\tname: site.name ?? saved.slug,\n\t\t\t\t\t\tstorage: formatStorageLabel(saved.storage),\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${saveDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'playground_rename_site',\n\t\t\tdescription: renameDef.description,\n\t\t\tinputSchema: paramsToJsonSchema(renameDef.params),\n\t\t\tannotations: renameDef.annotations,\n\t\t\texecute: async (input, client) => {\n\t\t\t\ttry {\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\tconst newName = input['newName'] as string;\n\t\t\t\t\tconst sites = config.list();\n\t\t\t\t\tconst activeSite = sites.find((s) => s.isActive);\n\t\t\t\t\tawait config.rename(newName);\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\tsiteId: activeSite?.slug,\n\t\t\t\t\t\tnewName,\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${renameDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'playground_get_website_url',\n\t\t\tdescription: websiteUrlDef.description,\n\t\t\tinputSchema: paramsToJsonSchema(websiteUrlDef.params),\n\t\t\tannotations: websiteUrlDef.annotations,\n\t\t\texecute: async (_input, client) => {\n\t\t\t\ttry {\n\t\t\t\t\tclient?.signal?.throwIfAborted();\n\t\t\t\t\treturn {\n\t\t\t\t\t\turl: window.location.href,\n\t\t\t\t\t};\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\terror: `${websiteUrlDef.errorPrefix}: ${stringifyError(error)}`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t];\n}\n","/**\n * Re-advertises the WebMCP tools registered inside the WordPress document as\n * tools of the Playground page itself.\n *\n * A plugin running in Playground can register tools with\n * `document.modelContext`, but that registry lives in a nested,\n * service-worker-served iframe an agent never sees. This proxy mirrors those\n * tools onto the top-level `document.modelContext` and forwards each call back\n * into the WordPress document:\n *\n * agent → document.modelContext (this page)\n * → PlaygroundClient.callWebMCPTool() (Comlink)\n * → remote frame (postMessage)\n * → WordPress document (the plugin's execute())\n */\n\nimport type {\n\tPlaygroundClient,\n\tWebMCPToolDescriptor,\n} from '@wp-playground/remote';\nimport { logger } from '@php-wasm/logger';\nimport {\n\ttoolDefinitions,\n\tgetSiteToolDefinitions,\n\tstringifyError,\n} from './tools/tool-definitions';\nimport type { ModelContextTool } from './webmcp';\nimport { getModelContext } from './webmcp';\n\nexport interface WebMCPSiteToolProxy {\n\tstop(): void;\n}\n\n/**\n * Starts mirroring `client`'s in-site WebMCP tools onto this page.\n *\n * Every announcement carries the full tool list, so the previous registration\n * is aborted and the new list registered in its place. Returns a handle that\n * unregisters everything it registered.\n */\nexport function startWebMCPSiteToolProxy(\n\tclient: PlaygroundClient\n): WebMCPSiteToolProxy {\n\tconst maybeModelContext = getModelContext();\n\tif (!maybeModelContext) {\n\t\t// Nothing can be advertised, so there is nothing to observe for.\n\t\treturn { stop: () => {} };\n\t}\n\t// `register` is hoisted, so it does not inherit the narrowing above.\n\tconst modelContext = maybeModelContext;\n\n\tconst reserved = reservedToolNames();\n\tlet registration: AbortController | null = null;\n\tlet stopped = false;\n\tlet registeredDescriptors = '';\n\n\tasync function register(tools: WebMCPToolDescriptor[]) {\n\t\tif (stopped) {\n\t\t\treturn;\n\t\t}\n\t\t// Registration is asynchronous, so a burst of announcements could\n\t\t// otherwise re-register an unchanged list several times over.\n\t\tconst descriptors = JSON.stringify(tools);\n\t\tif (descriptors === registeredDescriptors) {\n\t\t\treturn;\n\t\t}\n\t\tregisteredDescriptors = descriptors;\n\n\t\tregistration?.abort();\n\t\tregistration = new AbortController();\n\t\tconst { signal } = registration;\n\n\t\tfor (const tool of tools) {\n\t\t\tif (reserved.has(tool.name)) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Skipping the WebMCP tool \"${tool.name}\" registered by ` +\n\t\t\t\t\t\t`the site: Playground already provides a tool under ` +\n\t\t\t\t\t\t`that name.`\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait modelContext.registerTool(proxyTool(client, tool), {\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Failed to register the site's WebMCP tool ` +\n\t\t\t\t\t\t`\"${tool.name}\": ${stringifyError(error)}`\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (signal.aborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tclient\n\t\t.onWebMCPToolsChanged((tools: WebMCPToolDescriptor[]) => {\n\t\t\tvoid register(tools);\n\t\t})\n\t\t.catch((error) => {\n\t\t\tlogger.warn(\"Failed to observe the site's WebMCP tools:\", error);\n\t\t});\n\n\treturn {\n\t\tstop() {\n\t\t\tstopped = true;\n\t\t\tregistration?.abort();\n\t\t\tregistration = null;\n\t\t\tregisteredDescriptors = '';\n\t\t},\n\t};\n}\n\n/**\n * Names Playground registers itself. A site tool may not take one of them\n * over, or an agent asking to execute PHP would reach the site's plugin\n * instead.\n */\nfunction reservedToolNames(): Set<string> {\n\treturn new Set([\n\t\t...Object.keys(toolDefinitions),\n\t\t...Object.keys(getSiteToolDefinitions()),\n\t]);\n}\n\nfunction proxyTool(\n\tclient: PlaygroundClient,\n\ttool: WebMCPToolDescriptor\n): ModelContextTool {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tinputSchema: tool.inputSchema,\n\t\tannotations: tool.annotations,\n\t\texecute: async (input, clientArg) => {\n\t\t\tconst signal = clientArg?.signal;\n\t\t\tconst callId = crypto.randomUUID();\n\t\t\tconst abort = () => {\n\t\t\t\tvoid client.cancelWebMCPTool(callId).catch((error) => {\n\t\t\t\t\tlogger.warn('Failed to cancel the site tool:', error);\n\t\t\t\t});\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tsignal?.addEventListener('abort', abort, { once: true });\n\t\t\t\tconst result = await client.callWebMCPTool(\n\t\t\t\t\ttool.name,\n\t\t\t\t\tinput ?? {},\n\t\t\t\t\tcallId\n\t\t\t\t);\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\treturn result;\n\t\t\t} catch (error) {\n\t\t\t\treturn {\n\t\t\t\t\terror:\n\t\t\t\t\t\t`Error running the WordPress site's \"${tool.name}\" ` +\n\t\t\t\t\t\t`tool: ${stringifyError(error)}`,\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tsignal?.removeEventListener('abort', abort);\n\t\t\t}\n\t\t},\n\t};\n}\n"],"names":["RECONNECT_INTERVAL_MS","startMcpBridge","config","port","tabId","ws","previousSitesSerialized","reconnectTimer","stopped","sendSitesRegistration","socket","sites","serialized","connect","response","scheduleReconnect","token","_a","event","message","id","method","args","siteSlug","value","handleCommand","error","errorMsg","url","newName","playgroundClient","fn","createToolClient","siteToolDefinitions","getSiteToolDefinitions","registrationController","getActiveSite","active","s","registerWebMCPTools","modelContext","getModelContext","controller","signal","getActiveClient","client","tools","toolDefinitions","name","def","paramsToJsonSchema","input","executor","toolExecutors","adapter","result","_b","stringifyError","createSiteManagementTools","results","tool","failedRegistrations","index","reason","listDef","saveDef","renameDef","websiteUrlDef","_input","formatStorageLabel","site","storage","saved","activeSite","startWebMCPSiteToolProxy","maybeModelContext","reserved","reservedToolNames","registration","registeredDescriptors","register","descriptors","logger","proxyTool","clientArg","callId","abort"],"mappings":";;AA4BA,MAAMA,IAAwB;AAEvB,SAASC,EACfC,GACAC,GACkB;AAClB,QAAMC,IAAQ,OAAO,WAAA;AACrB,MAAIC,IAAuB,MACvBC,IAA0B,IAC1BC,IAAuD,MACvDC,IAAU;AAEd,WAASC,EAAsBC,GAAmB;AACjD,UAAMC,IAAQT,EAAO,KAAA,GACfU,IAAa,KAAK,UAAUD,CAAK;AACvC,IAAIC,MAAeN,MAGnBA,IAA0BM,GAC1BF,EAAO,KAAK,KAAK,UAAU,EAAE,MAAM,YAAY,OAAAN,GAAO,OAAAO,EAAA,CAAO,CAAC;AAAA,EAC/D;AAEA,iBAAeE,IAAU;AACxB,QAAI;AACH,YAAMC,IAAW,MAAM;AAAA,QACtB,oBAAoBX,CAAI;AAAA,MAAA;AAEzB,UAAI,CAACW,EAAS,IAAI;AACjB,QAAAC,EAAA;AACA;AAAA,MACD;AACA,YAAM,EAAE,OAAAC,EAAA,IAAU,MAAMF,EAAS,KAAA;AACjC,MAAAT,IAAK,IAAI,UAAU,kBAAkBF,CAAI,UAAUa,CAAK,EAAE;AAAA,IAC3D,QAAQ;AACP,MAAAD,EAAA;AACA;AAAA,IACD;AAEA,IAAAV,EAAG,iBAAiB,QAAQ,MAAM;;AACjC,MAAAC,IAA0B,IAC1BG,EAAsBJ,CAAG,IACzBY,IAAAf,EAAO,cAAP,QAAAe,EAAA,KAAAf;AAAA,IACD,CAAC,GAEDG,EAAG,iBAAiB,WAAW,OAAOa,MAAU;AAC/C,UAAIC;AACJ,UAAI;AACH,QAAAA,IAAU,KAAK,MAAMD,EAAM,IAAc;AAAA,MAC1C,QAAQ;AACP;AAAA,MACD;AACA,UAAIC,EAAQ,S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AA,QAAAA,EAAQ,iBAAiB,SAAS2C,GAAO,EAAE,MAAM;AACjD,cAAM/B,IAAS,MAAMV,EAAO;AAAA,UAC3Be,EAAK;AAAA,UACLT,KAAS,CAAA;AAAA,UACTkC;AAAA,QAAA;AAED,eAAA1C,KAAA,QAAAA,EAAQ,kBACDY;AAAA,MACR,SAAS7B,GAAO;AACf,eAAO;AAAA,UACN,OACC,uCAAuCkC,EAAK,IAAI,WACvCH,EAAe/B,CAAK,CAAC;AAAA,QAAA;AAAA,MAEjC,UAAA;AACC,QAAAiB,KAAA,QAAAA,EAAQ,oBAAoB,SAAS2C;AAAA,MACtC;AAAA,IACD;AAAA,EAAA;AAEF;"}
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";const Rr=require("node:process"),ao=require("ws"),co=require("node:http"),uo=require("node:crypto"),Qe=require("./tool-executors-BhDxY6BQ.cjs"),$s=require("ajv"),lo=require("zod"),fo=require("module");var yn=typeof document<"u"?document.currentScript:null;function _(t,e,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,c);const u=o.prototype,l=Object.keys(u);for(let f=0;f<l.length;f++){const p=l[f];p in a||(a[p]=u[p].bind(a))}}const s=(n==null?void 0:n.Parent)??Object;class i extends s{}Object.defineProperty(i,"name",{value:t});function o(a){var c;const u=n!=null&&n.Parent?new i:this;r(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const l of u._zod.deferred)l();return u}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,u;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(u=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:u.has(t)}}),Object.defineProperty(o,"name",{value:t}),o}class it extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Rs extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ps={};function Fe(t){return Ps}function Ns(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,s])=>e.indexOf(+r)===-1).map(([r,s])=>s)}function $n(t,e){return typeof e=="bigint"?e.toString():e}function an(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Kn(t){return t==null}function Yn(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function ho(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let s=(r.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c!=null&&c[1]&&(s=Number.parseInt(c[1]))}const i=n>s?n:s,o=Number.parseInt(t.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return o%a/10**i}const Pr=Symbol("evaluating");function W(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==Pr)return r===void 0&&(r=Pr,r=n()),r},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function et(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function He(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function Nr(t){return JSON.stringify(t)}function mo(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Es="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function St(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const po=an(()=>{var t;if(typeof navigator<"u"&&((t=navigator==null?void 0:navigator.userAgent)!=null&&t.includes("Cloudflare")))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function ot(t){if(St(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(St(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Is(t){return ot(t)?{...t}:Array.isArray(t)?[...t]:t}const go=new Set(["string","number","symbol"]);function at(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Me(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n!=null&&n.parent)&&(r._zod.parent=t),r}function P(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if((e==null?void 0:e.message)!==void 0){if((e==null?void 0:e.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function _o(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const yo={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function vo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(o[a]=n.shape[a])}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function bo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={...t._zod.def.shape};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete o[a]}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function wo(t,e){if(!ot(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0){const i=t._zod.def.shape;for(const o in e)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=He(t._zod.def,{get shape(){const i={...t._zod.def.shape,...e};return et(this,"shape",i),i}});return Me(t,s)}function ko(t,e){if(!ot(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e};return et(this,"shape",r),r}});return Me(t,n)}function So(t,e){const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return et(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return Me(t,n)}function To(t,e,n){const s=e._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=He(e._zod.def,{get shape(){const a=e._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=t?new t({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=t?new t({type:"optional",innerType:a[u]}):a[u];return et(this,"shape",c),c},checks:[]});return Me(e,o)}function zo(t,e,n){const r=He(e._zod.def,{get shape(){const s=e._zod.def.shape,i={...s};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)i[o]=new t({type:"nonoptional",innerType:s[o]});return et(this,"shape",i),i}});return Me(e,r)}function nt(t,e=0){var n;if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(((n=t.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function rt(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function jt(t){return typeof t=="string"?t:t==null?void 0:t.message}function Ue(t,e,n){var s,i,o,a,c,u;const r={...t,path:t.path??[]};if(!t.message){const l=jt((o=(i=(s=t.inst)==null?void 0:s._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,t))??jt((a=e==null?void 0:e.error)==null?void 0:a.call(e,t))??jt((c=n.customError)==null?void 0:c.call(n,t))??jt((u=n.localeError)==null?void 0:u.call(n,t))??"Invalid input";r.message=l}return delete r.inst,delete r.continue,e!=null&&e.reportInput||delete r.input,r}function Qn(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Tt(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const Cs=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,$n,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Os=_("$ZodError",Cs),cn=_("$ZodError",Cs,{Parent:Error});function $o(t,e=n=>n.message){const n={},r=[];for(const s of t.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:n}}function Ro(t,e=n=>n.message){const n={_errors:[]},r=s=>{for(const i of s.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>r({issues:o}));else if(i.code==="invalid_key")r({issues:i.issues});else if(i.code==="invalid_element")r({issues:i.issues});else if(i.path.length===0)n._errors.push(e(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(e(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return r(t),n}const un=t=>(e,n,r,s)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new it;if(o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Es(a,s==null?void 0:s.callee),a}return o.value},Po=un(cn),ln=t=>async(e,n,r,s)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Es(a,s==null?void 0:s.callee),a}return o.value},No=ln(cn),dn=t=>(e,n,r)=>{const s=r?{...r,async:!1}:{async:!1},i=e._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new it;return i.issues.length?{success:!1,error:new(t??Os)(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},Xn=dn(cn),fn=t=>async(e,n,r)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=e._zod.run({value:n,issues:[]},s);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new t(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},er=fn(cn),Eo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return un(t)(e,n,s)},Io=t=>(e,n,r)=>un(t)(e,n,r),Co=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ln(t)(e,n,s)},Oo=t=>async(e,n,r)=>ln(t)(e,n,r),xo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return dn(t)(e,n,s)},Zo=t=>(e,n,r)=>dn(t)(e,n,r),Ao=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return fn(t)(e,n,s)},jo=t=>async(e,n,r)=>fn(t)(e,n,r),Mo=/^[cC][^\s-]{8,}$/,Lo=/^[0-9a-z]+$/,Do=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,qo=/^[0-9a-vA-V]{20}$/,Fo=/^[A-Za-z0-9]{27}$/,Uo=/^[a-zA-Z0-9_-]{21}$/,Vo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ho=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Er=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Jo=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Bo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Wo(){return new RegExp(Bo,"u")}const Go=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ko=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Yo=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Qo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Xo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,xs=/^[A-Za-z0-9_-]*$/,ea=/^\+[1-9]\d{6,14}$/,Zs="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",ta=new RegExp(`^${Zs}$`);function As(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function na(t){return new RegExp(`^${As(t)}$`)}function ra(t){const e=As({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${Zs}T(?:${r})$`)}const sa=t=>{const e=t?`[\\s\\S]{${(t==null?void 0:t.minimum)??0},${(t==null?void 0:t.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},ia=/^-?\d+$/,js=/^-?\d+(?:\.\d+)?$/,oa=/^(?:true|false)$/i,aa=/^null$/i,ca=/^[^A-Z]*$/,ua=/^[^a-z]*$/,Se=_("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),Ms={number:"number",bigint:"bigint",object:"date"},Ls=_("$ZodCheckLessThan",(t,e)=>{Se.init(t,e);const n=Ms[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<i&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Ds=_("$ZodCheckGreaterThan",(t,e)=>{Se.init(t,e);const n=Ms[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>i&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),la=_("$ZodCheckMultipleOf",(t,e)=>{Se.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):ho(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),da=_("$ZodCheckNumberFormat",(t,e)=>{var o;Se.init(t,e),e.format=e.format||"float64";const n=(o=e.format)==null?void 0:o.includes("int"),r=n?"int":"number",[s,i]=yo[e.format];t._zod.onattach.push(a=>{const c=a._zod.bag;c.format=e.format,c.minimum=s,c.maximum=i,n&&(c.pattern=ia)}),t._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort});return}}c<s&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:t,continue:!e.abort})}}),fa=_("$ZodCheckMaxLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const s=r.value;if(s.length<=e.maximum)return;const o=Qn(s);r.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ha=_("$ZodCheckMinLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const s=r.value;if(s.length>=e.minimum)return;const o=Qn(s);r.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ma=_("$ZodCheckLengthEquals",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=r=>{const s=r.value,i=s.length;if(i===e.length)return;const o=Qn(s),a=i>e.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),hn=_("$ZodCheckStringFormat",(t,e)=>{var n,r;Se.init(t,e),t._zod.onattach.push(s=>{const i=s._zod.bag;i.format=e.format,e.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),pa=_("$ZodCheckRegex",(t,e)=>{hn.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),ga=_("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=ca),hn.init(t,e)}),_a=_("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=ua),hn.init(t,e)}),ya=_("$ZodCheckIncludes",(t,e)=>{Se.init(t,e);const n=at(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(s=>{const i=s._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),va=_("$ZodCheckStartsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`^${at(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),ba=_("$ZodCheckEndsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`.*${at(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}}),wa=_("$ZodCheckOverwrite",(t,e)=>{Se.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class ka{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
1
+ "use strict";const Rr=require("node:process"),ao=require("ws"),co=require("node:http"),uo=require("node:crypto"),Qe=require("./tool-executors-CkOyDA_-.cjs"),$s=require("ajv"),lo=require("zod"),fo=require("module");var yn=typeof document<"u"?document.currentScript:null;function _(t,e,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,c);const u=o.prototype,l=Object.keys(u);for(let f=0;f<l.length;f++){const p=l[f];p in a||(a[p]=u[p].bind(a))}}const s=(n==null?void 0:n.Parent)??Object;class i extends s{}Object.defineProperty(i,"name",{value:t});function o(a){var c;const u=n!=null&&n.Parent?new i:this;r(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const l of u._zod.deferred)l();return u}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,u;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(u=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:u.has(t)}}),Object.defineProperty(o,"name",{value:t}),o}class it extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Rs extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ps={};function Fe(t){return Ps}function Ns(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,s])=>e.indexOf(+r)===-1).map(([r,s])=>s)}function $n(t,e){return typeof e=="bigint"?e.toString():e}function an(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function Kn(t){return t==null}function Yn(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function ho(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let s=(r.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c!=null&&c[1]&&(s=Number.parseInt(c[1]))}const i=n>s?n:s,o=Number.parseInt(t.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return o%a/10**i}const Pr=Symbol("evaluating");function W(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==Pr)return r===void 0&&(r=Pr,r=n()),r},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function et(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function He(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function Nr(t){return JSON.stringify(t)}function mo(t){return t.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Es="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function St(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const po=an(()=>{var t;if(typeof navigator<"u"&&((t=navigator==null?void 0:navigator.userAgent)!=null&&t.includes("Cloudflare")))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function ot(t){if(St(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(St(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Is(t){return ot(t)?{...t}:Array.isArray(t)?[...t]:t}const go=new Set(["string","number","symbol"]);function at(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Me(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n!=null&&n.parent)&&(r._zod.parent=t),r}function P(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if((e==null?void 0:e.message)!==void 0){if((e==null?void 0:e.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function _o(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const yo={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function vo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(o[a]=n.shape[a])}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function bo(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=He(t._zod.def,{get shape(){const o={...t._zod.def.shape};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete o[a]}return et(this,"shape",o),o},checks:[]});return Me(t,i)}function wo(t,e){if(!ot(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0){const i=t._zod.def.shape;for(const o in e)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=He(t._zod.def,{get shape(){const i={...t._zod.def.shape,...e};return et(this,"shape",i),i}});return Me(t,s)}function ko(t,e){if(!ot(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e};return et(this,"shape",r),r}});return Me(t,n)}function So(t,e){const n=He(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return et(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return Me(t,n)}function To(t,e,n){const s=e._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=He(e._zod.def,{get shape(){const a=e._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=t?new t({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=t?new t({type:"optional",innerType:a[u]}):a[u];return et(this,"shape",c),c},checks:[]});return Me(e,o)}function zo(t,e,n){const r=He(e._zod.def,{get shape(){const s=e._zod.def.shape,i={...s};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)i[o]=new t({type:"nonoptional",innerType:s[o]});return et(this,"shape",i),i}});return Me(e,r)}function nt(t,e=0){var n;if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(((n=t.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function rt(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function jt(t){return typeof t=="string"?t:t==null?void 0:t.message}function Ue(t,e,n){var s,i,o,a,c,u;const r={...t,path:t.path??[]};if(!t.message){const l=jt((o=(i=(s=t.inst)==null?void 0:s._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,t))??jt((a=e==null?void 0:e.error)==null?void 0:a.call(e,t))??jt((c=n.customError)==null?void 0:c.call(n,t))??jt((u=n.localeError)==null?void 0:u.call(n,t))??"Invalid input";r.message=l}return delete r.inst,delete r.continue,e!=null&&e.reportInput||delete r.input,r}function Qn(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Tt(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const Cs=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,$n,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Os=_("$ZodError",Cs),cn=_("$ZodError",Cs,{Parent:Error});function $o(t,e=n=>n.message){const n={},r=[];for(const s of t.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:n}}function Ro(t,e=n=>n.message){const n={_errors:[]},r=s=>{for(const i of s.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>r({issues:o}));else if(i.code==="invalid_key")r({issues:i.issues});else if(i.code==="invalid_element")r({issues:i.issues});else if(i.path.length===0)n._errors.push(e(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(e(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return r(t),n}const un=t=>(e,n,r,s)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new it;if(o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Es(a,s==null?void 0:s.callee),a}return o.value},Po=un(cn),ln=t=>async(e,n,r,s)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=e._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((s==null?void 0:s.Err)??t)(o.issues.map(c=>Ue(c,i,Fe())));throw Es(a,s==null?void 0:s.callee),a}return o.value},No=ln(cn),dn=t=>(e,n,r)=>{const s=r?{...r,async:!1}:{async:!1},i=e._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new it;return i.issues.length?{success:!1,error:new(t??Os)(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},Xn=dn(cn),fn=t=>async(e,n,r)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=e._zod.run({value:n,issues:[]},s);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new t(i.issues.map(o=>Ue(o,s,Fe())))}:{success:!0,data:i.value}},er=fn(cn),Eo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return un(t)(e,n,s)},Io=t=>(e,n,r)=>un(t)(e,n,r),Co=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ln(t)(e,n,s)},Oo=t=>async(e,n,r)=>ln(t)(e,n,r),xo=t=>(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return dn(t)(e,n,s)},Zo=t=>(e,n,r)=>dn(t)(e,n,r),Ao=t=>async(e,n,r)=>{const s=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return fn(t)(e,n,s)},jo=t=>async(e,n,r)=>fn(t)(e,n,r),Mo=/^[cC][^\s-]{8,}$/,Lo=/^[0-9a-z]+$/,Do=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,qo=/^[0-9a-vA-V]{20}$/,Fo=/^[A-Za-z0-9]{27}$/,Uo=/^[a-zA-Z0-9_-]{21}$/,Vo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ho=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Er=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Jo=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Bo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Wo(){return new RegExp(Bo,"u")}const Go=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ko=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Yo=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Qo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Xo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,xs=/^[A-Za-z0-9_-]*$/,ea=/^\+[1-9]\d{6,14}$/,Zs="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",ta=new RegExp(`^${Zs}$`);function As(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function na(t){return new RegExp(`^${As(t)}$`)}function ra(t){const e=As({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${e}(?:${n.join("|")})`;return new RegExp(`^${Zs}T(?:${r})$`)}const sa=t=>{const e=t?`[\\s\\S]{${(t==null?void 0:t.minimum)??0},${(t==null?void 0:t.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},ia=/^-?\d+$/,js=/^-?\d+(?:\.\d+)?$/,oa=/^(?:true|false)$/i,aa=/^null$/i,ca=/^[^A-Z]*$/,ua=/^[^a-z]*$/,Se=_("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),Ms={number:"number",bigint:"bigint",object:"date"},Ls=_("$ZodCheckLessThan",(t,e)=>{Se.init(t,e);const n=Ms[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<i&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Ds=_("$ZodCheckGreaterThan",(t,e)=>{Se.init(t,e);const n=Ms[typeof e.value];t._zod.onattach.push(r=>{const s=r._zod.bag,i=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>i&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),la=_("$ZodCheckMultipleOf",(t,e)=>{Se.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):ho(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),da=_("$ZodCheckNumberFormat",(t,e)=>{var o;Se.init(t,e),e.format=e.format||"float64";const n=(o=e.format)==null?void 0:o.includes("int"),r=n?"int":"number",[s,i]=yo[e.format];t._zod.onattach.push(a=>{const c=a._zod.bag;c.format=e.format,c.minimum=s,c.maximum=i,n&&(c.pattern=ia)}),t._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort});return}}c<s&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:t,continue:!e.abort})}}),fa=_("$ZodCheckMaxLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const s=r.value;if(s.length<=e.maximum)return;const o=Qn(s);r.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ha=_("$ZodCheckMinLength",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const s=r.value;if(s.length>=e.minimum)return;const o=Qn(s);r.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),ma=_("$ZodCheckLengthEquals",(t,e)=>{var n;Se.init(t,e),(n=t._zod.def).when??(n.when=r=>{const s=r.value;return!Kn(s)&&s.length!==void 0}),t._zod.onattach.push(r=>{const s=r._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=r=>{const s=r.value,i=s.length;if(i===e.length)return;const o=Qn(s),a=i>e.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),hn=_("$ZodCheckStringFormat",(t,e)=>{var n,r;Se.init(t,e),t._zod.onattach.push(s=>{const i=s._zod.bag;i.format=e.format,e.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),pa=_("$ZodCheckRegex",(t,e)=>{hn.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),ga=_("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=ca),hn.init(t,e)}),_a=_("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=ua),hn.init(t,e)}),ya=_("$ZodCheckIncludes",(t,e)=>{Se.init(t,e);const n=at(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(s=>{const i=s._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),va=_("$ZodCheckStartsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`^${at(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),ba=_("$ZodCheckEndsWith",(t,e)=>{Se.init(t,e);const n=new RegExp(`.*${at(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}}),wa=_("$ZodCheckOverwrite",(t,e)=>{Se.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class ka{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
2
2
  `).filter(o=>o),s=Math.min(...r.map(o=>o.length-o.trimStart().length)),i=r.map(o=>o.slice(s)).map(o=>" ".repeat(this.indent*2)+o);for(const o of i)this.content.push(o)}compile(){const e=Function,n=this==null?void 0:this.args,s=[...((this==null?void 0:this.content)??[""]).map(i=>` ${i}`)];return new e(...n,s.join(`
3
3
  `))}}const Sa={major:4,minor:3,patch:6},ee=_("$ZodType",(t,e)=>{var s;var n;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=Sa;const r=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&r.unshift(t);for(const i of r)for(const o of i._zod.onattach)o(t);if(r.length===0)(n=t._zod).deferred??(n.deferred=[]),(s=t._zod.deferred)==null||s.push(()=>{t._zod.run=t._zod.parse});else{const i=(a,c,u)=>{let l=nt(a),f;for(const p of c){if(p._zod.def.when){if(!p._zod.def.when(a))continue}else if(l)continue;const m=a.issues.length,v=p._zod.check(a);if(v instanceof Promise&&(u==null?void 0:u.async)===!1)throw new it;if(f||v instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await v,a.issues.length!==m&&(l||(l=nt(a,m)))});else{if(a.issues.length===m)continue;l||(l=nt(a,m))}}return f?f.then(()=>a):a},o=(a,c,u)=>{if(nt(a))return a.aborted=!0,a;const l=i(c,r,u);if(l instanceof Promise){if(u.async===!1)throw new it;return l.then(f=>t._zod.parse(f,u))}return t._zod.parse(l,u)};t._zod.run=(a,c)=>{if(c.skipChecks)return t._zod.parse(a,c);if(c.direction==="backward"){const l=t._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});return l instanceof Promise?l.then(f=>o(f,a,c)):o(l,a,c)}const u=t._zod.parse(a,c);if(u instanceof Promise){if(c.async===!1)throw new it;return u.then(l=>i(l,r,c))}return i(u,r,c)}}W(t,"~standard",()=>({validate:i=>{var o;try{const a=Xn(t,i);return a.success?{value:a.data}:{issues:(o=a.error)==null?void 0:o.issues}}catch{return er(t,i).then(c=>{var u;return c.success?{value:c.data}:{issues:(u=c.error)==null?void 0:u.issues}})}},vendor:"zod",version:1}))}),tr=_("$ZodString",(t,e)=>{var n;ee.init(t,e),t._zod.pattern=[...((n=t==null?void 0:t._zod.bag)==null?void 0:n.patterns)??[]].pop()??sa(t._zod.bag),t._zod.parse=(r,s)=>{if(e.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:t}),r}}),ne=_("$ZodStringFormat",(t,e)=>{hn.init(t,e),tr.init(t,e)}),Ta=_("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Ho),ne.init(t,e)}),za=_("$ZodUUID",(t,e)=>{if(e.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(r===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Er(r))}else e.pattern??(e.pattern=Er());ne.init(t,e)}),$a=_("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Jo),ne.init(t,e)}),Ra=_("$ZodURL",(t,e)=>{ne.init(t,e),t._zod.check=n=>{try{const r=n.value.trim(),s=new URL(r);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(s.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:e.hostname.source,input:n.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:n.value,inst:t,continue:!e.abort})),e.normalize?n.value=s.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:t,continue:!e.abort})}}}),Pa=_("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Wo()),ne.init(t,e)}),Na=_("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=Uo),ne.init(t,e)}),Ea=_("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=Mo),ne.init(t,e)}),Ia=_("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=Lo),ne.init(t,e)}),Ca=_("$ZodULID",(t,e)=>{e.pattern??(e.pattern=Do),ne.init(t,e)}),Oa=_("$ZodXID",(t,e)=>{e.pattern??(e.pattern=qo),ne.init(t,e)}),xa=_("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Fo),ne.init(t,e)}),Za=_("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=ra(e)),ne.init(t,e)}),Aa=_("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=ta),ne.init(t,e)}),ja=_("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=na(e)),ne.init(t,e)}),Ma=_("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=Vo),ne.init(t,e)}),La=_("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=Go),ne.init(t,e),t._zod.bag.format="ipv4"}),Da=_("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Ko),ne.init(t,e),t._zod.bag.format="ipv6",t._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:t,continue:!e.abort})}}}),qa=_("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Yo),ne.init(t,e)}),Fa=_("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=Qo),ne.init(t,e),t._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[s,i]=r;if(!i)throw new Error;const o=Number(i);if(`${o}`!==i)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${s}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:t,continue:!e.abort})}}});function qs(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const Ua=_("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Xo),ne.init(t,e),t._zod.bag.contentEncoding="base64",t._zod.check=n=>{qs(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:t,continue:!e.abort})}});function Va(t){if(!xs.test(t))return!1;const e=t.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=e.padEnd(Math.ceil(e.length/4)*4,"=");return qs(n)}const Ha=_("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=xs),ne.init(t,e),t._zod.bag.contentEncoding="base64url",t._zod.check=n=>{Va(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:t,continue:!e.abort})}}),Ja=_("$ZodE164",(t,e)=>{e.pattern??(e.pattern=ea),ne.init(t,e)});function Ba(t,e=null){try{const n=t.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const s=JSON.parse(atob(r));return!("typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||e&&(!("alg"in s)||s.alg!==e))}catch{return!1}}const Wa=_("$ZodJWT",(t,e)=>{ne.init(t,e),t._zod.check=n=>{Ba(n.value,e.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:t,continue:!e.abort})}}),Fs=_("$ZodNumber",(t,e)=>{ee.init(t,e),t._zod.pattern=t._zod.bag.pattern??js,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=Number(n.value)}catch{}const s=n.value;if(typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s))return n;const i=typeof s=="number"?Number.isNaN(s)?"NaN":Number.isFinite(s)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:s,inst:t,...i?{received:i}:{}}),n}}),Ga=_("$ZodNumberFormat",(t,e)=>{da.init(t,e),Fs.init(t,e)}),Ka=_("$ZodBoolean",(t,e)=>{ee.init(t,e),t._zod.pattern=oa,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=!!n.value}catch{}const s=n.value;return typeof s=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:s,inst:t}),n}}),Ya=_("$ZodNull",(t,e)=>{ee.init(t,e),t._zod.pattern=aa,t._zod.values=new Set([null]),t._zod.parse=(n,r)=>{const s=n.value;return s===null||n.issues.push({expected:"null",code:"invalid_type",input:s,inst:t}),n}}),Qa=_("$ZodUnknown",(t,e)=>{ee.init(t,e),t._zod.parse=n=>n}),Xa=_("$ZodNever",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:t}),n)});function Ir(t,e,n){t.issues.length&&e.issues.push(...rt(n,t.issues)),e.value[n]=t.value}const ec=_("$ZodArray",(t,e)=>{ee.init(t,e),t._zod.parse=(n,r)=>{const s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:t}),n;n.value=Array(s.length);const i=[];for(let o=0;o<s.length;o++){const a=s[o],c=e.element._zod.run({value:a,issues:[]},r);c instanceof Promise?i.push(c.then(u=>Ir(u,n,o))):Ir(c,n,o)}return i.length?Promise.all(i).then(()=>n):n}});function qt(t,e,n,r,s){if(t.issues.length){if(s&&!(n in r))return;e.issues.push(...rt(n,t.issues))}t.value===void 0?n in r&&(e.value[n]=void 0):e.value[n]=t.value}function Us(t){var r,s,i,o;const e=Object.keys(t.shape);for(const a of e)if(!((o=(i=(s=(r=t.shape)==null?void 0:r[a])==null?void 0:s._zod)==null?void 0:i.traits)!=null&&o.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=_o(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}}function Vs(t,e,n,r,s,i){const o=[],a=s.keySet,c=s.catchall._zod,u=c.def.type,l=c.optout==="optional";for(const f in e){if(a.has(f))continue;if(u==="never"){o.push(f);continue}const p=c.run({value:e[f],issues:[]},r);p instanceof Promise?t.push(p.then(m=>qt(m,n,f,e,l))):qt(p,n,f,e,l)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:i}),t.length?Promise.all(t).then(()=>n):n}const Hs=_("$ZodObject",(t,e)=>{ee.init(t,e);const n=Object.getOwnPropertyDescriptor(e,"shape");if(!(n!=null&&n.get)){const a=e.shape;Object.defineProperty(e,"shape",{get:()=>{const c={...a};return Object.defineProperty(e,"shape",{value:c}),c}})}const r=an(()=>Us(e));W(t._zod,"propValues",()=>{const a=e.shape,c={};for(const u in a){const l=a[u]._zod;if(l.values){c[u]??(c[u]=new Set);for(const f of l.values)c[u].add(f)}}return c});const s=St,i=e.catchall;let o;t._zod.parse=(a,c)=>{o??(o=r.value);const u=a.value;if(!s(u))return a.issues.push({expected:"object",code:"invalid_type",input:u,inst:t}),a;a.value={};const l=[],f=o.shape;for(const p of o.keys){const m=f[p],v=m._zod.optout==="optional",T=m._zod.run({value:u[p],issues:[]},c);T instanceof Promise?l.push(T.then(x=>qt(x,a,p,u,v))):qt(T,a,p,u,v)}return i?Vs(l,u,a,c,r.value,t):l.length?Promise.all(l).then(()=>a):a}}),tc=_("$ZodObjectJIT",(t,e)=>{Hs.init(t,e);const n=t._zod.parse,r=an(()=>Us(e)),s=p=>{var A;const m=new ka(["shape","payload","ctx"]),v=r.value,T=j=>{const L=Nr(j);return`shape[${L}]._zod.run({ value: input[${L}], issues: [] }, ctx)`};m.write("const input = payload.value;");const x=Object.create(null);let b=0;for(const j of v.keys)x[j]=`key_${b++}`;m.write("const newResult = {};");for(const j of v.keys){const L=x[j],ue=Nr(j),K=p[j],_e=((A=K==null?void 0:K._zod)==null?void 0:A.optout)==="optional";m.write(`const ${L} = ${T(j)};`),_e?m.write(`
4
4
  if (${L}.issues.length) {
package/index.js CHANGED
@@ -3,7 +3,7 @@ import $r from "node:process";
3
3
  import { WebSocketServer as oo } from "ws";
4
4
  import { createServer as ao } from "node:http";
5
5
  import { randomUUID as co } from "node:crypto";
6
- import { f as Ts, p as uo, t as lo, a as fo, g as ho, s as mo } from "./tool-executors-jX-K5l3h.js";
6
+ import { f as Ts, p as uo, t as lo, a as fo, g as ho, s as mo } from "./tool-executors-D1J1qKnB.js";
7
7
  import $s from "ajv";
8
8
  import { ZodOptional as po } from "zod";
9
9
  import { createRequire as go } from "module";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/mcp",
3
- "version": "3.1.61",
3
+ "version": "3.1.62",
4
4
  "description": "MCP server for WordPress Playground - enables AI agents to interact with the WordPress Playground website.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,11 +40,11 @@
40
40
  "postal-mime": "2.7.5",
41
41
  "ws": "8.21.0",
42
42
  "zod": "^4.3",
43
- "@wp-playground/remote": "3.1.61",
44
- "@php-wasm/universal": "3.1.61",
45
- "@php-wasm/logger": "3.1.61"
43
+ "@wp-playground/remote": "3.1.62",
44
+ "@php-wasm/universal": "3.1.62",
45
+ "@php-wasm/logger": "3.1.62"
46
46
  },
47
- "gitHead": "1e779217fceedb5b29b1359a196dc97ce40f31de",
47
+ "gitHead": "8c52f103f3ce30668994c0e75c2c530b82097a5e",
48
48
  "packageManager": "npm@10.9.2",
49
49
  "overrides": {
50
50
  "rollup": "^4.34.6",
@@ -1,4 +1,4 @@
1
- "use strict";const y="https://playground.wordpress.net/";function g(e,t){if(!t)return`${y}?mcp-port=${e}`;const n=new URL(t);return n.searchParams.set("mcp-port",String(e)),n.toString()}const m={playground_execute_php:{title:"Execute PHP Code",errorPrefix:"Error executing PHP",description:`Run arbitrary PHP code in WordPress Playground
1
+ "use strict";const m="https://playground.wordpress.net/";function w(e,t){if(!t)return`${m}?mcp-port=${e}`;const n=new URL(t);return n.searchParams.set("mcp-port",String(e)),n.toString()}const _={playground_execute_php:{title:"Execute PHP Code",errorPrefix:"Error executing PHP",description:`Run arbitrary PHP code in WordPress Playground
2
2
  and return the output.
3
3
 
4
4
  WordPress is NOT bootstrapped automatically. To use
@@ -17,7 +17,7 @@
17
17
  WARNING: output is returned in full with no
18
18
  truncation — avoid queries that produce unbounded
19
19
  output (e.g. SELECT * without LIMIT). Keep output
20
- under 50 KB to avoid filling the context window.`,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"code",type:"string",description:`PHP code to execute. Example:
20
+ under 50 KB to avoid filling the context window.`,annotations:{readOnlyHint:!1,destructiveHint:!0,consequentialHint:!0,debugging:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"code",type:"string",description:`PHP code to execute. Example:
21
21
  "<?php echo get_bloginfo('name');"`,required:!0}]},playground_request:{title:"HTTP Request",errorPrefix:"Error making request",description:`Make an HTTP request to the WordPress site
22
22
  running in Playground. REST API requests
23
23
  (/wp-json/* or ?rest_route=) are automatically
@@ -83,7 +83,7 @@
83
83
 
84
84
  Note: full HTML responses can be very large and may
85
85
  fill the context window. To change the URL the user
86
- sees in their tab, use playground_navigate instead.`,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!0},params:[{name:"url",type:"string",description:`Request URL path, e.g.
86
+ sees in their tab, use playground_navigate instead.`,annotations:{readOnlyHint:!1,destructiveHint:!1,consequentialHint:!0,untrustedContentHint:!0,debugging:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"url",type:"string",description:`Request URL path, e.g.
87
87
  "/wp-json/wp/v2/posts" or
88
88
  "/wp-admin/plugins.php"`,required:!0},{name:"method",type:"string",description:`HTTP method (GET, POST, PUT,
89
89
  DELETE, etc.). Defaults to GET.`,required:!1,default:"GET"},{name:"headers",type:"object",description:`Request headers as string key-value
@@ -108,7 +108,7 @@
108
108
  you need version information or the document root
109
109
  path. For just the current URL, prefer
110
110
  playground_get_current_url.`,annotations:{readOnlyHint:!0,destructiveHint:!1,openWorldHint:!0},params:[]},playground_read_file:{title:"Read File",errorPrefix:"Error reading file",description:`Read a file from the WordPress virtual
111
- filesystem. Returns the file contents as text.`,annotations:{readOnlyHint:!0,destructiveHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:`Absolute path to the file, e.g.
111
+ filesystem. Returns the file contents as text.`,annotations:{readOnlyHint:!0,destructiveHint:!1,untrustedContentHint:!0,openWorldHint:!0},params:[{name:"path",type:"string",description:`Absolute path to the file, e.g.
112
112
  "/wordpress/wp-config.php"`,required:!0}]},playground_write_file:{title:"Write File",errorPrefix:"Error writing file",description:`Write content to a file in the WordPress
113
113
  virtual filesystem.
114
114
 
@@ -121,7 +121,7 @@
121
121
  directories are NOT created automatically — call
122
122
  playground_mkdir first if needed, otherwise the
123
123
  write will fail with a "no such file or directory"
124
- error.`,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:`Absolute path to write to, e.g.
124
+ error.`,annotations:{readOnlyHint:!1,destructiveHint:!0,consequentialHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:`Absolute path to write to, e.g.
125
125
  "/wordpress/wp-content/test.txt"`,required:!0},{name:"contents",type:"string",description:"File contents to write",required:!0}]},playground_list_files:{title:"List Files",errorPrefix:"Error listing files",description:`List files and directories at a given path
126
126
  in the WordPress virtual filesystem. Returns a
127
127
  flat, non-recursive listing of the immediate
@@ -139,14 +139,14 @@
139
139
  WARNING: Deletion is permanent and cannot be
140
140
  undone. Returns an error if the file does not
141
141
  exist — use playground_file_exists first if
142
- deletion is conditional.`,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:"Absolute path of file to delete",required:!0}]},playground_delete_directory:{title:"Delete Directory",errorPrefix:"Error deleting directory",description:`Delete a directory from the WordPress
142
+ deletion is conditional.`,annotations:{readOnlyHint:!1,destructiveHint:!0,consequentialHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:"Absolute path of file to delete",required:!0}]},playground_delete_directory:{title:"Delete Directory",errorPrefix:"Error deleting directory",description:`Delete a directory from the WordPress
143
143
  virtual filesystem.
144
144
 
145
145
  WARNING: Deletion is permanent and cannot be
146
146
  undone. By default (recursive=false), the directory
147
147
  must be empty or the call will fail. Set
148
148
  recursive=true to delete a directory and all its
149
- contents — use with care.`,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:"Absolute path of directory to delete",required:!0},{name:"recursive",type:"boolean",description:`If true, delete directory and
149
+ contents — use with care.`,annotations:{readOnlyHint:!1,destructiveHint:!0,consequentialHint:!0,idempotentHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:"Absolute path of directory to delete",required:!0},{name:"recursive",type:"boolean",description:`If true, delete directory and
150
150
  all contents. If false (default), fails
151
151
  on non-empty directories.`,required:!1,default:!1}]},playground_file_exists:{title:"File Exists",errorPrefix:"Error checking file existence",description:`Check whether a file or directory exists
152
152
  in the WordPress virtual filesystem.`,annotations:{readOnlyHint:!0,destructiveHint:!1,openWorldHint:!0},params:[{name:"path",type:"string",description:"Absolute path to check",required:!0}]},playground_list_emails:{title:"List Captured Emails",errorPrefix:"Error listing emails",description:`List every email the WordPress site has sent
@@ -162,7 +162,7 @@
162
162
  contains the from/to/CC addresses, subject, date,
163
163
  text and HTML bodies, and attachment metadata
164
164
  (file name, MIME type, size). Attachment contents
165
- are not included.`,annotations:{readOnlyHint:!0,destructiveHint:!1,openWorldHint:!0},params:[]}};function w(){return{playground_list_sites:{title:"List Available Sites",errorPrefix:"Error listing sites",description:`List all WordPress Playground sites
165
+ are not included.`,annotations:{readOnlyHint:!0,destructiveHint:!1,untrustedContentHint:!0,debugging:!0,openWorldHint:!0},params:[]}};function b(){return{playground_list_sites:{title:"List Available Sites",errorPrefix:"Error listing sites",description:`List all WordPress Playground sites
166
166
  available. Call this before any other playground
167
167
  tool — it returns the siteId required by every
168
168
  other operation.
@@ -196,12 +196,12 @@
196
196
  server. Use this tool whenever you need to send
197
197
  the user to Playground or open it autonomously —
198
198
  always obtain the URL from this tool rather than
199
- constructing it manually.`,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},params:[]}}}function _(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function b(e){return e==="none"?"temporary":e}function P(e){const t={},n=[];for(const r of e){const s={};r.type==="string_or_object"?s.oneOf=[{type:"string"},{type:"object"}]:s.type=r.type,s.description=r.description,r.additionalProperties!==void 0&&(s.additionalProperties=r.additionalProperties),r.default!==void 0&&(s.default=r.default),t[r.name]=s,r.required&&n.push(r.name)}const i={type:"object",properties:t};return n.length>0&&(i.required=n),i}async function v(e){const[t,n]=await Promise.all([e.getCurrentURL(),e.run({code:`<?php
199
+ constructing it manually.`,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},params:[]}}}function P(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function v(e){return e==="none"?"temporary":e}function H(e){const t={},n=[];for(const i of e){const o={};i.type==="string_or_object"?o.oneOf=[{type:"string"},{type:"object"}]:o.type=i.type,o.description=i.description,i.additionalProperties!==void 0&&(o.additionalProperties=i.additionalProperties),i.default!==void 0&&(o.default=i.default),t[i.name]=o,i.required&&n.push(i.name)}const r={type:"object",properties:t,additionalProperties:!1};return n.length>0&&(r.required=n),r}async function x(e){const[t,n]=await Promise.all([e.getCurrentURL(),e.run({code:`<?php
200
200
  require_once "/wordpress/wp-load.php";
201
201
  echo json_encode([
202
202
  "documentRoot" => ABSPATH,
203
203
  "wpVersion" => get_bloginfo("version"),
204
204
  "siteUrl" => get_site_url(),
205
205
  "phpVersion" => phpversion(),
206
- ]);`}).then(r=>r.text)]);let i;try{i=JSON.parse(n)}catch{i={}}return{url:String(t),documentRoot:i.documentRoot??"/wordpress",siteUrl:i.siteUrl??String(t),wpVersion:i.wpVersion??"unknown",phpVersion:i.phpVersion??"unknown"}}const H={playground_execute_php:(e,t)=>e.run({code:t.code}),playground_request:async(e,t)=>{const n=t.url,i=t.method??"GET",r={...t.headers??{}},s=t.body,o=typeof s=="object"&&s!==null?JSON.stringify(s):s;try{const c=new URL(n,"http://localhost"),u=n.includes("/wp-json/")||c.searchParams.has("rest_route");u&&o&&!Object.keys(r).some(a=>a.toLowerCase()==="content-type")&&(r["Content-Type"]="application/json");const h=Object.keys(r).some(a=>a.toLowerCase()==="x-wp-nonce");if(u&&!h){const a=Math.random().toString(36).slice(2,10),p=`/wordpress/wp-content/mcp-nonce-${a}.php`,f=`/wp-content/mcp-nonce-${a}.php`;await e.writeFile(p,"<?php require_once '/wordpress/wp-load.php'; echo wp_create_nonce('wp_rest');");let l="";try{l=(await e.request({url:f,method:"GET"})).text.trim()}finally{await e.unlink(p)}l&&l!=="0"&&(r["X-WP-Nonce"]=l)}}catch{}return await e.request({url:n,method:i,headers:r,body:o})},playground_navigate:async(e,t)=>(await e.goTo(t.path),{url:await e.getCurrentURL()}),playground_get_current_url:async e=>({url:await e.getCurrentURL()}),playground_get_site_info:e=>v(e),playground_read_file:async(e,t)=>({contents:await e.readFileAsText(t.path)}),playground_write_file:async(e,t)=>(await e.writeFile(t.path,t.contents),{success:!0}),playground_list_files:async(e,t)=>({files:await e.listFiles(t.path)}),playground_mkdir:async(e,t)=>(await e.mkdirTree(t.path),{success:!0}),playground_delete_file:async(e,t)=>(await e.unlink(t.path),{success:!0}),playground_delete_directory:async(e,t)=>(await e.rmdir(t.path,{recursive:t.recursive??!1}),{success:!0}),playground_file_exists:async(e,t)=>({exists:await e.fileExists(t.path)}),playground_list_emails:async e=>({emails:await e.listEmails()})};function x(e){const t=new TextDecoder,n={async run(i){const r=await e.run(i);return{text:t.decode(r.bytes),errors:r.errors,exitCode:r.exitCode}},async request(i){const r=await e.request({url:i.url,method:i.method,headers:i.headers,body:i.body});return{text:t.decode(r.bytes),httpStatusCode:r.httpStatusCode,headers:r.headers}},async listEmails(){return(await e.email()).map(T)}};return new Proxy(e,{get:(i,r)=>{const s=n[r];if(s!==void 0)return s;const o=i[r];return typeof o=="function"?o.bind(i):o}})}function T(e){var t,n;return{from:e.from?d(e.from):void 0,to:(t=e.to)==null?void 0:t.map(d),cc:(n=e.cc)==null?void 0:n.map(d),subject:e.subject,date:e.date,text:e.text,html:e.html,attachments:(e.attachments??[]).map(i=>{var r;return{filename:i.filename,mimeType:i.mimeType,size:typeof i.content=="string"?i.content.length:((r=i.content)==null?void 0:r.byteLength)??0}})}}function d(e){return e.group?`${e.name}: ${e.group.map(d).join(", ")};`:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||""}exports.createToolClient=x;exports.formatStorageLabel=b;exports.getSiteToolDefinitions=w;exports.paramsToJsonSchema=P;exports.playgroundUrl=g;exports.stringifyError=_;exports.toolDefinitions=m;exports.toolExecutors=H;
207
- //# sourceMappingURL=tool-executors-BhDxY6BQ.cjs.map
206
+ ]);`}).then(i=>i.text)]);let r;try{r=JSON.parse(n)}catch{r={}}return{url:String(t),documentRoot:r.documentRoot??"/wordpress",siteUrl:r.siteUrl??String(t),wpVersion:r.wpVersion??"unknown",phpVersion:r.phpVersion??"unknown"}}const T={playground_execute_php:(e,t)=>e.run({code:t.code}),playground_request:async(e,t,n)=>{const r=t.url,i=t.method??"GET",o={...t.headers??{}},s=t.body,u=typeof s=="object"&&s!==null?JSON.stringify(s):s;try{const h=new URL(r,"http://localhost"),p=r.includes("/wp-json/")||h.searchParams.has("rest_route");p&&u&&!Object.keys(o).some(a=>a.toLowerCase()==="content-type")&&(o["Content-Type"]="application/json");const f=Object.keys(o).some(a=>a.toLowerCase()==="x-wp-nonce");if(p&&!f){const a=Math.random().toString(36).slice(2,10),c=`/wordpress/wp-content/mcp-nonce-${a}.php`,y=`/wp-content/mcp-nonce-${a}.php`,g="<?php require_once '/wordpress/wp-load.php'; echo wp_create_nonce('wp_rest');";n==null||n.throwIfAborted(),await e.writeFile(c,g);let l="";try{n==null||n.throwIfAborted(),l=(await e.request({url:y,method:"GET"})).text.trim()}finally{await e.unlink(c)}l&&l!=="0"&&(o["X-WP-Nonce"]=l)}}catch{}return n==null||n.throwIfAborted(),await e.request({url:r,method:i,headers:o,body:u})},playground_navigate:async(e,t)=>(await e.goTo(t.path),{url:await e.getCurrentURL()}),playground_get_current_url:async e=>({url:await e.getCurrentURL()}),playground_get_site_info:e=>x(e),playground_read_file:async(e,t)=>({contents:await e.readFileAsText(t.path)}),playground_write_file:async(e,t)=>(await e.writeFile(t.path,t.contents),{success:!0}),playground_list_files:async(e,t)=>({files:await e.listFiles(t.path)}),playground_mkdir:async(e,t)=>(await e.mkdirTree(t.path),{success:!0}),playground_delete_file:async(e,t)=>(await e.unlink(t.path),{success:!0}),playground_delete_directory:async(e,t)=>(await e.rmdir(t.path,{recursive:t.recursive??!1}),{success:!0}),playground_file_exists:async(e,t)=>({exists:await e.fileExists(t.path)}),playground_list_emails:async e=>({emails:await e.listEmails()})};function E(e){const t=new TextDecoder,n={async run(r){const i=await e.run(r);return{text:t.decode(i.bytes),errors:i.errors,exitCode:i.exitCode}},async request(r){const i=await e.request({url:r.url,method:r.method,headers:r.headers,body:r.body});return{text:t.decode(i.bytes),httpStatusCode:i.httpStatusCode,headers:i.headers}},async listEmails(){return(await e.email()).map(R)}};return new Proxy(e,{get:(r,i)=>{const o=n[i];if(o!==void 0)return o;const s=r[i];return typeof s=="function"?s.bind(r):s}})}function R(e){var t,n;return{from:e.from?d(e.from):void 0,to:(t=e.to)==null?void 0:t.map(d),cc:(n=e.cc)==null?void 0:n.map(d),subject:e.subject,date:e.date,text:e.text,html:e.html,attachments:(e.attachments??[]).map(r=>{var i;return{filename:r.filename,mimeType:r.mimeType,size:typeof r.content=="string"?r.content.length:((i=r.content)==null?void 0:i.byteLength)??0}})}}function d(e){return e.group?`${e.name}: ${e.group.map(d).join(", ")};`:e.name&&e.address?`${e.name} <${e.address}>`:e.address||e.name||""}exports.createToolClient=E;exports.formatStorageLabel=v;exports.getSiteToolDefinitions=b;exports.paramsToJsonSchema=H;exports.playgroundUrl=w;exports.stringifyError=P;exports.toolDefinitions=_;exports.toolExecutors=T;
207
+ //# sourceMappingURL=tool-executors-CkOyDA_-.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-executors-CkOyDA_-.cjs","sources":["../../../../packages/playground/mcp/src/tools/tool-definitions.ts","../../../../packages/playground/mcp/src/tools/tool-executors.ts"],"sourcesContent":["/**\n * Tool metadata and schema helpers for WordPress Playground.\n *\n * Pure data — no execution logic. Both the MCP server and\n * WebMCP import these for consistent descriptions, annotations,\n * and schema conversion.\n */\n\nexport interface ToolAnnotations {\n\treadOnlyHint?: boolean;\n\tdestructiveHint?: boolean;\n\tidempotentHint?: boolean;\n\topenWorldHint?: boolean;\n\tconsequentialHint?: boolean;\n\tuntrustedContentHint?: boolean;\n\tdebugging?: boolean;\n}\n\nexport type ToolParamType =\n\t| 'string'\n\t| 'boolean'\n\t| 'object'\n\t| 'string_or_object';\n\nexport interface ToolParam {\n\tname: string;\n\ttype: ToolParamType;\n\tdescription: string;\n\trequired: boolean;\n\tadditionalProperties?: boolean;\n\tdefault?: unknown;\n}\n\nexport interface ToolDefinition {\n\ttitle: string;\n\tdescription: string;\n\terrorPrefix: string;\n\tannotations: ToolAnnotations;\n\tparams: ToolParam[];\n}\n\nconst PLAYGROUND_BASE_URL = 'https://playground.wordpress.net/';\n\nexport function playgroundUrl(port: number, baseUrl?: string): string {\n\tif (!baseUrl) {\n\t\treturn `${PLAYGROUND_BASE_URL}?mcp-port=${port}`;\n\t}\n\tconst url = new URL(baseUrl);\n\turl.searchParams.set('mcp-port', String(port));\n\treturn url.toString();\n}\n\n// -- Per-site tool definitions --\n\nexport const toolDefinitions: Record<string, ToolDefinition> = {\n\tplayground_execute_php: {\n\t\ttitle: 'Execute PHP Code',\n\t\terrorPrefix: 'Error executing PHP',\n\t\tdescription: `Run arbitrary PHP code in WordPress Playground\n\t\t\tand return the output.\n\n\t\t\tWordPress is NOT bootstrapped automatically. To use\n\t\t\tWordPress functions, start your code with:\n\t\t\trequire(\"/wordpress/wp-load.php\");\n\t\t\tAlways include the opening <?php tag.\n\n\t\t\tThe response JSON contains three fields:\n\t\t\t- \"text\": stdout output\n\t\t\t- \"errors\": PHP warnings, notices, and fatal error\n\t\t\t messages from stderr\n\t\t\t- \"exitCode\": 0 on success, non-zero on fatal error\n\t\t\tCheck both \"errors\" and \"exitCode\" to determine\n\t\t\twhether the call succeeded.\n\n\t\t\tWARNING: output is returned in full with no\n\t\t\ttruncation — avoid queries that produce unbounded\n\t\t\toutput (e.g. SELECT * without LIMIT). Keep output\n\t\t\tunder 50 KB to avoid filling the context window.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tconsequentialHint: true,\n\t\t\tdebugging: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'code',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `PHP code to execute. Example:\n\t\t\t\t\t\"<?php echo get_bloginfo('name');\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_request: {\n\t\ttitle: 'HTTP Request',\n\t\terrorPrefix: 'Error making request',\n\t\tdescription: `Make an HTTP request to the WordPress site\n\t\t\trunning in Playground. REST API requests\n\t\t\t(/wp-json/* or ?rest_route=) are automatically\n\t\t\tauthenticated with a valid nonce — no manual\n\t\t\tauth needed.\n\n\t\t\tTool selection guide:\n\t\t\t1. Use this tool (playground_request) with the\n\t\t\t REST API for standard content CRUD — posts,\n\t\t\t pages, users, terms, comments, settings, etc.\n\t\t\t The REST API handles serialization, pagination,\n\t\t\t and field filtering for you. Prefer compact\n\t\t\t REST responses: use _fields to request only the\n\t\t\t fields needed and per_page/page for large\n\t\t\t collections. Before using endpoint-specific\n\t\t\t filters, inspect the route metadata from\n\t\t\t /wp-json/ and use only args documented for that\n\t\t\t route.\n\t\t\t2. Use this tool with the WordPress REST API to\n\t\t\t discover and call registered abilities when the\n\t\t\t site exposes the Abilities API:\n\t\t\t - GET /wp-json/wp-abilities/v1/abilities\n\t\t\t lists registered abilities. Always assume this\n\t\t\t response may be large and start with _fields,\n\t\t\t e.g.\n\t\t\t /wp-json/wp-abilities/v1/abilities?_fields=name,category,label,description\n\t\t\t Do not assume filters like search or category\n\t\t\t exist unless /wp-json/ route metadata documents\n\t\t\t them.\n\t\t\t - GET /wp-json/wp-abilities/v1/abilities/{name}\n\t\t\t gets one ability, including schemas and\n\t\t\t metadata. Ability names include \"/\" in the\n\t\t\t path; do not encode it. For example, use\n\t\t\t /wp-json/wp-abilities/v1/abilities/memex/save-note\n\t\t\t for \"memex/save-note\".\n\t\t\t - GET, POST, or DELETE\n\t\t\t /wp-json/wp-abilities/v1/abilities/{name}/run\n\t\t\t executes the ability. Inspect the ability\n\t\t\t metadata first, then call /run with the\n\t\t\t documented method. POST bodies usually wrap\n\t\t\t arguments in an \"input\" object, e.g.\n\t\t\t {\"input\":{\"title\":\"Hello\"}}.\n\t\t\t - GET /wp-json/wp-abilities/v1/categories\n\t\t\t lists ability categories. Each category includes\n\t\t\t _links.abilities; follow that URL to list\n\t\t\t abilities in that category. The abilities\n\t\t\t collection can also be filtered directly with\n\t\t\t /wp-json/wp-abilities/v1/abilities?category={slug}.\n\t\t\t3. Use playground_execute_php when the data you\n\t\t\t need is not exposed by the REST API (e.g.\n\t\t\t raw options, direct database queries, or\n\t\t\t custom table access).\n\t\t\t4. Use this tool as a plain HTTP request (non-REST)\n\t\t\t when the HTTP layer itself matters: verifying\n\t\t\t redirects, status codes, cookies, or response\n\t\t\t headers.\n\n\t\t\tThe response JSON contains three fields:\n\t\t\t- \"text\": the response body as a string\n\t\t\t- \"httpStatusCode\": HTTP status code (200, 404…)\n\t\t\t- \"headers\": response headers as key-value pairs\n\t\t\tCheck \"httpStatusCode\" to determine success.\n\n\t\t\tNote: full HTML responses can be very large and may\n\t\t\tfill the context window. To change the URL the user\n\t\t\tsees in their tab, use playground_navigate instead.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tconsequentialHint: true,\n\t\t\tuntrustedContentHint: true,\n\t\t\tdebugging: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'url',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `Request URL path, e.g.\n\t\t\t\t\t\"/wp-json/wp/v2/posts\" or\n\t\t\t\t\t\"/wp-admin/plugins.php\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'method',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `HTTP method (GET, POST, PUT,\n\t\t\t\t\tDELETE, etc.). Defaults to GET.`,\n\t\t\t\trequired: false,\n\t\t\t\tdefault: 'GET',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'headers',\n\t\t\t\ttype: 'object',\n\t\t\t\tdescription: `Request headers as string key-value\n\t\t\t\t\tpairs, e.g. {\"Content-Type\":\n\t\t\t\t\t\"application/json\"}`,\n\t\t\t\trequired: false,\n\t\t\t\tadditionalProperties: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'body',\n\t\t\t\ttype: 'string_or_object',\n\t\t\t\tdescription: `Request body (for POST/PUT requests).\n\t\t\t\t\tAccepts a JSON string or an object.`,\n\t\t\t\trequired: false,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_navigate: {\n\t\ttitle: 'Navigate to URL',\n\t\terrorPrefix: 'Error navigating',\n\t\tdescription: `Navigate to a URL path in WordPress\n\t\t\tPlayground and return the final URL after any\n\t\t\tredirects. Examples: \"/wp-admin/\",\n\t\t\t\"/wp-login.php\", \"/\".\n\n\t\t\tOn 404 or error pages, navigation still succeeds\n\t\t\tfrom the tool's perspective — check the returned\n\t\t\tURL or use playground_request to verify the HTTP\n\t\t\tstatus code if needed.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `The URL path to navigate to,\n\t\t\t\t\te.g. \"/wp-admin/\" or\n\t\t\t\t\t\"/wp-login.php\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_get_current_url: {\n\t\ttitle: 'Get Current URL',\n\t\terrorPrefix: 'Error getting current URL',\n\t\tdescription: `Get the current URL path of the WordPress\n\t\t\tsite displayed in Playground. For additional\n\t\t\tmetadata (WordPress version, PHP version, document\n\t\t\troot), use playground_get_site_info instead.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [],\n\t},\n\tplayground_get_site_info: {\n\t\ttitle: 'Get Site Info',\n\t\terrorPrefix: 'Error getting site info',\n\t\tdescription: `Get metadata about the running WordPress\n\t\t\tinstance: current URL, document root, site URL,\n\t\t\tWordPress version, and PHP version. Use this when\n\t\t\tyou need version information or the document root\n\t\t\tpath. For just the current URL, prefer\n\t\t\tplayground_get_current_url.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [],\n\t},\n\tplayground_read_file: {\n\t\ttitle: 'Read File',\n\t\terrorPrefix: 'Error reading file',\n\t\tdescription: `Read a file from the WordPress virtual\n\t\t\tfilesystem. Returns the file contents as text.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tuntrustedContentHint: true,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `Absolute path to the file, e.g.\n\t\t\t\t\t\"/wordpress/wp-config.php\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_write_file: {\n\t\ttitle: 'Write File',\n\t\terrorPrefix: 'Error writing file',\n\t\tdescription: `Write content to a file in the WordPress\n\t\t\tvirtual filesystem.\n\n\t\t\tWARNING: Overwrites the entire file — existing\n\t\t\tcontent is permanently lost. Read the file first\n\t\t\twith playground_read_file if you need to preserve\n\t\t\tany content.\n\n\t\t\tCreates the file if it does not exist. Parent\n\t\t\tdirectories are NOT created automatically — call\n\t\t\tplayground_mkdir first if needed, otherwise the\n\t\t\twrite will fail with a \"no such file or directory\"\n\t\t\terror.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tconsequentialHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `Absolute path to write to, e.g.\n\t\t\t\t\t\"/wordpress/wp-content/test.txt\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'contents',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'File contents to write',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_list_files: {\n\t\ttitle: 'List Files',\n\t\terrorPrefix: 'Error listing files',\n\t\tdescription: `List files and directories at a given path\n\t\t\tin the WordPress virtual filesystem. Returns a\n\t\t\tflat, non-recursive listing of the immediate\n\t\t\tcontents. To explore subdirectories, call this tool\n\t\t\tagain with the subdirectory path.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `Absolute path to list, e.g.\n\t\t\t\t\t\"/wordpress/wp-content/plugins\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_mkdir: {\n\t\ttitle: 'Create Directory',\n\t\terrorPrefix: 'Error creating directory',\n\t\tdescription: `Create a directory (and all required parent\n\t\t\tdirectories) in the WordPress virtual filesystem.\n\t\t\tCall this before playground_write_file when writing\n\t\t\tto a path whose parent directories do not yet\n\t\t\texist.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: false,\n\t\t\tidempotentHint: true,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: `Absolute path of directory to\n\t\t\t\t\tcreate, e.g.\n\t\t\t\t\t\"/wordpress/wp-content/my-plugin\"`,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_delete_file: {\n\t\ttitle: 'Delete File',\n\t\terrorPrefix: 'Error deleting file',\n\t\tdescription: `Delete a file from the WordPress virtual\n\t\t\tfilesystem.\n\n\t\t\tWARNING: Deletion is permanent and cannot be\n\t\t\tundone. Returns an error if the file does not\n\t\t\texist — use playground_file_exists first if\n\t\t\tdeletion is conditional.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tconsequentialHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Absolute path of file to delete',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_delete_directory: {\n\t\ttitle: 'Delete Directory',\n\t\terrorPrefix: 'Error deleting directory',\n\t\tdescription: `Delete a directory from the WordPress\n\t\t\tvirtual filesystem.\n\n\t\t\tWARNING: Deletion is permanent and cannot be\n\t\t\tundone. By default (recursive=false), the directory\n\t\t\tmust be empty or the call will fail. Set\n\t\t\trecursive=true to delete a directory and all its\n\t\t\tcontents — use with care.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: false,\n\t\t\tdestructiveHint: true,\n\t\t\tconsequentialHint: true,\n\t\t\tidempotentHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Absolute path of directory to delete',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'recursive',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: `If true, delete directory and\n\t\t\t\t\tall contents. If false (default), fails\n\t\t\t\t\ton non-empty directories.`,\n\t\t\t\trequired: false,\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_file_exists: {\n\t\ttitle: 'File Exists',\n\t\terrorPrefix: 'Error checking file existence',\n\t\tdescription: `Check whether a file or directory exists\n\t\t\tin the WordPress virtual filesystem.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [\n\t\t\t{\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdescription: 'Absolute path to check',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t},\n\tplayground_list_emails: {\n\t\ttitle: 'List Captured Emails',\n\t\terrorPrefix: 'Error listing emails',\n\t\tdescription: `List every email the WordPress site has sent\n\t\t\tso far. Playground has no mail server. Each\n\t\t\tmessage WordPress attempts to send (password\n\t\t\tresets, comment notifications, wp_mail() calls…)\n\t\t\tis captured instead of being delivered. Use this\n\t\t\ttool to read those messages, e.g. to verify that\n\t\t\ta plugin sent an email or to retrieve a\n\t\t\tconfirmation link.\n\n\t\t\tReturns the full inbox in send order. Each entry\n\t\t\tcontains the from/to/CC addresses, subject, date,\n\t\t\ttext and HTML bodies, and attachment metadata\n\t\t\t(file name, MIME type, size). Attachment contents\n\t\t\tare not included.`,\n\t\tannotations: {\n\t\t\treadOnlyHint: true,\n\t\t\tdestructiveHint: false,\n\t\t\tuntrustedContentHint: true,\n\t\t\tdebugging: true,\n\t\t\topenWorldHint: true,\n\t\t},\n\t\tparams: [],\n\t},\n};\n\n// -- Site management tool definitions --\n\nexport function getSiteToolDefinitions(): Record<string, ToolDefinition> {\n\treturn {\n\t\tplayground_list_sites: {\n\t\t\ttitle: 'List Available Sites',\n\t\t\terrorPrefix: 'Error listing sites',\n\t\t\tdescription: `List all WordPress Playground sites\n\t\t\tavailable. Call this before any other playground\n\t\t\ttool — it returns the siteId required by every\n\t\t\tother operation.\n\n\t\t\tIf this returns no sites, the user may need to\n\t\t\topen Playground in their browser. Use\n\t\t\tplayground_get_website_url to get the exact URL\n\t\t\tto send to the user.\n\n\t\t\tReturns site names and storage type. \"temporary\"\n\t\t\tsites are lost on page reload, \"opfs\" sites persist\n\t\t\tacross reloads. Call playground_save_in_browser to persist\n\t\t\ta temporary site.`,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t\tdestructiveHint: false,\n\t\t\t},\n\t\t\tparams: [],\n\t\t},\n\t\tplayground_open_site_in_new_tab: {\n\t\t\ttitle: 'Open Site in New Tab',\n\t\t\terrorPrefix: 'Error opening site in new tab',\n\t\t\tdescription: `Open a WordPress Playground site in a new\n\t\t\tbrowser tab. The site must appear in\n\t\t\tplayground_list_sites.\n\n\t\t\tCheck playground_get_current_url first — if the\n\t\t\tsite is already open in a tab, calling this tool\n\t\t\twill open a second tab rather than switching to\n\t\t\tthe existing one.`,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t},\n\t\t\tparams: [],\n\t\t},\n\t\tplayground_rename_site: {\n\t\t\ttitle: 'Rename Site',\n\t\t\terrorPrefix: 'Error renaming site',\n\t\t\tdescription: `Rename a WordPress Playground site. Updates\n\t\t\tthe display name shown in the browser UI.`,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: 'newName',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdescription: 'The new display name for the site',\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tplayground_save_in_browser: {\n\t\t\ttitle: 'Save in Browser',\n\t\t\terrorPrefix: 'Error saving site',\n\t\t\tdescription: `Save a temporary WordPress Playground site\n\t\t\tto browser storage so it survives page reloads.\n\t\t\tSafe to call even if the site is already saved\n\t\t\t(no-op).\n\n\t\t\tSites start as temporary by default and are lost\n\t\t\twhen the browser tab is closed or the page is\n\t\t\treloaded. Call this early in any multi-step\n\t\t\tworkflow where losing progress would be costly.`,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t},\n\t\t\tparams: [],\n\t\t},\n\t\tplayground_get_website_url: {\n\t\t\ttitle: 'Get Playground Website URL',\n\t\t\terrorPrefix: 'Error getting website URL',\n\t\t\tdescription: `Return the URL the user must open in their\n\t\t\tbrowser to use WordPress Playground with this MCP\n\t\t\tserver. Use this tool whenever you need to send\n\t\t\tthe user to Playground or open it autonomously —\n\t\t\talways obtain the URL from this tool rather than\n\t\t\tconstructing it manually.`,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: true,\n\t\t\t\topenWorldHint: false,\n\t\t\t},\n\t\t\tparams: [],\n\t\t},\n\t};\n}\n\nexport function stringifyError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\tif (typeof error === 'string') {\n\t\treturn error;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n\n/**\n * Translate internal Playground storage types to user-facing names.\n */\nexport function formatStorageLabel(raw: string): string {\n\treturn raw === 'none' ? 'temporary' : raw;\n}\n\n/**\n * Convert ToolParam[] to a plain JSON Schema object.\n * Used by WebMCP which expects raw JSON Schema (not Zod).\n */\nexport function paramsToJsonSchema(\n\tparams: ToolParam[]\n): Record<string, unknown> {\n\tconst properties: Record<string, Record<string, unknown>> = {};\n\tconst required: string[] = [];\n\n\tfor (const param of params) {\n\t\tconst prop: Record<string, unknown> = {};\n\t\tif (param.type === 'string_or_object') {\n\t\t\tprop['oneOf'] = [{ type: 'string' }, { type: 'object' }];\n\t\t} else {\n\t\t\tprop['type'] = param.type;\n\t\t}\n\t\tprop['description'] = param.description;\n\t\tif (param.additionalProperties !== undefined) {\n\t\t\tprop['additionalProperties'] = param.additionalProperties;\n\t\t}\n\t\tif (param.default !== undefined) {\n\t\t\tprop['default'] = param.default;\n\t\t}\n\t\tproperties[param.name] = prop;\n\t\tif (param.required) {\n\t\t\trequired.push(param.name);\n\t\t}\n\t}\n\n\tconst schema: Record<string, unknown> = {\n\t\ttype: 'object',\n\t\tproperties,\n\t\tadditionalProperties: false,\n\t};\n\tif (required.length > 0) {\n\t\tschema['required'] = required;\n\t}\n\treturn schema;\n}\n","/**\n * Shared tool executor functions.\n *\n * Both the MCP server and WebMCP call these executors so that tool\n * output shapes are defined in exactly one place. Each transport\n * provides its own ToolClient implementation that normalises I/O\n * differences (e.g. byte decoding).\n */\n\nimport type { PlaygroundClient } from '@wp-playground/remote';\nimport type { PHPRequest } from '@php-wasm/universal';\nimport type { Address, Email } from 'postal-mime';\n\n/**\n * Minimal client interface consumed by tool executors.\n *\n * - WebMCP implements this by wrapping PlaygroundClient (decoding\n * response bytes via TextDecoder).\n * - The MCP server implements this by wrapping bridge.sendCommand\n * (bytes are already decoded at the bridge-client boundary).\n */\nexport interface ToolClient {\n\trun(options: {\n\t\tcode: string;\n\t}): Promise<{ text: string; errors: string; exitCode: number }>;\n\trequest(options: {\n\t\turl: string;\n\t\tmethod: string;\n\t\theaders?: Record<string, string>;\n\t\tbody?: string;\n\t}): Promise<{\n\t\ttext: string;\n\t\thttpStatusCode: number;\n\t\theaders: Record<string, string[]>;\n\t}>;\n\tgoTo(path: string): Promise<void>;\n\tgetCurrentURL(): Promise<string>;\n\treadFileAsText(path: string): Promise<string>;\n\twriteFile(path: string, contents: string): Promise<void>;\n\tlistFiles(path: string): Promise<string[]>;\n\tmkdirTree(path: string): Promise<void>;\n\tunlink(path: string): Promise<void>;\n\trmdir(path: string, options: { recursive: boolean }): Promise<void>;\n\tfileExists(path: string): Promise<boolean>;\n\tlistEmails(): Promise<EmailSummary[]>;\n}\n\n/**\n * JSON-serializable view of a captured email. Attachment contents are\n * dropped on purpose: they may be megabytes of binary data and would not\n * survive the JSON transport between the browser and the MCP server.\n */\nexport interface EmailSummary {\n\tfrom?: string;\n\tto?: string[];\n\tcc?: string[];\n\tsubject?: string;\n\tdate?: string;\n\ttext?: string;\n\thtml?: string;\n\tattachments: Array<{\n\t\tfilename: string | null;\n\t\tmimeType: string;\n\t\tsize: number;\n\t}>;\n}\n\nexport interface SiteInfo {\n\turl: string;\n\tdocumentRoot: string;\n\tsiteUrl: string;\n\twpVersion: string;\n\tphpVersion: string;\n}\n\nasync function executeSiteInfo(client: ToolClient): Promise<SiteInfo> {\n\tconst [url, infoText] = await Promise.all([\n\t\tclient.getCurrentURL(),\n\t\tclient\n\t\t\t.run({\n\t\t\t\tcode: `<?php\n\t\t\trequire_once \"/wordpress/wp-load.php\";\n\t\t\techo json_encode([\n\t\t\t\t\"documentRoot\" => ABSPATH,\n\t\t\t\t\"wpVersion\" => get_bloginfo(\"version\"),\n\t\t\t\t\"siteUrl\" => get_site_url(),\n\t\t\t\t\"phpVersion\" => phpversion(),\n\t\t\t]);`,\n\t\t\t})\n\t\t\t.then((resp) => resp.text),\n\t]);\n\n\tlet info: Partial<Omit<SiteInfo, 'url'>>;\n\ttry {\n\t\tinfo = JSON.parse(infoText);\n\t} catch {\n\t\tinfo = {};\n\t}\n\n\treturn {\n\t\turl: String(url),\n\t\tdocumentRoot: info.documentRoot ?? '/wordpress',\n\t\tsiteUrl: info.siteUrl ?? String(url),\n\t\twpVersion: info.wpVersion ?? 'unknown',\n\t\tphpVersion: info.phpVersion ?? 'unknown',\n\t};\n}\n\nexport const toolExecutors: Record<\n\tstring,\n\t(\n\t\tclient: ToolClient,\n\t\tinput: Record<string, unknown>,\n\t\tsignal?: AbortSignal\n\t) => Promise<unknown>\n> = {\n\tplayground_execute_php: (client, input) =>\n\t\tclient.run({ code: input['code'] as string }),\n\n\tplayground_request: async (client, input, signal) => {\n\t\tconst url = input['url'] as string;\n\t\tconst method = (input['method'] as string) ?? 'GET';\n\t\tconst headers = {\n\t\t\t...((input['headers'] as Record<string, string>) ?? {}),\n\t\t};\n\t\tconst rawBody = input['body'];\n\t\tconst body =\n\t\t\ttypeof rawBody === 'object' && rawBody !== null\n\t\t\t\t? JSON.stringify(rawBody)\n\t\t\t\t: (rawBody as string | undefined);\n\n\t\ttry {\n\t\t\tconst parsedUrl = new URL(url, 'http://localhost');\n\t\t\tconst isRestApi =\n\t\t\t\turl.includes('/wp-json/') ||\n\t\t\t\tparsedUrl.searchParams.has('rest_route');\n\n\t\t\t// Auto-set Content-Type for REST API JSON bodies.\n\t\t\tif (\n\t\t\t\tisRestApi &&\n\t\t\t\tbody &&\n\t\t\t\t!Object.keys(headers).some(\n\t\t\t\t\t(k) => k.toLowerCase() === 'content-type'\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\theaders['Content-Type'] = 'application/json';\n\t\t\t}\n\n\t\t\tconst hasNonce = Object.keys(headers).some(\n\t\t\t\t(k) => k.toLowerCase() === 'x-wp-nonce'\n\t\t\t);\n\n\t\t\tif (isRestApi && !hasNonce) {\n\t\t\t\t// Generate the nonce via a temporary PHP file requested\n\t\t\t\t// through request() — not run() — so that the cookie\n\t\t\t\t// store is included and WordPress ties the nonce to\n\t\t\t\t// the logged-in user.\n\t\t\t\tconst nonceId = Math.random().toString(36).slice(2, 10);\n\t\t\t\tconst noncePath = `/wordpress/wp-content/mcp-nonce-${nonceId}.php`;\n\t\t\t\tconst nonceUrl = `/wp-content/mcp-nonce-${nonceId}.php`;\n\t\t\t\tconst nonceCode =\n\t\t\t\t\t\"<?php require_once '/wordpress/wp-load.php'; echo wp_create_nonce('wp_rest');\";\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tawait client.writeFile(noncePath, nonceCode);\n\t\t\t\tlet nonce = '';\n\t\t\t\ttry {\n\t\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\t\tconst nonceResp = await client.request({\n\t\t\t\t\t\turl: nonceUrl,\n\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t});\n\t\t\t\t\tnonce = nonceResp.text.trim();\n\t\t\t\t} finally {\n\t\t\t\t\tawait client.unlink(noncePath);\n\t\t\t\t}\n\t\t\t\tif (nonce && nonce !== '0') {\n\t\t\t\t\theaders['X-WP-Nonce'] = nonce;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Nonce generation failed — proceed without it.\n\t\t}\n\n\t\t// PHP requests already running cannot be interrupted. Stop before the\n\t\t// requested mutation if cancellation arrived during nonce preparation.\n\t\tsignal?.throwIfAborted();\n\t\treturn await client.request({ url, method, headers, body });\n\t},\n\n\tplayground_navigate: async (client, input) => {\n\t\tawait client.goTo(input['path'] as string);\n\t\treturn { url: await client.getCurrentURL() };\n\t},\n\n\tplayground_get_current_url: async (client) => ({\n\t\turl: await client.getCurrentURL(),\n\t}),\n\n\tplayground_get_site_info: (client): Promise<SiteInfo> =>\n\t\texecuteSiteInfo(client),\n\n\tplayground_read_file: async (client, input) => ({\n\t\tcontents: await client.readFileAsText(input['path'] as string),\n\t}),\n\n\tplayground_write_file: async (client, input) => {\n\t\tawait client.writeFile(\n\t\t\tinput['path'] as string,\n\t\t\tinput['contents'] as string\n\t\t);\n\t\treturn { success: true };\n\t},\n\n\tplayground_list_files: async (client, input) => ({\n\t\tfiles: await client.listFiles(input['path'] as string),\n\t}),\n\n\tplayground_mkdir: async (client, input) => {\n\t\tawait client.mkdirTree(input['path'] as string);\n\t\treturn { success: true };\n\t},\n\n\tplayground_delete_file: async (client, input) => {\n\t\tawait client.unlink(input['path'] as string);\n\t\treturn { success: true };\n\t},\n\n\tplayground_delete_directory: async (client, input) => {\n\t\tawait client.rmdir(input['path'] as string, {\n\t\t\trecursive: (input['recursive'] as boolean) ?? false,\n\t\t});\n\t\treturn { success: true };\n\t},\n\n\tplayground_file_exists: async (client, input) => ({\n\t\texists: await client.fileExists(input['path'] as string),\n\t}),\n\n\tplayground_list_emails: async (client) => ({\n\t\temails: await client.listEmails(),\n\t}),\n};\n\n/**\n * Wrap a PlaygroundClient as a ToolClient.\n *\n * Most methods pass through directly. `run` and `request` are\n * intercepted to decode PHP/HTTP response bytes into plain strings\n * via TextDecoder, and `listEmails` condenses the captured emails\n * into JSON-serializable summaries.\n */\nexport function createToolClient(client: PlaygroundClient): ToolClient {\n\tconst decoder = new TextDecoder();\n\tconst overrides: Partial<ToolClient> = {\n\t\tasync run(options) {\n\t\t\tconst resp = await client.run(options);\n\t\t\treturn {\n\t\t\t\ttext: decoder.decode(resp.bytes),\n\t\t\t\terrors: resp.errors,\n\t\t\t\texitCode: resp.exitCode,\n\t\t\t};\n\t\t},\n\t\tasync request(options) {\n\t\t\tconst resp = await client.request({\n\t\t\t\turl: options.url,\n\t\t\t\tmethod: options.method as PHPRequest['method'],\n\t\t\t\theaders: options.headers,\n\t\t\t\tbody: options.body,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\ttext: decoder.decode(resp.bytes),\n\t\t\t\thttpStatusCode: resp.httpStatusCode,\n\t\t\t\theaders: resp.headers,\n\t\t\t};\n\t\t},\n\t\tasync listEmails() {\n\t\t\tconst emails = await client.email();\n\t\t\treturn emails.map(summarizeEmail);\n\t\t},\n\t};\n\treturn new Proxy(client as unknown as ToolClient, {\n\t\tget: (target, prop: string) => {\n\t\t\tconst override = (overrides as Record<string, unknown>)[prop];\n\t\t\tif (override !== undefined) {\n\t\t\t\treturn override;\n\t\t\t}\n\t\t\tconst val = (target as unknown as Record<string, unknown>)[prop];\n\t\t\treturn typeof val === 'function' ? val.bind(target) : val;\n\t\t},\n\t});\n}\n\nfunction summarizeEmail(email: Email): EmailSummary {\n\treturn {\n\t\tfrom: email.from ? formatAddress(email.from) : undefined,\n\t\tto: email.to?.map(formatAddress),\n\t\tcc: email.cc?.map(formatAddress),\n\t\tsubject: email.subject,\n\t\tdate: email.date,\n\t\ttext: email.text,\n\t\thtml: email.html,\n\t\tattachments: (email.attachments ?? []).map((attachment) => ({\n\t\t\tfilename: attachment.filename,\n\t\t\tmimeType: attachment.mimeType,\n\t\t\tsize:\n\t\t\t\ttypeof attachment.content === 'string'\n\t\t\t\t\t? attachment.content.length\n\t\t\t\t\t: (attachment.content?.byteLength ?? 0),\n\t\t})),\n\t};\n}\n\nfunction formatAddress(address: Address): string {\n\tif (address.group) {\n\t\treturn `${address.name}: ${address.group\n\t\t\t.map(formatAddress)\n\t\t\t.join(', ')};`;\n\t}\n\tif (address.name && address.address) {\n\t\treturn `${address.name} <${address.address}>`;\n\t}\n\treturn address.address || address.name || '';\n}\n"],"names":["PLAYGROUND_BASE_URL","playgroundUrl","port","baseUrl","url","toolDefinitions","getSiteToolDefinitions","stringifyError","error","formatStorageLabel","raw","paramsToJsonSchema","params","properties","required","param","prop","schema","executeSiteInfo","client","infoText","resp","info","toolExecutors","input","signal","method","headers","rawBody","body","parsedUrl","isRestApi","k","hasNonce","nonceId","noncePath","nonceUrl","nonceCode","nonce","createToolClient","decoder","overrides","options","summarizeEmail","target","override","val","email","formatAddress","_a","_b","attachment","address"],"mappings":"aAyCA,MAAMA,EAAsB,oC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