@f2c/mcp 0.1.2 → 0.2.0
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/LICENSE +21 -0
- package/README.md +16 -3
- package/dist/cli.js +7 -7
- package/dist/cli.mjs +7 -7
- package/dist/stdio.js +7 -7
- package/dist/stdio.mjs +7 -7
- package/dist/{streamableHttp.js → streamable-http.js} +12 -12
- package/dist/{streamableHttp.mjs → streamable-http.mjs} +12 -12
- package/package.json +9 -8
- /package/dist/{streamableHttp.d.mts → streamable-http.d.mts} +0 -0
- /package/dist/{streamableHttp.d.ts → streamable-http.d.ts} +0 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 f2c-ai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
# F2C MCP Server
|
1
|
+
# F2C MCP Server
|
2
|
+

|
3
|
+
[](https://smithery.ai/server/@f2c-ai/f2c-mcp)
|
2
4
|
[![npm version][npm-version-src]][npm-version-href]
|
3
5
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
4
6
|
[![github][github-src]][github-href]
|
5
7
|
[![node][node-src]][node-href]
|
6
8
|
|
9
|
+
|
7
10
|
[npm-version-src]: https://img.shields.io/npm/v/@f2c/mcp?style=flat&colorA=18181B&colorB=F0DB4F
|
8
11
|
[npm-version-href]: https://npmjs.com/package/@f2c/mcp
|
9
12
|
[npm-downloads-src]: https://img.shields.io/npm/dm/@f2c/mcp?style=flat&colorA=18181B&colorB=F0DB4F
|
@@ -13,15 +16,24 @@
|
|
13
16
|
[node-src]: https://img.shields.io/node/v/@f2c/mcp?style=flat&colorA=18181B&colorB=F0DB4F
|
14
17
|
[node-href]: https://nodejs.org/en/about/previous-releases
|
15
18
|
|
16
|
-
English | [简体中文](./README-zh-CN.md)
|
19
|
+
English | [简体中文](./README-zh-CN.md)
|
20
|
+
|
21
|
+
A Model Context Protocol server for Figma Design to Code using [F2C](https://f2c.yy.com/).
|
22
|
+
|
23
|
+
<a href="https://glama.ai/mcp/servers/@f2c-ai/f2c-mcp">
|
24
|
+
<img width="380" height="200" src="https://glama.ai/mcp/servers/@f2c-ai/f2c-mcp/badge" alt="f2c-mcp-server MCP server" />
|
25
|
+
</a>
|
17
26
|
|
18
|
-
|
27
|
+
## Features
|
28
|
+
<img alt="f2c" src="https://raw.githubusercontent.com/f2c-ai/f2c-mcp/main/docs/bannerv3.png" />
|
19
29
|
|
20
30
|
- 🎨 Convert Figma design nodes to high-fidelity HTML/CSS markup, Industry-leading position
|
21
31
|
- 📚 Provides Figma design context to AI coding tools like Cursor
|
22
32
|
- 🚀 Supports Figma file URLs with fileKey and nodeId parameters
|
23
33
|
|
34
|
+
|
24
35
|
## Getting started
|
36
|
+
|
25
37
|
See [Getting started](docs/en/GettingStarted.md)
|
26
38
|
|
27
39
|
## FAQ
|
@@ -32,4 +44,5 @@ See [FAQ](docs/en/FAQ.md)
|
|
32
44
|
Thanks to:
|
33
45
|
|
34
46
|
+ [Framelink Figma MCP Server](https://github.com/GLips/Figma-Context-MCP) Give Cursor and other AI-powered coding tools access to your Figma files with this Model Context Protocol server.
|
47
|
+
+ [Cursor Talk to Figma MCP](https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp) Allowing Cursor to communicate with Figma for reading designs and modifying them programmatically.
|
35
48
|
+ [Figma MCP Server](https://github.com/MatthewDailey/figma-mcp) This server provides tools for viewing, commenting, and analyzing Figma designs directly through the ModelContextProtocol.
|
package/dist/cli.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
"use strict";var Gt=Object.create;var Ie=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Bt=Object.getPrototypeOf,Xt=Object.prototype.hasOwnProperty;var Wt=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Kt(e))!Xt.call(o,s)&&s!==t&&Ie(o,s,{get:()=>e[s],enumerable:!(r=Jt(e,s))||r.enumerable});return o};var Yt=(o,e,t)=>(t=o!=null?Gt(Bt(o)):{},Wt(e||!o||!o.__esModule?Ie(t,"default",{value:o,enumerable:!0}):t,o));var n=require("zod"),ge="2025-03-26",Me=[ge,"2024-11-05","2024-10-07"],$="2.0",Le=n.z.union([n.z.string(),n.z.number().int()]),De=n.z.string(),Qt=n.z.object({progressToken:n.z.optional(Le)}).passthrough(),R=n.z.object({_meta:n.z.optional(Qt)}).passthrough(),v=n.z.object({method:n.z.string(),params:n.z.optional(R)}),I=n.z.object({_meta:n.z.optional(n.z.object({}).passthrough())}).passthrough(),C=n.z.object({method:n.z.string(),params:n.z.optional(I)}),P=n.z.object({_meta:n.z.optional(n.z.object({}).passthrough())}).passthrough(),q=n.z.union([n.z.string(),n.z.number().int()]),He=n.z.object({jsonrpc:n.z.literal($),id:q}).merge(v).strict(),$e=o=>He.safeParse(o).success,qe=n.z.object({jsonrpc:n.z.literal($)}).merge(C).strict(),Ze=o=>qe.safeParse(o).success,Fe=n.z.object({jsonrpc:n.z.literal($),id:q,result:P}).strict(),ye=o=>Fe.safeParse(o).success,g;(function(o){o[o.ConnectionClosed=-32e3]="ConnectionClosed",o[o.RequestTimeout=-32001]="RequestTimeout",o[o.ParseError=-32700]="ParseError",o[o.InvalidRequest=-32600]="InvalidRequest",o[o.MethodNotFound=-32601]="MethodNotFound",o[o.InvalidParams=-32602]="InvalidParams",o[o.InternalError=-32603]="InternalError"})(g||(g={}));var ze=n.z.object({jsonrpc:n.z.literal($),id:q,error:n.z.object({code:n.z.number().int(),message:n.z.string(),data:n.z.optional(n.z.unknown())})}).strict(),Ue=o=>ze.safeParse(o).success,Ve=n.z.union([He,qe,Fe,ze]),Z=P.strict(),F=C.extend({method:n.z.literal("notifications/cancelled"),params:I.extend({requestId:q,reason:n.z.string().optional()})}),Ge=n.z.object({name:n.z.string(),version:n.z.string()}).passthrough(),er=n.z.object({experimental:n.z.optional(n.z.object({}).passthrough()),sampling:n.z.optional(n.z.object({}).passthrough()),roots:n.z.optional(n.z.object({listChanged:n.z.optional(n.z.boolean())}).passthrough())}).passthrough(),be=v.extend({method:n.z.literal("initialize"),params:R.extend({protocolVersion:n.z.string(),capabilities:er,clientInfo:Ge})});var tr=n.z.object({experimental:n.z.optional(n.z.object({}).passthrough()),logging:n.z.optional(n.z.object({}).passthrough()),completions:n.z.optional(n.z.object({}).passthrough()),prompts:n.z.optional(n.z.object({listChanged:n.z.optional(n.z.boolean())}).passthrough()),resources:n.z.optional(n.z.object({subscribe:n.z.optional(n.z.boolean()),listChanged:n.z.optional(n.z.boolean())}).passthrough()),tools:n.z.optional(n.z.object({listChanged:n.z.optional(n.z.boolean())}).passthrough())}).passthrough(),rr=P.extend({protocolVersion:n.z.string(),capabilities:tr,serverInfo:Ge,instructions:n.z.optional(n.z.string())}),_e=C.extend({method:n.z.literal("notifications/initialized")});var z=v.extend({method:n.z.literal("ping")}),or=n.z.object({progress:n.z.number(),total:n.z.optional(n.z.number())}).passthrough(),U=C.extend({method:n.z.literal("notifications/progress"),params:I.merge(or).extend({progressToken:Le})}),V=v.extend({params:R.extend({cursor:n.z.optional(De)}).optional()}),G=P.extend({nextCursor:n.z.optional(De)}),Je=n.z.object({uri:n.z.string(),mimeType:n.z.optional(n.z.string())}).passthrough(),Ke=Je.extend({text:n.z.string()}),Be=Je.extend({blob:n.z.string().base64()}),nr=n.z.object({uri:n.z.string(),name:n.z.string(),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).passthrough(),sr=n.z.object({uriTemplate:n.z.string(),name:n.z.string(),description:n.z.optional(n.z.string()),mimeType:n.z.optional(n.z.string())}).passthrough(),J=V.extend({method:n.z.literal("resources/list")}),ar=G.extend({resources:n.z.array(nr)}),K=V.extend({method:n.z.literal("resources/templates/list")}),ir=G.extend({resourceTemplates:n.z.array(sr)}),B=v.extend({method:n.z.literal("resources/read"),params:R.extend({uri:n.z.string()})}),lr=P.extend({contents:n.z.array(n.z.union([Ke,Be]))}),cr=C.extend({method:n.z.literal("notifications/resources/list_changed")}),pr=v.extend({method:n.z.literal("resources/subscribe"),params:R.extend({uri:n.z.string()})}),ur=v.extend({method:n.z.literal("resources/unsubscribe"),params:R.extend({uri:n.z.string()})}),mr=C.extend({method:n.z.literal("notifications/resources/updated"),params:I.extend({uri:n.z.string()})}),dr=n.z.object({name:n.z.string(),description:n.z.optional(n.z.string()),required:n.z.optional(n.z.boolean())}).passthrough(),fr=n.z.object({name:n.z.string(),description:n.z.optional(n.z.string()),arguments:n.z.optional(n.z.array(dr))}).passthrough(),X=V.extend({method:n.z.literal("prompts/list")}),hr=G.extend({prompts:n.z.array(fr)}),W=v.extend({method:n.z.literal("prompts/get"),params:R.extend({name:n.z.string(),arguments:n.z.optional(n.z.record(n.z.string()))})}),Y=n.z.object({type:n.z.literal("text"),text:n.z.string()}).passthrough(),Q=n.z.object({type:n.z.literal("image"),data:n.z.string().base64(),mimeType:n.z.string()}).passthrough(),ee=n.z.object({type:n.z.literal("audio"),data:n.z.string().base64(),mimeType:n.z.string()}).passthrough(),Xe=n.z.object({type:n.z.literal("resource"),resource:n.z.union([Ke,Be])}).passthrough(),gr=n.z.object({role:n.z.enum(["user","assistant"]),content:n.z.union([Y,Q,ee,Xe])}).passthrough(),yr=P.extend({description:n.z.optional(n.z.string()),messages:n.z.array(gr)}),br=C.extend({method:n.z.literal("notifications/prompts/list_changed")}),_r=n.z.object({title:n.z.optional(n.z.string()),readOnlyHint:n.z.optional(n.z.boolean()),destructiveHint:n.z.optional(n.z.boolean()),idempotentHint:n.z.optional(n.z.boolean()),openWorldHint:n.z.optional(n.z.boolean())}).passthrough(),xr=n.z.object({name:n.z.string(),description:n.z.optional(n.z.string()),inputSchema:n.z.object({type:n.z.literal("object"),properties:n.z.optional(n.z.object({}).passthrough())}).passthrough(),annotations:n.z.optional(_r)}).passthrough(),te=V.extend({method:n.z.literal("tools/list")}),vr=G.extend({tools:n.z.array(xr)}),We=P.extend({content:n.z.array(n.z.union([Y,Q,ee,Xe])),isError:n.z.boolean().default(!1).optional()}),Wr=We.or(P.extend({toolResult:n.z.unknown()})),re=v.extend({method:n.z.literal("tools/call"),params:R.extend({name:n.z.string(),arguments:n.z.optional(n.z.record(n.z.unknown()))})}),Sr=C.extend({method:n.z.literal("notifications/tools/list_changed")}),Ye=n.z.enum(["debug","info","notice","warning","error","critical","alert","emergency"]),Rr=v.extend({method:n.z.literal("logging/setLevel"),params:R.extend({level:Ye})}),Pr=C.extend({method:n.z.literal("notifications/message"),params:I.extend({level:Ye,logger:n.z.optional(n.z.string()),data:n.z.unknown()})}),Tr=n.z.object({name:n.z.string().optional()}).passthrough(),wr=n.z.object({hints:n.z.optional(n.z.array(Tr)),costPriority:n.z.optional(n.z.number().min(0).max(1)),speedPriority:n.z.optional(n.z.number().min(0).max(1)),intelligencePriority:n.z.optional(n.z.number().min(0).max(1))}).passthrough(),kr=n.z.object({role:n.z.enum(["user","assistant"]),content:n.z.union([Y,Q,ee])}).passthrough(),Cr=v.extend({method:n.z.literal("sampling/createMessage"),params:R.extend({messages:n.z.array(kr),systemPrompt:n.z.optional(n.z.string()),includeContext:n.z.optional(n.z.enum(["none","thisServer","allServers"])),temperature:n.z.optional(n.z.number()),maxTokens:n.z.number().int(),stopSequences:n.z.optional(n.z.array(n.z.string())),metadata:n.z.optional(n.z.object({}).passthrough()),modelPreferences:n.z.optional(wr)})}),xe=P.extend({model:n.z.string(),stopReason:n.z.optional(n.z.enum(["endTurn","stopSequence","maxTokens"]).or(n.z.string())),role:n.z.enum(["user","assistant"]),content:n.z.discriminatedUnion("type",[Y,Q,ee])}),Er=n.z.object({type:n.z.literal("ref/resource"),uri:n.z.string()}).passthrough(),jr=n.z.object({type:n.z.literal("ref/prompt"),name:n.z.string()}).passthrough(),oe=v.extend({method:n.z.literal("completion/complete"),params:R.extend({ref:n.z.union([jr,Er]),argument:n.z.object({name:n.z.string(),value:n.z.string()}).passthrough()})}),Ar=P.extend({completion:n.z.object({values:n.z.array(n.z.string()).max(100),total:n.z.optional(n.z.number().int()),hasMore:n.z.optional(n.z.boolean())}).passthrough()}),Nr=n.z.object({uri:n.z.string().startsWith("file://"),name:n.z.optional(n.z.string())}).passthrough(),Or=v.extend({method:n.z.literal("roots/list")}),ve=P.extend({roots:n.z.array(Nr)}),Ir=C.extend({method:n.z.literal("notifications/roots/list_changed")}),Yr=n.z.union([z,be,oe,Rr,W,X,J,K,B,pr,ur,re,te]),Qr=n.z.union([F,U,_e,Ir]),eo=n.z.union([Z,xe,ve]),to=n.z.union([z,Cr,Or]),ro=n.z.union([F,U,Pr,mr,cr,Sr,br]),oo=n.z.union([Z,rr,Ar,yr,hr,ar,ir,lr,We,vr]),y=class extends Error{constructor(e,t,r){super(`MCP error ${e}: ${t}`),this.code=e,this.data=r,this.name="McpError"}};var Mr=6e4,ne=class{constructor(e){this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this.setNotificationHandler(F,t=>{let r=this._requestHandlerAbortControllers.get(t.params.requestId);r?.abort(t.params.reason)}),this.setNotificationHandler(U,t=>{this._onprogress(t)}),this.setRequestHandler(z,t=>({}))}_setupTimeout(e,t,r,s,l=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(s,t),startTime:Date.now(),timeout:t,maxTotalTimeout:r,resetTimeoutOnProgress:l,onTimeout:s})}_resetTimeout(e){let t=this._timeoutInfo.get(e);if(!t)return!1;let r=Date.now()-t.startTime;if(t.maxTotalTimeout&&r>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),new y(g.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:r});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){let t=this._timeoutInfo.get(e);t&&(clearTimeout(t.timeoutId),this._timeoutInfo.delete(e))}async connect(e){this._transport=e,this._transport.onclose=()=>{this._onclose()},this._transport.onerror=t=>{this._onerror(t)},this._transport.onmessage=(t,r)=>{ye(t)||Ue(t)?this._onresponse(t):$e(t)?this._onrequest(t,r):Ze(t)?this._onnotification(t):this._onerror(new Error(`Unknown message type: ${JSON.stringify(t)}`))},await this._transport.start()}_onclose(){var e;let t=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._transport=void 0,(e=this.onclose)===null||e===void 0||e.call(this);let r=new y(g.ConnectionClosed,"Connection closed");for(let s of t.values())s(r)}_onerror(e){var t;(t=this.onerror)===null||t===void 0||t.call(this,e)}_onnotification(e){var t;let r=(t=this._notificationHandlers.get(e.method))!==null&&t!==void 0?t:this.fallbackNotificationHandler;r!==void 0&&Promise.resolve().then(()=>r(e)).catch(s=>this._onerror(new Error(`Uncaught error in notification handler: ${s}`)))}_onrequest(e,t){var r,s,l,a;let i=(r=this._requestHandlers.get(e.method))!==null&&r!==void 0?r:this.fallbackRequestHandler;if(i===void 0){(s=this._transport)===null||s===void 0||s.send({jsonrpc:"2.0",id:e.id,error:{code:g.MethodNotFound,message:"Method not found"}}).catch(f=>this._onerror(new Error(`Failed to send an error response: ${f}`)));return}let c=new AbortController;this._requestHandlerAbortControllers.set(e.id,c);let b={signal:c.signal,sessionId:(l=this._transport)===null||l===void 0?void 0:l.sessionId,_meta:(a=e.params)===null||a===void 0?void 0:a._meta,sendNotification:f=>this.notification(f,{relatedRequestId:e.id}),sendRequest:(f,x,E)=>this.request(f,x,{...E,relatedRequestId:e.id}),authInfo:t?.authInfo,requestId:e.id};Promise.resolve().then(()=>i(e,b)).then(f=>{var x;if(!c.signal.aborted)return(x=this._transport)===null||x===void 0?void 0:x.send({result:f,jsonrpc:"2.0",id:e.id})},f=>{var x,E;if(!c.signal.aborted)return(x=this._transport)===null||x===void 0?void 0:x.send({jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(f.code)?f.code:g.InternalError,message:(E=f.message)!==null&&E!==void 0?E:"Internal error"}})}).catch(f=>this._onerror(new Error(`Failed to send response: ${f}`))).finally(()=>{this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){let{progressToken:t,...r}=e.params,s=Number(t),l=this._progressHandlers.get(s);if(!l){this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}let a=this._responseHandlers.get(s),i=this._timeoutInfo.get(s);if(i&&a&&i.resetTimeoutOnProgress)try{this._resetTimeout(s)}catch(c){a(c);return}l(r)}_onresponse(e){let t=Number(e.id),r=this._responseHandlers.get(t);if(r===void 0){this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`));return}if(this._responseHandlers.delete(t),this._progressHandlers.delete(t),this._cleanupTimeout(t),ye(e))r(e);else{let s=new y(e.error.code,e.error.message,e.error.data);r(s)}}get transport(){return this._transport}async close(){var e;await((e=this._transport)===null||e===void 0?void 0:e.close())}request(e,t,r){let{relatedRequestId:s,resumptionToken:l,onresumptiontoken:a}=r??{};return new Promise((i,c)=>{var b,f,x,E,he;if(!this._transport){c(new Error("Not connected"));return}((b=this._options)===null||b===void 0?void 0:b.enforceStrictCapabilities)===!0&&this.assertCapabilityForMethod(e.method),(f=r?.signal)===null||f===void 0||f.throwIfAborted();let k=this._requestMessageId++,Ae={...e,jsonrpc:"2.0",id:k};r?.onprogress&&(this._progressHandlers.set(k,r.onprogress),Ae.params={...e.params,_meta:{progressToken:k}});let Ne=S=>{var j;this._responseHandlers.delete(k),this._progressHandlers.delete(k),this._cleanupTimeout(k),(j=this._transport)===null||j===void 0||j.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:k,reason:String(S)}},{relatedRequestId:s,resumptionToken:l,onresumptiontoken:a}).catch(O=>this._onerror(new Error(`Failed to send cancellation: ${O}`))),c(S)};this._responseHandlers.set(k,S=>{var j;if(!(!((j=r?.signal)===null||j===void 0)&&j.aborted)){if(S instanceof Error)return c(S);try{let O=t.parse(S.result);i(O)}catch(O){c(O)}}}),(x=r?.signal)===null||x===void 0||x.addEventListener("abort",()=>{var S;Ne((S=r?.signal)===null||S===void 0?void 0:S.reason)});let Oe=(E=r?.timeout)!==null&&E!==void 0?E:Mr,Vt=()=>Ne(new y(g.RequestTimeout,"Request timed out",{timeout:Oe}));this._setupTimeout(k,Oe,r?.maxTotalTimeout,Vt,(he=r?.resetTimeoutOnProgress)!==null&&he!==void 0?he:!1),this._transport.send(Ae,{relatedRequestId:s,resumptionToken:l,onresumptiontoken:a}).catch(S=>{this._cleanupTimeout(k),c(S)})})}async notification(e,t){if(!this._transport)throw new Error("Not connected");this.assertNotificationCapability(e.method);let r={...e,jsonrpc:"2.0"};await this._transport.send(r,t)}setRequestHandler(e,t){let r=e.shape.method.value;this.assertRequestHandlerCapability(r),this._requestHandlers.set(r,(s,l)=>Promise.resolve(t(e.parse(s),l)))}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw new Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){this._notificationHandlers.set(e.shape.method.value,r=>Promise.resolve(t(e.parse(r))))}removeNotificationHandler(e){this._notificationHandlers.delete(e)}};function Qe(o,e){return Object.entries(e).reduce((t,[r,s])=>(s&&typeof s=="object"?t[r]=t[r]?{...t[r],...s}:s:t[r]=s,t),{...o})}var se=class extends ne{constructor(e,t){var r;super(t),this._serverInfo=e,this._capabilities=(r=t?.capabilities)!==null&&r!==void 0?r:{},this._instructions=t?.instructions,this.setRequestHandler(be,s=>this._oninitialize(s)),this.setNotificationHandler(_e,()=>{var s;return(s=this.oninitialized)===null||s===void 0?void 0:s.call(this)})}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=Qe(this._capabilities,e)}assertCapabilityForMethod(e){var t,r;switch(e){case"sampling/createMessage":if(!(!((t=this._clientCapabilities)===null||t===void 0)&&t.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"roots/list":if(!(!((r=this._clientCapabilities)===null||r===void 0)&&r.roots))throw new Error(`Client does not support listing roots (required for ${e})`);break;case"ping":break}}assertNotificationCapability(e){switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`);break;case"notifications/cancelled":break;case"notifications/progress":break}}assertRequestHandlerCapability(e){switch(e){case"sampling/createMessage":if(!this._capabilities.sampling)throw new Error(`Server does not support sampling (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`);break;case"ping":case"initialize":break}}async _oninitialize(e){let t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:Me.includes(t)?t:ge,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},Z)}async createMessage(e,t){return this.request({method:"sampling/createMessage",params:e},xe,t)}async listRoots(e,t){return this.request({method:"roots/list",params:e},ve,t)}async sendLoggingMessage(e){return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}};var tt=Symbol("Let zodToJsonSchema decide on which parser to use");var et={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},rt=o=>typeof o=="string"?{...et,name:o}:{...et,...o};var ot=o=>{let e=rt(o),t=e.name!==void 0?[...e.basePath,e.definitionPath,e.name]:e.basePath;return{...e,currentPath:t,propertyPath:void 0,seen:new Map(Object.entries(e.definitions).map(([r,s])=>[s._def,{def:s._def,path:[...e.basePath,e.definitionPath,r],jsonSchema:void 0}]))}};function Se(o,e,t,r){r?.errorMessages&&t&&(o.errorMessage={...o.errorMessage,[e]:t})}function d(o,e,t,r,s){o[e]=t,Se(o,e,r,s)}var m=require("zod");function nt(){return{}}var st=require("zod");function at(o,e){let t={type:"array"};return o.type?._def&&o.type?._def?.typeName!==st.ZodFirstPartyTypeKind.ZodAny&&(t.items=u(o.type._def,{...e,currentPath:[...e.currentPath,"items"]})),o.minLength&&d(t,"minItems",o.minLength.value,o.minLength.message,e),o.maxLength&&d(t,"maxItems",o.maxLength.value,o.maxLength.message,e),o.exactLength&&(d(t,"minItems",o.exactLength.value,o.exactLength.message,e),d(t,"maxItems",o.exactLength.value,o.exactLength.message,e)),t}function it(o,e){let t={type:"integer",format:"int64"};if(!o.checks)return t;for(let r of o.checks)switch(r.kind){case"min":e.target==="jsonSchema7"?r.inclusive?d(t,"minimum",r.value,r.message,e):d(t,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(t.exclusiveMinimum=!0),d(t,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?d(t,"maximum",r.value,r.message,e):d(t,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(t.exclusiveMaximum=!0),d(t,"maximum",r.value,r.message,e));break;case"multipleOf":d(t,"multipleOf",r.value,r.message,e);break}return t}function lt(){return{type:"boolean"}}function ae(o,e){return u(o.type._def,e)}var ct=(o,e)=>u(o.innerType._def,e);function Re(o,e,t){let r=t??e.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((s,l)=>Re(o,e,s))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return Lr(o,e)}}var Lr=(o,e)=>{let t={type:"integer",format:"unix-time"};if(e.target==="openApi3")return t;for(let r of o.checks)switch(r.kind){case"min":d(t,"minimum",r.value,r.message,e);break;case"max":d(t,"maximum",r.value,r.message,e);break}return t};function pt(o,e){return{...u(o.innerType._def,e),default:o.defaultValue()}}function ut(o,e){return e.effectStrategy==="input"?u(o.schema._def,e):{}}function mt(o){return{type:"string",enum:Array.from(o.values)}}var Dr=o=>"type"in o&&o.type==="string"?!1:"allOf"in o;function dt(o,e){let t=[u(o.left._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),u(o.right._def,{...e,currentPath:[...e.currentPath,"allOf","1"]})].filter(l=>!!l),r=e.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0,s=[];return t.forEach(l=>{if(Dr(l))s.push(...l.allOf),l.unevaluatedProperties===void 0&&(r=void 0);else{let a=l;if("additionalProperties"in l&&l.additionalProperties===!1){let{additionalProperties:i,...c}=l;a=c}else r=void 0;s.push(a)}}),s.length?{allOf:s,...r}:void 0}function ft(o,e){let t=typeof o.value;return t!=="bigint"&&t!=="number"&&t!=="boolean"&&t!=="string"?{type:Array.isArray(o.value)?"array":"object"}:e.target==="openApi3"?{type:t==="bigint"?"integer":t,enum:[o.value]}:{type:t==="bigint"?"integer":t,const:o.value}}var A=require("zod");var Pe,T={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(Pe===void 0&&(Pe=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Pe),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?: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])$/,ipv4Cidr:/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function ie(o,e){let t={type:"string"};if(o.checks)for(let r of o.checks)switch(r.kind){case"min":d(t,"minLength",typeof t.minLength=="number"?Math.max(t.minLength,r.value):r.value,r.message,e);break;case"max":d(t,"maxLength",typeof t.maxLength=="number"?Math.min(t.maxLength,r.value):r.value,r.message,e);break;case"email":switch(e.emailStrategy){case"format:email":w(t,"email",r.message,e);break;case"format:idn-email":w(t,"idn-email",r.message,e);break;case"pattern:zod":_(t,T.email,r.message,e);break}break;case"url":w(t,"uri",r.message,e);break;case"uuid":w(t,"uuid",r.message,e);break;case"regex":_(t,r.regex,r.message,e);break;case"cuid":_(t,T.cuid,r.message,e);break;case"cuid2":_(t,T.cuid2,r.message,e);break;case"startsWith":_(t,RegExp(`^${Te(r.value,e)}`),r.message,e);break;case"endsWith":_(t,RegExp(`${Te(r.value,e)}$`),r.message,e);break;case"datetime":w(t,"date-time",r.message,e);break;case"date":w(t,"date",r.message,e);break;case"time":w(t,"time",r.message,e);break;case"duration":w(t,"duration",r.message,e);break;case"length":d(t,"minLength",typeof t.minLength=="number"?Math.max(t.minLength,r.value):r.value,r.message,e),d(t,"maxLength",typeof t.maxLength=="number"?Math.min(t.maxLength,r.value):r.value,r.message,e);break;case"includes":{_(t,RegExp(Te(r.value,e)),r.message,e);break}case"ip":{r.version!=="v6"&&w(t,"ipv4",r.message,e),r.version!=="v4"&&w(t,"ipv6",r.message,e);break}case"base64url":_(t,T.base64url,r.message,e);break;case"jwt":_(t,T.jwt,r.message,e);break;case"cidr":{r.version!=="v6"&&_(t,T.ipv4Cidr,r.message,e),r.version!=="v4"&&_(t,T.ipv6Cidr,r.message,e);break}case"emoji":_(t,T.emoji(),r.message,e);break;case"ulid":{_(t,T.ulid,r.message,e);break}case"base64":{switch(e.base64Strategy){case"format:binary":{w(t,"binary",r.message,e);break}case"contentEncoding:base64":{d(t,"contentEncoding","base64",r.message,e);break}case"pattern:zod":{_(t,T.base64,r.message,e);break}}break}case"nanoid":_(t,T.nanoid,r.message,e);case"toLowerCase":case"toUpperCase":case"trim":break;default:}return t}function Te(o,e){return e.patternStrategy==="escape"?$r(o):o}var Hr=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function $r(o){let e="";for(let t=0;t<o.length;t++)Hr.has(o[t])||(e+="\\"),e+=o[t];return e}function w(o,e,t,r){o.format||o.anyOf?.some(s=>s.format)?(o.anyOf||(o.anyOf=[]),o.format&&(o.anyOf.push({format:o.format,...o.errorMessage&&r.errorMessages&&{errorMessage:{format:o.errorMessage.format}}}),delete o.format,o.errorMessage&&(delete o.errorMessage.format,Object.keys(o.errorMessage).length===0&&delete o.errorMessage)),o.anyOf.push({format:e,...t&&r.errorMessages&&{errorMessage:{format:t}}})):d(o,"format",e,t,r)}function _(o,e,t,r){o.pattern||o.allOf?.some(s=>s.pattern)?(o.allOf||(o.allOf=[]),o.pattern&&(o.allOf.push({pattern:o.pattern,...o.errorMessage&&r.errorMessages&&{errorMessage:{pattern:o.errorMessage.pattern}}}),delete o.pattern,o.errorMessage&&(delete o.errorMessage.pattern,Object.keys(o.errorMessage).length===0&&delete o.errorMessage)),o.allOf.push({pattern:ht(e,r),...t&&r.errorMessages&&{errorMessage:{pattern:t}}})):d(o,"pattern",ht(e,r),t,r)}function ht(o,e){if(!e.applyRegexFlags||!o.flags)return o.source;let t={i:o.flags.includes("i"),m:o.flags.includes("m"),s:o.flags.includes("s")},r=t.i?o.source.toLowerCase():o.source,s="",l=!1,a=!1,i=!1;for(let c=0;c<r.length;c++){if(l){s+=r[c],l=!1;continue}if(t.i){if(a){if(r[c].match(/[a-z]/)){i?(s+=r[c],s+=`${r[c-2]}-${r[c]}`.toUpperCase(),i=!1):r[c+1]==="-"&&r[c+2]?.match(/[a-z]/)?(s+=r[c],i=!0):s+=`${r[c]}${r[c].toUpperCase()}`;continue}}else if(r[c].match(/[a-z]/)){s+=`[${r[c]}${r[c].toUpperCase()}]`;continue}}if(t.m){if(r[c]==="^"){s+=`(^|(?<=[\r
|
3
|
-
]))`;continue}else if(r[
|
4
|
-
]))`;continue}}if(t.s&&r[
|
5
|
-
`:`[${r[
|
6
|
-
]`;continue}s+=r[c],r[c]==="\\"?l=!0:a&&r[c]==="]"?a=!1:!a&&r[c]==="["&&(a=!0)}try{new RegExp(s)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),o.source}return s}function le(o,e){if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&o.keyType?._def.typeName===A.ZodFirstPartyTypeKind.ZodEnum)return{type:"object",required:o.keyType._def.values,properties:o.keyType._def.values.reduce((r,s)=>({...r,[s]:u(o.valueType._def,{...e,currentPath:[...e.currentPath,"properties",s]})??{}}),{}),additionalProperties:e.rejectedAdditionalProperties};let t={type:"object",additionalProperties:u(o.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return t;if(o.keyType?._def.typeName===A.ZodFirstPartyTypeKind.ZodString&&o.keyType._def.checks?.length){let{type:r,...s}=ie(o.keyType._def,e);return{...t,propertyNames:s}}else{if(o.keyType?._def.typeName===A.ZodFirstPartyTypeKind.ZodEnum)return{...t,propertyNames:{enum:o.keyType._def.values}};if(o.keyType?._def.typeName===A.ZodFirstPartyTypeKind.ZodBranded&&o.keyType._def.type._def.typeName===A.ZodFirstPartyTypeKind.ZodString&&o.keyType._def.type._def.checks?.length){let{type:r,...s}=ae(o.keyType._def,e);return{...t,propertyNames:s}}}return t}function gt(o,e){if(e.mapStrategy==="record")return le(o,e);let t=u(o.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},r=u(o.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[t,r],minItems:2,maxItems:2}}}function yt(o){let e=o.values,r=Object.keys(o.values).filter(l=>typeof e[e[l]]!="number").map(l=>e[l]),s=Array.from(new Set(r.map(l=>typeof l)));return{type:s.length===1?s[0]==="string"?"string":"number":["string","number"],enum:r}}function bt(){return{not:{}}}function _t(o){return o.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var M={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function vt(o,e){if(e.target==="openApi3")return xt(o,e);let t=o.options instanceof Map?Array.from(o.options.values()):o.options;if(t.every(r=>r._def.typeName in M&&(!r._def.checks||!r._def.checks.length))){let r=t.reduce((s,l)=>{let a=M[l._def.typeName];return a&&!s.includes(a)?[...s,a]:s},[]);return{type:r.length>1?r:r[0]}}else if(t.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){let r=t.reduce((s,l)=>{let a=typeof l._def.value;switch(a){case"string":case"number":case"boolean":return[...s,a];case"bigint":return[...s,"integer"];case"object":if(l._def.value===null)return[...s,"null"];case"symbol":case"undefined":case"function":default:return s}},[]);if(r.length===t.length){let s=r.filter((l,a,i)=>i.indexOf(l)===a);return{type:s.length>1?s:s[0],enum:t.reduce((l,a)=>l.includes(a._def.value)?l:[...l,a._def.value],[])}}}else if(t.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:t.reduce((r,s)=>[...r,...s._def.values.filter(l=>!r.includes(l))],[])};return xt(o,e)}var xt=(o,e)=>{let t=(o.options instanceof Map?Array.from(o.options.values()):o.options).map((r,s)=>u(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${s}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return t.length?{anyOf:t}:void 0};function St(o,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(o.innerType._def.typeName)&&(!o.innerType._def.checks||!o.innerType._def.checks.length))return e.target==="openApi3"?{type:M[o.innerType._def.typeName],nullable:!0}:{type:[M[o.innerType._def.typeName],"null"]};if(e.target==="openApi3"){let r=u(o.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let t=u(o.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return t&&{anyOf:[t,{type:"null"}]}}function Rt(o,e){let t={type:"number"};if(!o.checks)return t;for(let r of o.checks)switch(r.kind){case"int":t.type="integer",Se(t,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?d(t,"minimum",r.value,r.message,e):d(t,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(t.exclusiveMinimum=!0),d(t,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?d(t,"maximum",r.value,r.message,e):d(t,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(t.exclusiveMaximum=!0),d(t,"maximum",r.value,r.message,e));break;case"multipleOf":d(t,"multipleOf",r.value,r.message,e);break}return t}var Pt=require("zod");function Tt(o,e){let t=e.target==="openAi",r={type:"object",properties:{}},s=[],l=o.shape();for(let i in l){let c=l[i];if(c===void 0||c._def===void 0)continue;let b=Zr(c);b&&t&&(c instanceof Pt.ZodOptional&&(c=c._def.innerType),c.isNullable()||(c=c.nullable()),b=!1);let f=u(c._def,{...e,currentPath:[...e.currentPath,"properties",i],propertyPath:[...e.currentPath,"properties",i]});f!==void 0&&(r.properties[i]=f,b||s.push(i))}s.length&&(r.required=s);let a=qr(o,e);return a!==void 0&&(r.additionalProperties=a),r}function qr(o,e){if(o.catchall._def.typeName!=="ZodNever")return u(o.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(o.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function Zr(o){try{return o.isOptional()}catch{return!0}}var wt=(o,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return u(o.innerType._def,e);let t=u(o.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return t?{anyOf:[{not:{}},t]}:{}};var kt=(o,e)=>{if(e.pipeStrategy==="input")return u(o.in._def,e);if(e.pipeStrategy==="output")return u(o.out._def,e);let t=u(o.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=u(o.out._def,{...e,currentPath:[...e.currentPath,"allOf",t?"1":"0"]});return{allOf:[t,r].filter(s=>s!==void 0)}};function Ct(o,e){return u(o.type._def,e)}function Et(o,e){let r={type:"array",uniqueItems:!0,items:u(o.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return o.minSize&&d(r,"minItems",o.minSize.value,o.minSize.message,e),o.maxSize&&d(r,"maxItems",o.maxSize.value,o.maxSize.message,e),r}function jt(o,e){return o.rest?{type:"array",minItems:o.items.length,items:o.items.map((t,r)=>u(t._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((t,r)=>r===void 0?t:[...t,r],[]),additionalItems:u(o.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:o.items.length,maxItems:o.items.length,items:o.items.map((t,r)=>u(t._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((t,r)=>r===void 0?t:[...t,r],[])}}function At(){return{not:{}}}function Nt(){return{}}var Ot=(o,e)=>u(o.innerType._def,e);var It=(o,e,t)=>{switch(e){case m.ZodFirstPartyTypeKind.ZodString:return ie(o,t);case m.ZodFirstPartyTypeKind.ZodNumber:return Rt(o,t);case m.ZodFirstPartyTypeKind.ZodObject:return Tt(o,t);case m.ZodFirstPartyTypeKind.ZodBigInt:return it(o,t);case m.ZodFirstPartyTypeKind.ZodBoolean:return lt();case m.ZodFirstPartyTypeKind.ZodDate:return Re(o,t);case m.ZodFirstPartyTypeKind.ZodUndefined:return At();case m.ZodFirstPartyTypeKind.ZodNull:return _t(t);case m.ZodFirstPartyTypeKind.ZodArray:return at(o,t);case m.ZodFirstPartyTypeKind.ZodUnion:case m.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:return vt(o,t);case m.ZodFirstPartyTypeKind.ZodIntersection:return dt(o,t);case m.ZodFirstPartyTypeKind.ZodTuple:return jt(o,t);case m.ZodFirstPartyTypeKind.ZodRecord:return le(o,t);case m.ZodFirstPartyTypeKind.ZodLiteral:return ft(o,t);case m.ZodFirstPartyTypeKind.ZodEnum:return mt(o);case m.ZodFirstPartyTypeKind.ZodNativeEnum:return yt(o);case m.ZodFirstPartyTypeKind.ZodNullable:return St(o,t);case m.ZodFirstPartyTypeKind.ZodOptional:return wt(o,t);case m.ZodFirstPartyTypeKind.ZodMap:return gt(o,t);case m.ZodFirstPartyTypeKind.ZodSet:return Et(o,t);case m.ZodFirstPartyTypeKind.ZodLazy:return()=>o.getter()._def;case m.ZodFirstPartyTypeKind.ZodPromise:return Ct(o,t);case m.ZodFirstPartyTypeKind.ZodNaN:case m.ZodFirstPartyTypeKind.ZodNever:return bt();case m.ZodFirstPartyTypeKind.ZodEffects:return ut(o,t);case m.ZodFirstPartyTypeKind.ZodAny:return nt();case m.ZodFirstPartyTypeKind.ZodUnknown:return Nt();case m.ZodFirstPartyTypeKind.ZodDefault:return pt(o,t);case m.ZodFirstPartyTypeKind.ZodBranded:return ae(o,t);case m.ZodFirstPartyTypeKind.ZodReadonly:return Ot(o,t);case m.ZodFirstPartyTypeKind.ZodCatch:return ct(o,t);case m.ZodFirstPartyTypeKind.ZodPipeline:return kt(o,t);case m.ZodFirstPartyTypeKind.ZodFunction:case m.ZodFirstPartyTypeKind.ZodVoid:case m.ZodFirstPartyTypeKind.ZodSymbol:return;default:return(r=>{})(e)}};function u(o,e,t=!1){let r=e.seen.get(o);if(e.override){let i=e.override?.(o,e,r,t);if(i!==tt)return i}if(r&&!t){let i=Fr(r,e);if(i!==void 0)return i}let s={def:o,path:e.currentPath,jsonSchema:void 0};e.seen.set(o,s);let l=It(o,o.typeName,e),a=typeof l=="function"?u(l(),e):l;if(a&&Ur(o,e,a),e.postProcess){let i=e.postProcess(a,o,e);return s.jsonSchema=a,i}return s.jsonSchema=a,a}var Fr=(o,e)=>{switch(e.$refStrategy){case"root":return{$ref:o.path.join("/")};case"relative":return{$ref:zr(e.currentPath,o.path)};case"none":case"seen":return o.path.length<e.currentPath.length&&o.path.every((t,r)=>e.currentPath[r]===t)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),{}):e.$refStrategy==="seen"?{}:void 0}},zr=(o,e)=>{let t=0;for(;t<o.length&&t<e.length&&o[t]===e[t];t++);return[(o.length-t).toString(),...e.slice(t)].join("/")},Ur=(o,e,t)=>(o.description&&(t.description=o.description,e.markdownDescription&&(t.markdownDescription=o.description)),t);var we=(o,e)=>{let t=ot(e),r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((c,[b,f])=>({...c,[b]:u(f._def,{...t,currentPath:[...t.basePath,t.definitionPath,b]},!0)??{}}),{}):void 0,s=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,l=u(o._def,s===void 0?t:{...t,currentPath:[...t.basePath,t.definitionPath,s]},!1)??{},a=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;a!==void 0&&(l.title=a);let i=s===void 0?r?{...l,[t.definitionPath]:r}:l:{$ref:[...t.$refStrategy==="relative"?[]:t.basePath,t.definitionPath,s].join("/"),[t.definitionPath]:{...r,[s]:l}};return t.target==="jsonSchema7"?i.$schema="http://json-schema.org/draft-07/schema#":(t.target==="jsonSchema2019-09"||t.target==="openAi")&&(i.$schema="https://json-schema.org/draft/2019-09/schema#"),t.target==="openAi"&&("anyOf"in i||"oneOf"in i||"allOf"in i||"type"in i&&Array.isArray(i.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),i};var L=require("zod");var Mt=require("zod"),ke;(function(o){o.Completable="McpCompletable"})(ke||(ke={}));var N=class extends Mt.ZodType{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}};N.create=(o,e)=>new N({type:o,typeName:ke.Completable,complete:e.complete,...Vr(e)});function Vr(o){if(!o)return{};let{errorMap:e,invalid_type_error:t,required_error:r,description:s}=o;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(a,i)=>{var c,b;let{message:f}=o;return a.code==="invalid_enum_value"?{message:f??i.defaultError}:typeof i.data>"u"?{message:(c=f??r)!==null&&c!==void 0?c:i.defaultError}:a.code!=="invalid_type"?{message:i.defaultError}:{message:(b=f??t)!==null&&b!==void 0?b:i.defaultError}},description:s}}var pe=class{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new se(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(te.shape.method.value),this.server.assertCanSetRequestHandler(re.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(te,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,description:t.description,inputSchema:t.inputSchema?we(t.inputSchema,{strictUnions:!0}):Gr,annotations:t.annotations}))})),this.server.setRequestHandler(re,async(e,t)=>{let r=this._registeredTools[e.params.name];if(!r)throw new y(g.InvalidParams,`Tool ${e.params.name} not found`);if(!r.enabled)throw new y(g.InvalidParams,`Tool ${e.params.name} disabled`);if(r.inputSchema){let s=await r.inputSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new y(g.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${s.error.message}`);let l=s.data,a=r.callback;try{return await Promise.resolve(a(l,t))}catch(i){return{content:[{type:"text",text:i instanceof Error?i.message:String(i)}],isError:!0}}}else{let s=r.callback;try{return await Promise.resolve(s(t))}catch(l){return{content:[{type:"text",text:l instanceof Error?l.message:String(l)}],isError:!0}}}}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(oe.shape.method.value),this.server.setRequestHandler(oe,async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new y(g.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){let r=this._registeredPrompts[t.name];if(!r)throw new y(g.InvalidParams,`Prompt ${t.name} not found`);if(!r.enabled)throw new y(g.InvalidParams,`Prompt ${t.name} disabled`);if(!r.argsSchema)return ce;let s=r.argsSchema.shape[e.params.argument.name];if(!(s instanceof N))return ce;let a=await s._def.complete(e.params.argument.value);return Dt(a)}async handleResourceCompletion(e,t){let r=Object.values(this._registeredResourceTemplates).find(a=>a.resourceTemplate.uriTemplate.toString()===t.uri);if(!r){if(this._registeredResources[t.uri])return ce;throw new y(g.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}let s=r.resourceTemplate.completeCallback(e.params.argument.name);if(!s)return ce;let l=await s(e.params.argument.value);return Dt(l)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(J.shape.method.value),this.server.assertCanSetRequestHandler(K.shape.method.value),this.server.assertCanSetRequestHandler(B.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(J,async(e,t)=>{let r=Object.entries(this._registeredResources).filter(([l,a])=>a.enabled).map(([l,a])=>({uri:l,name:a.name,...a.metadata})),s=[];for(let l of Object.values(this._registeredResourceTemplates)){if(!l.resourceTemplate.listCallback)continue;let a=await l.resourceTemplate.listCallback(t);for(let i of a.resources)s.push({...i,...l.metadata})}return{resources:[...r,...s]}}),this.server.setRequestHandler(K,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([t,r])=>({name:t,uriTemplate:r.resourceTemplate.uriTemplate.toString(),...r.metadata}))})),this.server.setRequestHandler(B,async(e,t)=>{let r=new URL(e.params.uri),s=this._registeredResources[r.toString()];if(s){if(!s.enabled)throw new y(g.InvalidParams,`Resource ${r} disabled`);return s.readCallback(r,t)}for(let l of Object.values(this._registeredResourceTemplates)){let a=l.resourceTemplate.uriTemplate.match(r.toString());if(a)return l.readCallback(r,a,t)}throw new y(g.InvalidParams,`Resource ${r} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(X.shape.method.value),this.server.assertCanSetRequestHandler(W.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(X,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,description:t.description,arguments:t.argsSchema?Kr(t.argsSchema):void 0}))})),this.server.setRequestHandler(W,async(e,t)=>{let r=this._registeredPrompts[e.params.name];if(!r)throw new y(g.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new y(g.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){let s=await r.argsSchema.safeParseAsync(e.params.arguments);if(!s.success)throw new y(g.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${s.error.message}`);let l=s.data,a=r.callback;return await Promise.resolve(a(l,t))}else{let s=r.callback;return await Promise.resolve(s(t))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...r){let s;typeof r[0]=="object"&&(s=r.shift());let l=r[0];if(typeof t=="string"){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);let a={name:e,metadata:s,readCallback:l,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({uri:null}),update:i=>{typeof i.uri<"u"&&i.uri!==t&&(delete this._registeredResources[t],i.uri&&(this._registeredResources[i.uri]=a)),typeof i.name<"u"&&(a.name=i.name),typeof i.metadata<"u"&&(a.metadata=i.metadata),typeof i.callback<"u"&&(a.readCallback=i.callback),typeof i.enabled<"u"&&(a.enabled=i.enabled),this.sendResourceListChanged()}};return this._registeredResources[t]=a,this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);let a={resourceTemplate:t,metadata:s,readCallback:l,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:i=>{typeof i.name<"u"&&i.name!==e&&(delete this._registeredResourceTemplates[e],i.name&&(this._registeredResourceTemplates[i.name]=a)),typeof i.template<"u"&&(a.resourceTemplate=i.template),typeof i.metadata<"u"&&(a.metadata=i.metadata),typeof i.callback<"u"&&(a.readCallback=i.callback),typeof i.enabled<"u"&&(a.enabled=i.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=a,this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r;typeof t[0]=="string"&&(r=t.shift());let s,l;if(t.length>1){let c=t[0];Lt(c)?(s=t.shift(),t.length>1&&typeof t[0]=="object"&&t[0]!==null&&!Lt(t[0])&&(l=t.shift())):typeof c=="object"&&c!==null&&(l=t.shift())}let a=t[0],i={description:r,inputSchema:s===void 0?void 0:L.z.object(s),annotations:l,callback:a,enabled:!0,disable:()=>i.update({enabled:!1}),enable:()=>i.update({enabled:!0}),remove:()=>i.update({name:null}),update:c=>{typeof c.name<"u"&&c.name!==e&&(delete this._registeredTools[e],c.name&&(this._registeredTools[c.name]=i)),typeof c.description<"u"&&(i.description=c.description),typeof c.paramsSchema<"u"&&(i.inputSchema=L.z.object(c.paramsSchema)),typeof c.callback<"u"&&(i.callback=c.callback),typeof c.annotations<"u"&&(i.annotations=c.annotations),typeof c.enabled<"u"&&(i.enabled=c.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=i,this.setToolRequestHandlers(),this.sendToolListChanged(),i}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r;typeof t[0]=="string"&&(r=t.shift());let s;t.length>1&&(s=t.shift());let l=t[0],a={description:r,argsSchema:s===void 0?void 0:L.z.object(s),callback:l,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:i=>{typeof i.name<"u"&&i.name!==e&&(delete this._registeredPrompts[e],i.name&&(this._registeredPrompts[i.name]=a)),typeof i.description<"u"&&(a.description=i.description),typeof i.argsSchema<"u"&&(a.argsSchema=L.z.object(i.argsSchema)),typeof i.callback<"u"&&(a.callback=i.callback),typeof i.enabled<"u"&&(a.enabled=i.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=a,this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}isConnected(){return this.server.transport!==void 0}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}};var Gr={type:"object"};function Lt(o){return typeof o!="object"||o===null?!1:Object.keys(o).length===0||Object.values(o).some(Jr)}function Jr(o){return o!==null&&typeof o=="object"&&"parse"in o&&typeof o.parse=="function"&&"safeParse"in o&&typeof o.safeParse=="function"}function Kr(o){return Object.entries(o.shape).map(([e,t])=>({name:e,description:t.description,required:!t.isOptional()}))}function Dt(o){return{completion:{values:o.slice(0,100),total:o.length,hasMore:o.length>100}}}var ce={completion:{values:[],hasMore:!1}};var ue=process.env.personalToken||""||"",Ht="F2C MCP",$t="0.0.1";var Ce=class{constructor(){this.f2cHost="https://f2c-figma-api.yy.com/api";this.personalToken=ue}async nodeToCode(e){let t={fileKey:e.fileKey,nodeIds:e.ids,personal_token:e.personalToken||this.personalToken,format:e.format},r=this.opToUrl(`${this.f2cHost}/nodes`,t);return this.fetch(r,"text")}async fetch(e,t="json"){try{let s=await fetch(e,{method:"GET"});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return t==="text"?await s.text():await s.json()}catch(r){throw console.error("HTTP error",r),r}}opToUrl(e,t={}){if(Object.keys(t).length===0)return e;let r=new URL(e);for(let[s,l]of Object.entries(t))r.searchParams.append(s,l);return r.toString()}},qt=new Ce;var D=require("zod"),Zt=o=>{o.tool("figma_to_html","Convert Figma design to HTML code with node",{fileKey:D.z.string().describe("Unique identifier of the Figma file"),ids:D.z.string().describe("List of node IDs to retrieve, comma separated"),format:D.z.string().default("html").describe("Format of the returned code"),personalToken:D.z.string().optional().describe("Your Figma personal access token")},async e=>{try{return{content:[{type:"text",text:await qt.nodeToCode(e)}]}}catch(t){return console.error("Tool execution error:",t),{content:[{type:"text",text:`Error: ${t.message}`}]}}})};var Ee=class{constructor(){this.figmaHost="https://api.figma.com/v1";this.personalToken=ue}async files(e){let t;return e.ids?t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}/nodes`,e):t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}`,e),this.fetch(t)}async images(e){let t=this.opToUrl(`${this.figmaHost}/images/${e.fileKey}`,e);return this.fetch(t)}async imageFills(e){let t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}/images`,e);return this.fetch(t)}async meta(e){let t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}/meta`,e);return this.fetch(t)}async fetch(e,t="json"){try{let r={method:"GET",headers:{"X-FIGMA-TOKEN":this.personalToken}},s=await fetch(e,r);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return t==="text"?await s.text():await s.json()}catch(r){throw console.error("HTTP error",r),r}}opToUrl(e,t={},r=["fileKey","personalToken"]){if(Object.keys(t).length===0)return e;t.personalToken&&(this.personalToken=t.personalToken);let s=new URL(e);for(let[l,a]of Object.entries(t))r.includes(l)||s.searchParams.append(l,a);return s.toString()}},H=new Ee;var h=require("zod"),Ft=o=>{o.tool("figma_get_file_data","Get detailed information about a Figma file",{fileKey:h.z.string().describe("Unique identifier of the Figma file"),ids:h.z.string().describe("List of node IDs to retrieve, comma separated"),personalToken:h.z.string().optional().describe("Your Figma personal access token"),version:h.z.string().optional().describe("Specify the version to return"),depth:h.z.number().optional().describe("Specify the depth of nodes to return"),geometry:h.z.enum(["paths"]).optional().describe("Specify whether to include geometry path data"),plugin_data:h.z.string().optional().describe("Specify plugin data to return"),branch_data:h.z.boolean().optional().describe("Specify whether to return branch data")},async e=>{try{let t=await H.files(e);return{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return{content:[{type:"text",text:`Error: ${t.message}`}]}}}),o.tool("figma_get_images","Get images of Figma nodes",{fileKey:h.z.string().describe("Unique identifier of the Figma file"),ids:h.z.string().describe("Node IDs to get images for, comma separated"),format:h.z.enum(["jpg","png","svg","pdf"]).optional().describe("Image format, e.g., png, jpg, svg"),scale:h.z.number().optional().describe("Image scale factor"),svg_include_id:h.z.boolean().optional().describe("Whether SVG includes ID"),svg_simplify_stroke:h.z.boolean().optional().describe("Whether to simplify SVG strokes"),use_absolute_bounds:h.z.boolean().optional().describe("Whether to use absolute bounds"),version:h.z.string().optional().describe("Specify the version to return"),personalToken:h.z.string().optional().describe("Your Figma personal access token")},async e=>{try{let t=await H.images(e);return{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return{content:[{type:"text",text:`Error: ${t.message}`}]}}}),o.tool("figma_get_image_fills","Get all image resources in the specified Figma file",{fileKey:h.z.string().describe("Unique identifier of the Figma file"),personalToken:h.z.string().optional().describe("Your Figma personal access token")},async e=>{try{let t=await H.imageFills(e);return{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return{content:[{type:"text",text:`Error: ${t.message}`}]}}}),o.tool("figma_get_file_meta","Get metadata information for a Figma file",{fileKey:h.z.string().describe("Unique identifier of the Figma file"),personalToken:h.z.string().optional().describe("Your Figma personal access token")},async e=>{try{let t=await H.meta(e);return{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return{content:[{type:"text",text:`Error: ${t.message}`}]}}})};var me=new pe({name:Ht,version:$t},{capabilities:{logging:{}}});Ft(me);Zt(me);var je=Yt(require("process"),1);var de=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
|
7
|
-
`);if(e===-1)return null;let t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),
|
8
|
-
`}var
|
2
|
+
"use strict";var Wt=Object.create;var $e=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var er=Object.getPrototypeOf,tr=Object.prototype.hasOwnProperty;var rr=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Qt(e))!tr.call(o,n)&&n!==t&&$e(o,n,{get:()=>e[n],enumerable:!(r=Yt(e,n))||r.enumerable});return o};var ye=(o,e,t)=>(t=o!=null?Wt(er(o)):{},rr(e||!o||!o.__esModule?$e(t,"default",{value:o,enumerable:!0}):t,o));var s=require("zod"),be="2025-03-26",qe=[be,"2024-11-05","2024-10-07"],$="2.0",Fe=s.z.union([s.z.string(),s.z.number().int()]),Ze=s.z.string(),or=s.z.object({progressToken:s.z.optional(Fe)}).passthrough(),P=s.z.object({_meta:s.z.optional(or)}).passthrough(),x=s.z.object({method:s.z.string(),params:s.z.optional(P)}),L=s.z.object({_meta:s.z.optional(s.z.object({}).passthrough())}).passthrough(),k=s.z.object({method:s.z.string(),params:s.z.optional(L)}),R=s.z.object({_meta:s.z.optional(s.z.object({}).passthrough())}).passthrough(),q=s.z.union([s.z.string(),s.z.number().int()]),ze=s.z.object({jsonrpc:s.z.literal($),id:q}).merge(x).strict(),Ue=o=>ze.safeParse(o).success,Ve=s.z.object({jsonrpc:s.z.literal($)}).merge(k).strict(),Xe=o=>Ve.safeParse(o).success,Ge=s.z.object({jsonrpc:s.z.literal($),id:q,result:R}).strict(),_e=o=>Ge.safeParse(o).success,h;(function(o){o[o.ConnectionClosed=-32e3]="ConnectionClosed",o[o.RequestTimeout=-32001]="RequestTimeout",o[o.ParseError=-32700]="ParseError",o[o.InvalidRequest=-32600]="InvalidRequest",o[o.MethodNotFound=-32601]="MethodNotFound",o[o.InvalidParams=-32602]="InvalidParams",o[o.InternalError=-32603]="InternalError"})(h||(h={}));var Je=s.z.object({jsonrpc:s.z.literal($),id:q,error:s.z.object({code:s.z.number().int(),message:s.z.string(),data:s.z.optional(s.z.unknown())})}).strict(),Be=o=>Je.safeParse(o).success,Ke=s.z.union([ze,Ve,Ge,Je]),F=R.strict(),Z=k.extend({method:s.z.literal("notifications/cancelled"),params:L.extend({requestId:q,reason:s.z.string().optional()})}),We=s.z.object({name:s.z.string(),version:s.z.string()}).passthrough(),sr=s.z.object({experimental:s.z.optional(s.z.object({}).passthrough()),sampling:s.z.optional(s.z.object({}).passthrough()),roots:s.z.optional(s.z.object({listChanged:s.z.optional(s.z.boolean())}).passthrough())}).passthrough(),ve=x.extend({method:s.z.literal("initialize"),params:P.extend({protocolVersion:s.z.string(),capabilities:sr,clientInfo:We})});var nr=s.z.object({experimental:s.z.optional(s.z.object({}).passthrough()),logging:s.z.optional(s.z.object({}).passthrough()),completions:s.z.optional(s.z.object({}).passthrough()),prompts:s.z.optional(s.z.object({listChanged:s.z.optional(s.z.boolean())}).passthrough()),resources:s.z.optional(s.z.object({subscribe:s.z.optional(s.z.boolean()),listChanged:s.z.optional(s.z.boolean())}).passthrough()),tools:s.z.optional(s.z.object({listChanged:s.z.optional(s.z.boolean())}).passthrough())}).passthrough(),ar=R.extend({protocolVersion:s.z.string(),capabilities:nr,serverInfo:We,instructions:s.z.optional(s.z.string())}),xe=k.extend({method:s.z.literal("notifications/initialized")});var z=x.extend({method:s.z.literal("ping")}),ir=s.z.object({progress:s.z.number(),total:s.z.optional(s.z.number())}).passthrough(),U=k.extend({method:s.z.literal("notifications/progress"),params:L.merge(ir).extend({progressToken:Fe})}),V=x.extend({params:P.extend({cursor:s.z.optional(Ze)}).optional()}),X=R.extend({nextCursor:s.z.optional(Ze)}),Ye=s.z.object({uri:s.z.string(),mimeType:s.z.optional(s.z.string())}).passthrough(),Qe=Ye.extend({text:s.z.string()}),et=Ye.extend({blob:s.z.string().base64()}),cr=s.z.object({uri:s.z.string(),name:s.z.string(),description:s.z.optional(s.z.string()),mimeType:s.z.optional(s.z.string())}).passthrough(),lr=s.z.object({uriTemplate:s.z.string(),name:s.z.string(),description:s.z.optional(s.z.string()),mimeType:s.z.optional(s.z.string())}).passthrough(),G=V.extend({method:s.z.literal("resources/list")}),pr=X.extend({resources:s.z.array(cr)}),J=V.extend({method:s.z.literal("resources/templates/list")}),ur=X.extend({resourceTemplates:s.z.array(lr)}),B=x.extend({method:s.z.literal("resources/read"),params:P.extend({uri:s.z.string()})}),mr=R.extend({contents:s.z.array(s.z.union([Qe,et]))}),dr=k.extend({method:s.z.literal("notifications/resources/list_changed")}),fr=x.extend({method:s.z.literal("resources/subscribe"),params:P.extend({uri:s.z.string()})}),hr=x.extend({method:s.z.literal("resources/unsubscribe"),params:P.extend({uri:s.z.string()})}),gr=k.extend({method:s.z.literal("notifications/resources/updated"),params:L.extend({uri:s.z.string()})}),yr=s.z.object({name:s.z.string(),description:s.z.optional(s.z.string()),required:s.z.optional(s.z.boolean())}).passthrough(),br=s.z.object({name:s.z.string(),description:s.z.optional(s.z.string()),arguments:s.z.optional(s.z.array(yr))}).passthrough(),K=V.extend({method:s.z.literal("prompts/list")}),_r=X.extend({prompts:s.z.array(br)}),W=x.extend({method:s.z.literal("prompts/get"),params:P.extend({name:s.z.string(),arguments:s.z.optional(s.z.record(s.z.string()))})}),Y=s.z.object({type:s.z.literal("text"),text:s.z.string()}).passthrough(),Q=s.z.object({type:s.z.literal("image"),data:s.z.string().base64(),mimeType:s.z.string()}).passthrough(),ee=s.z.object({type:s.z.literal("audio"),data:s.z.string().base64(),mimeType:s.z.string()}).passthrough(),tt=s.z.object({type:s.z.literal("resource"),resource:s.z.union([Qe,et])}).passthrough(),vr=s.z.object({role:s.z.enum(["user","assistant"]),content:s.z.union([Y,Q,ee,tt])}).passthrough(),xr=R.extend({description:s.z.optional(s.z.string()),messages:s.z.array(vr)}),Sr=k.extend({method:s.z.literal("notifications/prompts/list_changed")}),Pr=s.z.object({title:s.z.optional(s.z.string()),readOnlyHint:s.z.optional(s.z.boolean()),destructiveHint:s.z.optional(s.z.boolean()),idempotentHint:s.z.optional(s.z.boolean()),openWorldHint:s.z.optional(s.z.boolean())}).passthrough(),Rr=s.z.object({name:s.z.string(),description:s.z.optional(s.z.string()),inputSchema:s.z.object({type:s.z.literal("object"),properties:s.z.optional(s.z.object({}).passthrough())}).passthrough(),annotations:s.z.optional(Pr)}).passthrough(),te=V.extend({method:s.z.literal("tools/list")}),Tr=X.extend({tools:s.z.array(Rr)}),rt=R.extend({content:s.z.array(s.z.union([Y,Q,ee,tt])),isError:s.z.boolean().default(!1).optional()}),to=rt.or(R.extend({toolResult:s.z.unknown()})),re=x.extend({method:s.z.literal("tools/call"),params:P.extend({name:s.z.string(),arguments:s.z.optional(s.z.record(s.z.unknown()))})}),wr=k.extend({method:s.z.literal("notifications/tools/list_changed")}),ot=s.z.enum(["debug","info","notice","warning","error","critical","alert","emergency"]),Cr=x.extend({method:s.z.literal("logging/setLevel"),params:P.extend({level:ot})}),kr=k.extend({method:s.z.literal("notifications/message"),params:L.extend({level:ot,logger:s.z.optional(s.z.string()),data:s.z.unknown()})}),Er=s.z.object({name:s.z.string().optional()}).passthrough(),jr=s.z.object({hints:s.z.optional(s.z.array(Er)),costPriority:s.z.optional(s.z.number().min(0).max(1)),speedPriority:s.z.optional(s.z.number().min(0).max(1)),intelligencePriority:s.z.optional(s.z.number().min(0).max(1))}).passthrough(),Ar=s.z.object({role:s.z.enum(["user","assistant"]),content:s.z.union([Y,Q,ee])}).passthrough(),Nr=x.extend({method:s.z.literal("sampling/createMessage"),params:P.extend({messages:s.z.array(Ar),systemPrompt:s.z.optional(s.z.string()),includeContext:s.z.optional(s.z.enum(["none","thisServer","allServers"])),temperature:s.z.optional(s.z.number()),maxTokens:s.z.number().int(),stopSequences:s.z.optional(s.z.array(s.z.string())),metadata:s.z.optional(s.z.object({}).passthrough()),modelPreferences:s.z.optional(jr)})}),Se=R.extend({model:s.z.string(),stopReason:s.z.optional(s.z.enum(["endTurn","stopSequence","maxTokens"]).or(s.z.string())),role:s.z.enum(["user","assistant"]),content:s.z.discriminatedUnion("type",[Y,Q,ee])}),Or=s.z.object({type:s.z.literal("ref/resource"),uri:s.z.string()}).passthrough(),Ir=s.z.object({type:s.z.literal("ref/prompt"),name:s.z.string()}).passthrough(),oe=x.extend({method:s.z.literal("completion/complete"),params:P.extend({ref:s.z.union([Ir,Or]),argument:s.z.object({name:s.z.string(),value:s.z.string()}).passthrough()})}),Mr=R.extend({completion:s.z.object({values:s.z.array(s.z.string()).max(100),total:s.z.optional(s.z.number().int()),hasMore:s.z.optional(s.z.boolean())}).passthrough()}),Lr=s.z.object({uri:s.z.string().startsWith("file://"),name:s.z.optional(s.z.string())}).passthrough(),Dr=x.extend({method:s.z.literal("roots/list")}),Pe=R.extend({roots:s.z.array(Lr)}),Hr=k.extend({method:s.z.literal("notifications/roots/list_changed")}),ro=s.z.union([z,ve,oe,Cr,W,K,G,J,B,fr,hr,re,te]),oo=s.z.union([Z,U,xe,Hr]),so=s.z.union([F,Se,Pe]),no=s.z.union([z,Nr,Dr]),ao=s.z.union([Z,U,kr,gr,dr,wr,Sr]),io=s.z.union([F,ar,Mr,xr,_r,pr,ur,mr,rt,Tr]),g=class extends Error{constructor(e,t,r){super(`MCP error ${e}: ${t}`),this.code=e,this.data=r,this.name="McpError"}};var $r=6e4,se=class{constructor(e){this._options=e,this._requestMessageId=0,this._requestHandlers=new Map,this._requestHandlerAbortControllers=new Map,this._notificationHandlers=new Map,this._responseHandlers=new Map,this._progressHandlers=new Map,this._timeoutInfo=new Map,this.setNotificationHandler(Z,t=>{let r=this._requestHandlerAbortControllers.get(t.params.requestId);r?.abort(t.params.reason)}),this.setNotificationHandler(U,t=>{this._onprogress(t)}),this.setRequestHandler(z,t=>({}))}_setupTimeout(e,t,r,n,i=!1){this._timeoutInfo.set(e,{timeoutId:setTimeout(n,t),startTime:Date.now(),timeout:t,maxTotalTimeout:r,resetTimeoutOnProgress:i,onTimeout:n})}_resetTimeout(e){let t=this._timeoutInfo.get(e);if(!t)return!1;let r=Date.now()-t.startTime;if(t.maxTotalTimeout&&r>=t.maxTotalTimeout)throw this._timeoutInfo.delete(e),new g(h.RequestTimeout,"Maximum total timeout exceeded",{maxTotalTimeout:t.maxTotalTimeout,totalElapsed:r});return clearTimeout(t.timeoutId),t.timeoutId=setTimeout(t.onTimeout,t.timeout),!0}_cleanupTimeout(e){let t=this._timeoutInfo.get(e);t&&(clearTimeout(t.timeoutId),this._timeoutInfo.delete(e))}async connect(e){this._transport=e,this._transport.onclose=()=>{this._onclose()},this._transport.onerror=t=>{this._onerror(t)},this._transport.onmessage=(t,r)=>{_e(t)||Be(t)?this._onresponse(t):Ue(t)?this._onrequest(t,r):Xe(t)?this._onnotification(t):this._onerror(new Error(`Unknown message type: ${JSON.stringify(t)}`))},await this._transport.start()}_onclose(){var e;let t=this._responseHandlers;this._responseHandlers=new Map,this._progressHandlers.clear(),this._transport=void 0,(e=this.onclose)===null||e===void 0||e.call(this);let r=new g(h.ConnectionClosed,"Connection closed");for(let n of t.values())n(r)}_onerror(e){var t;(t=this.onerror)===null||t===void 0||t.call(this,e)}_onnotification(e){var t;let r=(t=this._notificationHandlers.get(e.method))!==null&&t!==void 0?t:this.fallbackNotificationHandler;r!==void 0&&Promise.resolve().then(()=>r(e)).catch(n=>this._onerror(new Error(`Uncaught error in notification handler: ${n}`)))}_onrequest(e,t){var r,n,i,a;let c=(r=this._requestHandlers.get(e.method))!==null&&r!==void 0?r:this.fallbackRequestHandler;if(c===void 0){(n=this._transport)===null||n===void 0||n.send({jsonrpc:"2.0",id:e.id,error:{code:h.MethodNotFound,message:"Method not found"}}).catch(f=>this._onerror(new Error(`Failed to send an error response: ${f}`)));return}let l=new AbortController;this._requestHandlerAbortControllers.set(e.id,l);let b={signal:l.signal,sessionId:(i=this._transport)===null||i===void 0?void 0:i.sessionId,_meta:(a=e.params)===null||a===void 0?void 0:a._meta,sendNotification:f=>this.notification(f,{relatedRequestId:e.id}),sendRequest:(f,v,E)=>this.request(f,v,{...E,relatedRequestId:e.id}),authInfo:t?.authInfo,requestId:e.id};Promise.resolve().then(()=>c(e,b)).then(f=>{var v;if(!l.signal.aborted)return(v=this._transport)===null||v===void 0?void 0:v.send({result:f,jsonrpc:"2.0",id:e.id})},f=>{var v,E;if(!l.signal.aborted)return(v=this._transport)===null||v===void 0?void 0:v.send({jsonrpc:"2.0",id:e.id,error:{code:Number.isSafeInteger(f.code)?f.code:h.InternalError,message:(E=f.message)!==null&&E!==void 0?E:"Internal error"}})}).catch(f=>this._onerror(new Error(`Failed to send response: ${f}`))).finally(()=>{this._requestHandlerAbortControllers.delete(e.id)})}_onprogress(e){let{progressToken:t,...r}=e.params,n=Number(t),i=this._progressHandlers.get(n);if(!i){this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(e)}`));return}let a=this._responseHandlers.get(n),c=this._timeoutInfo.get(n);if(c&&a&&c.resetTimeoutOnProgress)try{this._resetTimeout(n)}catch(l){a(l);return}i(r)}_onresponse(e){let t=Number(e.id),r=this._responseHandlers.get(t);if(r===void 0){this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(e)}`));return}if(this._responseHandlers.delete(t),this._progressHandlers.delete(t),this._cleanupTimeout(t),_e(e))r(e);else{let n=new g(e.error.code,e.error.message,e.error.data);r(n)}}get transport(){return this._transport}async close(){var e;await((e=this._transport)===null||e===void 0?void 0:e.close())}request(e,t,r){let{relatedRequestId:n,resumptionToken:i,onresumptiontoken:a}=r??{};return new Promise((c,l)=>{var b,f,v,E,ge;if(!this._transport){l(new Error("Not connected"));return}((b=this._options)===null||b===void 0?void 0:b.enforceStrictCapabilities)===!0&&this.assertCapabilityForMethod(e.method),(f=r?.signal)===null||f===void 0||f.throwIfAborted();let C=this._requestMessageId++,Le={...e,jsonrpc:"2.0",id:C};r?.onprogress&&(this._progressHandlers.set(C,r.onprogress),Le.params={...e.params,_meta:{progressToken:C}});let De=S=>{var A;this._responseHandlers.delete(C),this._progressHandlers.delete(C),this._cleanupTimeout(C),(A=this._transport)===null||A===void 0||A.send({jsonrpc:"2.0",method:"notifications/cancelled",params:{requestId:C,reason:String(S)}},{relatedRequestId:n,resumptionToken:i,onresumptiontoken:a}).catch(M=>this._onerror(new Error(`Failed to send cancellation: ${M}`))),l(S)};this._responseHandlers.set(C,S=>{var A;if(!(!((A=r?.signal)===null||A===void 0)&&A.aborted)){if(S instanceof Error)return l(S);try{let M=t.parse(S.result);c(M)}catch(M){l(M)}}}),(v=r?.signal)===null||v===void 0||v.addEventListener("abort",()=>{var S;De((S=r?.signal)===null||S===void 0?void 0:S.reason)});let He=(E=r?.timeout)!==null&&E!==void 0?E:$r,Kt=()=>De(new g(h.RequestTimeout,"Request timed out",{timeout:He}));this._setupTimeout(C,He,r?.maxTotalTimeout,Kt,(ge=r?.resetTimeoutOnProgress)!==null&&ge!==void 0?ge:!1),this._transport.send(Le,{relatedRequestId:n,resumptionToken:i,onresumptiontoken:a}).catch(S=>{this._cleanupTimeout(C),l(S)})})}async notification(e,t){if(!this._transport)throw new Error("Not connected");this.assertNotificationCapability(e.method);let r={...e,jsonrpc:"2.0"};await this._transport.send(r,t)}setRequestHandler(e,t){let r=e.shape.method.value;this.assertRequestHandlerCapability(r),this._requestHandlers.set(r,(n,i)=>Promise.resolve(t(e.parse(n),i)))}removeRequestHandler(e){this._requestHandlers.delete(e)}assertCanSetRequestHandler(e){if(this._requestHandlers.has(e))throw new Error(`A request handler for ${e} already exists, which would be overridden`)}setNotificationHandler(e,t){this._notificationHandlers.set(e.shape.method.value,r=>Promise.resolve(t(e.parse(r))))}removeNotificationHandler(e){this._notificationHandlers.delete(e)}};function st(o,e){return Object.entries(e).reduce((t,[r,n])=>(n&&typeof n=="object"?t[r]=t[r]?{...t[r],...n}:n:t[r]=n,t),{...o})}var ne=class extends se{constructor(e,t){var r;super(t),this._serverInfo=e,this._capabilities=(r=t?.capabilities)!==null&&r!==void 0?r:{},this._instructions=t?.instructions,this.setRequestHandler(ve,n=>this._oninitialize(n)),this.setNotificationHandler(xe,()=>{var n;return(n=this.oninitialized)===null||n===void 0?void 0:n.call(this)})}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=st(this._capabilities,e)}assertCapabilityForMethod(e){var t,r;switch(e){case"sampling/createMessage":if(!(!((t=this._clientCapabilities)===null||t===void 0)&&t.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"roots/list":if(!(!((r=this._clientCapabilities)===null||r===void 0)&&r.roots))throw new Error(`Client does not support listing roots (required for ${e})`);break;case"ping":break}}assertNotificationCapability(e){switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`);break;case"notifications/cancelled":break;case"notifications/progress":break}}assertRequestHandlerCapability(e){switch(e){case"sampling/createMessage":if(!this._capabilities.sampling)throw new Error(`Server does not support sampling (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`);break;case"ping":case"initialize":break}}async _oninitialize(e){let t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:qe.includes(t)?t:be,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},F)}async createMessage(e,t){return this.request({method:"sampling/createMessage",params:e},Se,t)}async listRoots(e,t){return this.request({method:"roots/list",params:e},Pe,t)}async sendLoggingMessage(e){return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}};var at=Symbol("Let zodToJsonSchema decide on which parser to use");var nt={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},it=o=>typeof o=="string"?{...nt,name:o}:{...nt,...o};var ct=o=>{let e=it(o),t=e.name!==void 0?[...e.basePath,e.definitionPath,e.name]:e.basePath;return{...e,currentPath:t,propertyPath:void 0,seen:new Map(Object.entries(e.definitions).map(([r,n])=>[n._def,{def:n._def,path:[...e.basePath,e.definitionPath,r],jsonSchema:void 0}]))}};function Re(o,e,t,r){r?.errorMessages&&t&&(o.errorMessage={...o.errorMessage,[e]:t})}function d(o,e,t,r,n){o[e]=t,Re(o,e,r,n)}var m=require("zod");function lt(){return{}}var pt=require("zod");function ut(o,e){let t={type:"array"};return o.type?._def&&o.type?._def?.typeName!==pt.ZodFirstPartyTypeKind.ZodAny&&(t.items=u(o.type._def,{...e,currentPath:[...e.currentPath,"items"]})),o.minLength&&d(t,"minItems",o.minLength.value,o.minLength.message,e),o.maxLength&&d(t,"maxItems",o.maxLength.value,o.maxLength.message,e),o.exactLength&&(d(t,"minItems",o.exactLength.value,o.exactLength.message,e),d(t,"maxItems",o.exactLength.value,o.exactLength.message,e)),t}function mt(o,e){let t={type:"integer",format:"int64"};if(!o.checks)return t;for(let r of o.checks)switch(r.kind){case"min":e.target==="jsonSchema7"?r.inclusive?d(t,"minimum",r.value,r.message,e):d(t,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(t.exclusiveMinimum=!0),d(t,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?d(t,"maximum",r.value,r.message,e):d(t,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(t.exclusiveMaximum=!0),d(t,"maximum",r.value,r.message,e));break;case"multipleOf":d(t,"multipleOf",r.value,r.message,e);break}return t}function dt(){return{type:"boolean"}}function ae(o,e){return u(o.type._def,e)}var ft=(o,e)=>u(o.innerType._def,e);function Te(o,e,t){let r=t??e.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((n,i)=>Te(o,e,n))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return qr(o,e)}}var qr=(o,e)=>{let t={type:"integer",format:"unix-time"};if(e.target==="openApi3")return t;for(let r of o.checks)switch(r.kind){case"min":d(t,"minimum",r.value,r.message,e);break;case"max":d(t,"maximum",r.value,r.message,e);break}return t};function ht(o,e){return{...u(o.innerType._def,e),default:o.defaultValue()}}function gt(o,e){return e.effectStrategy==="input"?u(o.schema._def,e):{}}function yt(o){return{type:"string",enum:Array.from(o.values)}}var Fr=o=>"type"in o&&o.type==="string"?!1:"allOf"in o;function bt(o,e){let t=[u(o.left._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),u(o.right._def,{...e,currentPath:[...e.currentPath,"allOf","1"]})].filter(i=>!!i),r=e.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0,n=[];return t.forEach(i=>{if(Fr(i))n.push(...i.allOf),i.unevaluatedProperties===void 0&&(r=void 0);else{let a=i;if("additionalProperties"in i&&i.additionalProperties===!1){let{additionalProperties:c,...l}=i;a=l}else r=void 0;n.push(a)}}),n.length?{allOf:n,...r}:void 0}function _t(o,e){let t=typeof o.value;return t!=="bigint"&&t!=="number"&&t!=="boolean"&&t!=="string"?{type:Array.isArray(o.value)?"array":"object"}:e.target==="openApi3"?{type:t==="bigint"?"integer":t,enum:[o.value]}:{type:t==="bigint"?"integer":t,const:o.value}}var N=require("zod");var we,T={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(we===void 0&&(we=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),we),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?: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])$/,ipv4Cidr:/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function ie(o,e){let t={type:"string"};if(o.checks)for(let r of o.checks)switch(r.kind){case"min":d(t,"minLength",typeof t.minLength=="number"?Math.max(t.minLength,r.value):r.value,r.message,e);break;case"max":d(t,"maxLength",typeof t.maxLength=="number"?Math.min(t.maxLength,r.value):r.value,r.message,e);break;case"email":switch(e.emailStrategy){case"format:email":w(t,"email",r.message,e);break;case"format:idn-email":w(t,"idn-email",r.message,e);break;case"pattern:zod":_(t,T.email,r.message,e);break}break;case"url":w(t,"uri",r.message,e);break;case"uuid":w(t,"uuid",r.message,e);break;case"regex":_(t,r.regex,r.message,e);break;case"cuid":_(t,T.cuid,r.message,e);break;case"cuid2":_(t,T.cuid2,r.message,e);break;case"startsWith":_(t,RegExp(`^${Ce(r.value,e)}`),r.message,e);break;case"endsWith":_(t,RegExp(`${Ce(r.value,e)}$`),r.message,e);break;case"datetime":w(t,"date-time",r.message,e);break;case"date":w(t,"date",r.message,e);break;case"time":w(t,"time",r.message,e);break;case"duration":w(t,"duration",r.message,e);break;case"length":d(t,"minLength",typeof t.minLength=="number"?Math.max(t.minLength,r.value):r.value,r.message,e),d(t,"maxLength",typeof t.maxLength=="number"?Math.min(t.maxLength,r.value):r.value,r.message,e);break;case"includes":{_(t,RegExp(Ce(r.value,e)),r.message,e);break}case"ip":{r.version!=="v6"&&w(t,"ipv4",r.message,e),r.version!=="v4"&&w(t,"ipv6",r.message,e);break}case"base64url":_(t,T.base64url,r.message,e);break;case"jwt":_(t,T.jwt,r.message,e);break;case"cidr":{r.version!=="v6"&&_(t,T.ipv4Cidr,r.message,e),r.version!=="v4"&&_(t,T.ipv6Cidr,r.message,e);break}case"emoji":_(t,T.emoji(),r.message,e);break;case"ulid":{_(t,T.ulid,r.message,e);break}case"base64":{switch(e.base64Strategy){case"format:binary":{w(t,"binary",r.message,e);break}case"contentEncoding:base64":{d(t,"contentEncoding","base64",r.message,e);break}case"pattern:zod":{_(t,T.base64,r.message,e);break}}break}case"nanoid":_(t,T.nanoid,r.message,e);case"toLowerCase":case"toUpperCase":case"trim":break;default:}return t}function Ce(o,e){return e.patternStrategy==="escape"?zr(o):o}var Zr=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function zr(o){let e="";for(let t=0;t<o.length;t++)Zr.has(o[t])||(e+="\\"),e+=o[t];return e}function w(o,e,t,r){o.format||o.anyOf?.some(n=>n.format)?(o.anyOf||(o.anyOf=[]),o.format&&(o.anyOf.push({format:o.format,...o.errorMessage&&r.errorMessages&&{errorMessage:{format:o.errorMessage.format}}}),delete o.format,o.errorMessage&&(delete o.errorMessage.format,Object.keys(o.errorMessage).length===0&&delete o.errorMessage)),o.anyOf.push({format:e,...t&&r.errorMessages&&{errorMessage:{format:t}}})):d(o,"format",e,t,r)}function _(o,e,t,r){o.pattern||o.allOf?.some(n=>n.pattern)?(o.allOf||(o.allOf=[]),o.pattern&&(o.allOf.push({pattern:o.pattern,...o.errorMessage&&r.errorMessages&&{errorMessage:{pattern:o.errorMessage.pattern}}}),delete o.pattern,o.errorMessage&&(delete o.errorMessage.pattern,Object.keys(o.errorMessage).length===0&&delete o.errorMessage)),o.allOf.push({pattern:vt(e,r),...t&&r.errorMessages&&{errorMessage:{pattern:t}}})):d(o,"pattern",vt(e,r),t,r)}function vt(o,e){if(!e.applyRegexFlags||!o.flags)return o.source;let t={i:o.flags.includes("i"),m:o.flags.includes("m"),s:o.flags.includes("s")},r=t.i?o.source.toLowerCase():o.source,n="",i=!1,a=!1,c=!1;for(let l=0;l<r.length;l++){if(i){n+=r[l],i=!1;continue}if(t.i){if(a){if(r[l].match(/[a-z]/)){c?(n+=r[l],n+=`${r[l-2]}-${r[l]}`.toUpperCase(),c=!1):r[l+1]==="-"&&r[l+2]?.match(/[a-z]/)?(n+=r[l],c=!0):n+=`${r[l]}${r[l].toUpperCase()}`;continue}}else if(r[l].match(/[a-z]/)){n+=`[${r[l]}${r[l].toUpperCase()}]`;continue}}if(t.m){if(r[l]==="^"){n+=`(^|(?<=[\r
|
3
|
+
]))`;continue}else if(r[l]==="$"){n+=`($|(?=[\r
|
4
|
+
]))`;continue}}if(t.s&&r[l]==="."){n+=a?`${r[l]}\r
|
5
|
+
`:`[${r[l]}\r
|
6
|
+
]`;continue}n+=r[l],r[l]==="\\"?i=!0:a&&r[l]==="]"?a=!1:!a&&r[l]==="["&&(a=!0)}try{new RegExp(n)}catch{return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),o.source}return n}function ce(o,e){if(e.target==="openAi"&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),e.target==="openApi3"&&o.keyType?._def.typeName===N.ZodFirstPartyTypeKind.ZodEnum)return{type:"object",required:o.keyType._def.values,properties:o.keyType._def.values.reduce((r,n)=>({...r,[n]:u(o.valueType._def,{...e,currentPath:[...e.currentPath,"properties",n]})??{}}),{}),additionalProperties:e.rejectedAdditionalProperties};let t={type:"object",additionalProperties:u(o.valueType._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]})??e.allowedAdditionalProperties};if(e.target==="openApi3")return t;if(o.keyType?._def.typeName===N.ZodFirstPartyTypeKind.ZodString&&o.keyType._def.checks?.length){let{type:r,...n}=ie(o.keyType._def,e);return{...t,propertyNames:n}}else{if(o.keyType?._def.typeName===N.ZodFirstPartyTypeKind.ZodEnum)return{...t,propertyNames:{enum:o.keyType._def.values}};if(o.keyType?._def.typeName===N.ZodFirstPartyTypeKind.ZodBranded&&o.keyType._def.type._def.typeName===N.ZodFirstPartyTypeKind.ZodString&&o.keyType._def.type._def.checks?.length){let{type:r,...n}=ae(o.keyType._def,e);return{...t,propertyNames:n}}}return t}function xt(o,e){if(e.mapStrategy==="record")return ce(o,e);let t=u(o.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},r=u(o.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{};return{type:"array",maxItems:125,items:{type:"array",items:[t,r],minItems:2,maxItems:2}}}function St(o){let e=o.values,r=Object.keys(o.values).filter(i=>typeof e[e[i]]!="number").map(i=>e[i]),n=Array.from(new Set(r.map(i=>typeof i)));return{type:n.length===1?n[0]==="string"?"string":"number":["string","number"],enum:r}}function Pt(){return{not:{}}}function Rt(o){return o.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var D={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function wt(o,e){if(e.target==="openApi3")return Tt(o,e);let t=o.options instanceof Map?Array.from(o.options.values()):o.options;if(t.every(r=>r._def.typeName in D&&(!r._def.checks||!r._def.checks.length))){let r=t.reduce((n,i)=>{let a=D[i._def.typeName];return a&&!n.includes(a)?[...n,a]:n},[]);return{type:r.length>1?r:r[0]}}else if(t.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){let r=t.reduce((n,i)=>{let a=typeof i._def.value;switch(a){case"string":case"number":case"boolean":return[...n,a];case"bigint":return[...n,"integer"];case"object":if(i._def.value===null)return[...n,"null"];case"symbol":case"undefined":case"function":default:return n}},[]);if(r.length===t.length){let n=r.filter((i,a,c)=>c.indexOf(i)===a);return{type:n.length>1?n:n[0],enum:t.reduce((i,a)=>i.includes(a._def.value)?i:[...i,a._def.value],[])}}}else if(t.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:t.reduce((r,n)=>[...r,...n._def.values.filter(i=>!r.includes(i))],[])};return Tt(o,e)}var Tt=(o,e)=>{let t=(o.options instanceof Map?Array.from(o.options.values()):o.options).map((r,n)=>u(r._def,{...e,currentPath:[...e.currentPath,"anyOf",`${n}`]})).filter(r=>!!r&&(!e.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return t.length?{anyOf:t}:void 0};function Ct(o,e){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(o.innerType._def.typeName)&&(!o.innerType._def.checks||!o.innerType._def.checks.length))return e.target==="openApi3"?{type:D[o.innerType._def.typeName],nullable:!0}:{type:[D[o.innerType._def.typeName],"null"]};if(e.target==="openApi3"){let r=u(o.innerType._def,{...e,currentPath:[...e.currentPath]});return r&&"$ref"in r?{allOf:[r],nullable:!0}:r&&{...r,nullable:!0}}let t=u(o.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","0"]});return t&&{anyOf:[t,{type:"null"}]}}function kt(o,e){let t={type:"number"};if(!o.checks)return t;for(let r of o.checks)switch(r.kind){case"int":t.type="integer",Re(t,"type",r.message,e);break;case"min":e.target==="jsonSchema7"?r.inclusive?d(t,"minimum",r.value,r.message,e):d(t,"exclusiveMinimum",r.value,r.message,e):(r.inclusive||(t.exclusiveMinimum=!0),d(t,"minimum",r.value,r.message,e));break;case"max":e.target==="jsonSchema7"?r.inclusive?d(t,"maximum",r.value,r.message,e):d(t,"exclusiveMaximum",r.value,r.message,e):(r.inclusive||(t.exclusiveMaximum=!0),d(t,"maximum",r.value,r.message,e));break;case"multipleOf":d(t,"multipleOf",r.value,r.message,e);break}return t}var Et=require("zod");function jt(o,e){let t=e.target==="openAi",r={type:"object",properties:{}},n=[],i=o.shape();for(let c in i){let l=i[c];if(l===void 0||l._def===void 0)continue;let b=Vr(l);b&&t&&(l instanceof Et.ZodOptional&&(l=l._def.innerType),l.isNullable()||(l=l.nullable()),b=!1);let f=u(l._def,{...e,currentPath:[...e.currentPath,"properties",c],propertyPath:[...e.currentPath,"properties",c]});f!==void 0&&(r.properties[c]=f,b||n.push(c))}n.length&&(r.required=n);let a=Ur(o,e);return a!==void 0&&(r.additionalProperties=a),r}function Ur(o,e){if(o.catchall._def.typeName!=="ZodNever")return u(o.catchall._def,{...e,currentPath:[...e.currentPath,"additionalProperties"]});switch(o.unknownKeys){case"passthrough":return e.allowedAdditionalProperties;case"strict":return e.rejectedAdditionalProperties;case"strip":return e.removeAdditionalStrategy==="strict"?e.allowedAdditionalProperties:e.rejectedAdditionalProperties}}function Vr(o){try{return o.isOptional()}catch{return!0}}var At=(o,e)=>{if(e.currentPath.toString()===e.propertyPath?.toString())return u(o.innerType._def,e);let t=u(o.innerType._def,{...e,currentPath:[...e.currentPath,"anyOf","1"]});return t?{anyOf:[{not:{}},t]}:{}};var Nt=(o,e)=>{if(e.pipeStrategy==="input")return u(o.in._def,e);if(e.pipeStrategy==="output")return u(o.out._def,e);let t=u(o.in._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),r=u(o.out._def,{...e,currentPath:[...e.currentPath,"allOf",t?"1":"0"]});return{allOf:[t,r].filter(n=>n!==void 0)}};function Ot(o,e){return u(o.type._def,e)}function It(o,e){let r={type:"array",uniqueItems:!0,items:u(o.valueType._def,{...e,currentPath:[...e.currentPath,"items"]})};return o.minSize&&d(r,"minItems",o.minSize.value,o.minSize.message,e),o.maxSize&&d(r,"maxItems",o.maxSize.value,o.maxSize.message,e),r}function Mt(o,e){return o.rest?{type:"array",minItems:o.items.length,items:o.items.map((t,r)=>u(t._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((t,r)=>r===void 0?t:[...t,r],[]),additionalItems:u(o.rest._def,{...e,currentPath:[...e.currentPath,"additionalItems"]})}:{type:"array",minItems:o.items.length,maxItems:o.items.length,items:o.items.map((t,r)=>u(t._def,{...e,currentPath:[...e.currentPath,"items",`${r}`]})).reduce((t,r)=>r===void 0?t:[...t,r],[])}}function Lt(){return{not:{}}}function Dt(){return{}}var Ht=(o,e)=>u(o.innerType._def,e);var $t=(o,e,t)=>{switch(e){case m.ZodFirstPartyTypeKind.ZodString:return ie(o,t);case m.ZodFirstPartyTypeKind.ZodNumber:return kt(o,t);case m.ZodFirstPartyTypeKind.ZodObject:return jt(o,t);case m.ZodFirstPartyTypeKind.ZodBigInt:return mt(o,t);case m.ZodFirstPartyTypeKind.ZodBoolean:return dt();case m.ZodFirstPartyTypeKind.ZodDate:return Te(o,t);case m.ZodFirstPartyTypeKind.ZodUndefined:return Lt();case m.ZodFirstPartyTypeKind.ZodNull:return Rt(t);case m.ZodFirstPartyTypeKind.ZodArray:return ut(o,t);case m.ZodFirstPartyTypeKind.ZodUnion:case m.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:return wt(o,t);case m.ZodFirstPartyTypeKind.ZodIntersection:return bt(o,t);case m.ZodFirstPartyTypeKind.ZodTuple:return Mt(o,t);case m.ZodFirstPartyTypeKind.ZodRecord:return ce(o,t);case m.ZodFirstPartyTypeKind.ZodLiteral:return _t(o,t);case m.ZodFirstPartyTypeKind.ZodEnum:return yt(o);case m.ZodFirstPartyTypeKind.ZodNativeEnum:return St(o);case m.ZodFirstPartyTypeKind.ZodNullable:return Ct(o,t);case m.ZodFirstPartyTypeKind.ZodOptional:return At(o,t);case m.ZodFirstPartyTypeKind.ZodMap:return xt(o,t);case m.ZodFirstPartyTypeKind.ZodSet:return It(o,t);case m.ZodFirstPartyTypeKind.ZodLazy:return()=>o.getter()._def;case m.ZodFirstPartyTypeKind.ZodPromise:return Ot(o,t);case m.ZodFirstPartyTypeKind.ZodNaN:case m.ZodFirstPartyTypeKind.ZodNever:return Pt();case m.ZodFirstPartyTypeKind.ZodEffects:return gt(o,t);case m.ZodFirstPartyTypeKind.ZodAny:return lt();case m.ZodFirstPartyTypeKind.ZodUnknown:return Dt();case m.ZodFirstPartyTypeKind.ZodDefault:return ht(o,t);case m.ZodFirstPartyTypeKind.ZodBranded:return ae(o,t);case m.ZodFirstPartyTypeKind.ZodReadonly:return Ht(o,t);case m.ZodFirstPartyTypeKind.ZodCatch:return ft(o,t);case m.ZodFirstPartyTypeKind.ZodPipeline:return Nt(o,t);case m.ZodFirstPartyTypeKind.ZodFunction:case m.ZodFirstPartyTypeKind.ZodVoid:case m.ZodFirstPartyTypeKind.ZodSymbol:return;default:return(r=>{})(e)}};function u(o,e,t=!1){let r=e.seen.get(o);if(e.override){let c=e.override?.(o,e,r,t);if(c!==at)return c}if(r&&!t){let c=Xr(r,e);if(c!==void 0)return c}let n={def:o,path:e.currentPath,jsonSchema:void 0};e.seen.set(o,n);let i=$t(o,o.typeName,e),a=typeof i=="function"?u(i(),e):i;if(a&&Jr(o,e,a),e.postProcess){let c=e.postProcess(a,o,e);return n.jsonSchema=a,c}return n.jsonSchema=a,a}var Xr=(o,e)=>{switch(e.$refStrategy){case"root":return{$ref:o.path.join("/")};case"relative":return{$ref:Gr(e.currentPath,o.path)};case"none":case"seen":return o.path.length<e.currentPath.length&&o.path.every((t,r)=>e.currentPath[r]===t)?(console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`),{}):e.$refStrategy==="seen"?{}:void 0}},Gr=(o,e)=>{let t=0;for(;t<o.length&&t<e.length&&o[t]===e[t];t++);return[(o.length-t).toString(),...e.slice(t)].join("/")},Jr=(o,e,t)=>(o.description&&(t.description=o.description,e.markdownDescription&&(t.markdownDescription=o.description)),t);var ke=(o,e)=>{let t=ct(e),r=typeof e=="object"&&e.definitions?Object.entries(e.definitions).reduce((l,[b,f])=>({...l,[b]:u(f._def,{...t,currentPath:[...t.basePath,t.definitionPath,b]},!0)??{}}),{}):void 0,n=typeof e=="string"?e:e?.nameStrategy==="title"?void 0:e?.name,i=u(o._def,n===void 0?t:{...t,currentPath:[...t.basePath,t.definitionPath,n]},!1)??{},a=typeof e=="object"&&e.name!==void 0&&e.nameStrategy==="title"?e.name:void 0;a!==void 0&&(i.title=a);let c=n===void 0?r?{...i,[t.definitionPath]:r}:i:{$ref:[...t.$refStrategy==="relative"?[]:t.basePath,t.definitionPath,n].join("/"),[t.definitionPath]:{...r,[n]:i}};return t.target==="jsonSchema7"?c.$schema="http://json-schema.org/draft-07/schema#":(t.target==="jsonSchema2019-09"||t.target==="openAi")&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),t.target==="openAi"&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c};var H=require("zod");var qt=require("zod"),Ee;(function(o){o.Completable="McpCompletable"})(Ee||(Ee={}));var O=class extends qt.ZodType{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}};O.create=(o,e)=>new O({type:o,typeName:Ee.Completable,complete:e.complete,...Br(e)});function Br(o){if(!o)return{};let{errorMap:e,invalid_type_error:t,required_error:r,description:n}=o;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:n}:{errorMap:(a,c)=>{var l,b;let{message:f}=o;return a.code==="invalid_enum_value"?{message:f??c.defaultError}:typeof c.data>"u"?{message:(l=f??r)!==null&&l!==void 0?l:c.defaultError}:a.code!=="invalid_type"?{message:c.defaultError}:{message:(b=f??t)!==null&&b!==void 0?b:c.defaultError}},description:n}}var pe=class{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new ne(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(te.shape.method.value),this.server.assertCanSetRequestHandler(re.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(te,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,description:t.description,inputSchema:t.inputSchema?ke(t.inputSchema,{strictUnions:!0}):Kr,annotations:t.annotations}))})),this.server.setRequestHandler(re,async(e,t)=>{let r=this._registeredTools[e.params.name];if(!r)throw new g(h.InvalidParams,`Tool ${e.params.name} not found`);if(!r.enabled)throw new g(h.InvalidParams,`Tool ${e.params.name} disabled`);if(r.inputSchema){let n=await r.inputSchema.safeParseAsync(e.params.arguments);if(!n.success)throw new g(h.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${n.error.message}`);let i=n.data,a=r.callback;try{return await Promise.resolve(a(i,t))}catch(c){return{content:[{type:"text",text:c instanceof Error?c.message:String(c)}],isError:!0}}}else{let n=r.callback;try{return await Promise.resolve(n(t))}catch(i){return{content:[{type:"text",text:i instanceof Error?i.message:String(i)}],isError:!0}}}}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(oe.shape.method.value),this.server.setRequestHandler(oe,async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new g(h.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){let r=this._registeredPrompts[t.name];if(!r)throw new g(h.InvalidParams,`Prompt ${t.name} not found`);if(!r.enabled)throw new g(h.InvalidParams,`Prompt ${t.name} disabled`);if(!r.argsSchema)return le;let n=r.argsSchema.shape[e.params.argument.name];if(!(n instanceof O))return le;let a=await n._def.complete(e.params.argument.value);return Zt(a)}async handleResourceCompletion(e,t){let r=Object.values(this._registeredResourceTemplates).find(a=>a.resourceTemplate.uriTemplate.toString()===t.uri);if(!r){if(this._registeredResources[t.uri])return le;throw new g(h.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}let n=r.resourceTemplate.completeCallback(e.params.argument.name);if(!n)return le;let i=await n(e.params.argument.value);return Zt(i)}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(G.shape.method.value),this.server.assertCanSetRequestHandler(J.shape.method.value),this.server.assertCanSetRequestHandler(B.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(G,async(e,t)=>{let r=Object.entries(this._registeredResources).filter(([i,a])=>a.enabled).map(([i,a])=>({uri:i,name:a.name,...a.metadata})),n=[];for(let i of Object.values(this._registeredResourceTemplates)){if(!i.resourceTemplate.listCallback)continue;let a=await i.resourceTemplate.listCallback(t);for(let c of a.resources)n.push({...c,...i.metadata})}return{resources:[...r,...n]}}),this.server.setRequestHandler(J,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([t,r])=>({name:t,uriTemplate:r.resourceTemplate.uriTemplate.toString(),...r.metadata}))})),this.server.setRequestHandler(B,async(e,t)=>{let r=new URL(e.params.uri),n=this._registeredResources[r.toString()];if(n){if(!n.enabled)throw new g(h.InvalidParams,`Resource ${r} disabled`);return n.readCallback(r,t)}for(let i of Object.values(this._registeredResourceTemplates)){let a=i.resourceTemplate.uriTemplate.match(r.toString());if(a)return i.readCallback(r,a,t)}throw new g(h.InvalidParams,`Resource ${r} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(K.shape.method.value),this.server.assertCanSetRequestHandler(W.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(K,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,t])=>({name:e,description:t.description,arguments:t.argsSchema?Yr(t.argsSchema):void 0}))})),this.server.setRequestHandler(W,async(e,t)=>{let r=this._registeredPrompts[e.params.name];if(!r)throw new g(h.InvalidParams,`Prompt ${e.params.name} not found`);if(!r.enabled)throw new g(h.InvalidParams,`Prompt ${e.params.name} disabled`);if(r.argsSchema){let n=await r.argsSchema.safeParseAsync(e.params.arguments);if(!n.success)throw new g(h.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${n.error.message}`);let i=n.data,a=r.callback;return await Promise.resolve(a(i,t))}else{let n=r.callback;return await Promise.resolve(n(t))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...r){let n;typeof r[0]=="object"&&(n=r.shift());let i=r[0];if(typeof t=="string"){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);let a={name:e,metadata:n,readCallback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({uri:null}),update:c=>{typeof c.uri<"u"&&c.uri!==t&&(delete this._registeredResources[t],c.uri&&(this._registeredResources[c.uri]=a)),typeof c.name<"u"&&(a.name=c.name),typeof c.metadata<"u"&&(a.metadata=c.metadata),typeof c.callback<"u"&&(a.readCallback=c.callback),typeof c.enabled<"u"&&(a.enabled=c.enabled),this.sendResourceListChanged()}};return this._registeredResources[t]=a,this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}else{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);let a={resourceTemplate:t,metadata:n,readCallback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:c=>{typeof c.name<"u"&&c.name!==e&&(delete this._registeredResourceTemplates[e],c.name&&(this._registeredResourceTemplates[c.name]=a)),typeof c.template<"u"&&(a.resourceTemplate=c.template),typeof c.metadata<"u"&&(a.metadata=c.metadata),typeof c.callback<"u"&&(a.readCallback=c.callback),typeof c.enabled<"u"&&(a.enabled=c.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=a,this.setResourceRequestHandlers(),this.sendResourceListChanged(),a}}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let r;typeof t[0]=="string"&&(r=t.shift());let n,i;if(t.length>1){let l=t[0];Ft(l)?(n=t.shift(),t.length>1&&typeof t[0]=="object"&&t[0]!==null&&!Ft(t[0])&&(i=t.shift())):typeof l=="object"&&l!==null&&(i=t.shift())}let a=t[0],c={description:r,inputSchema:n===void 0?void 0:H.z.object(n),annotations:i,callback:a,enabled:!0,disable:()=>c.update({enabled:!1}),enable:()=>c.update({enabled:!0}),remove:()=>c.update({name:null}),update:l=>{typeof l.name<"u"&&l.name!==e&&(delete this._registeredTools[e],l.name&&(this._registeredTools[l.name]=c)),typeof l.description<"u"&&(c.description=l.description),typeof l.paramsSchema<"u"&&(c.inputSchema=H.z.object(l.paramsSchema)),typeof l.callback<"u"&&(c.callback=l.callback),typeof l.annotations<"u"&&(c.annotations=l.annotations),typeof l.enabled<"u"&&(c.enabled=l.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=c,this.setToolRequestHandlers(),this.sendToolListChanged(),c}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let r;typeof t[0]=="string"&&(r=t.shift());let n;t.length>1&&(n=t.shift());let i=t[0],a={description:r,argsSchema:n===void 0?void 0:H.z.object(n),callback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:c=>{typeof c.name<"u"&&c.name!==e&&(delete this._registeredPrompts[e],c.name&&(this._registeredPrompts[c.name]=a)),typeof c.description<"u"&&(a.description=c.description),typeof c.argsSchema<"u"&&(a.argsSchema=H.z.object(c.argsSchema)),typeof c.callback<"u"&&(a.callback=c.callback),typeof c.enabled<"u"&&(a.enabled=c.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=a,this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}isConnected(){return this.server.transport!==void 0}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}};var Kr={type:"object"};function Ft(o){return typeof o!="object"||o===null?!1:Object.keys(o).length===0||Object.values(o).some(Wr)}function Wr(o){return o!==null&&typeof o=="object"&&"parse"in o&&typeof o.parse=="function"&&"safeParse"in o&&typeof o.safeParse=="function"}function Yr(o){return Object.entries(o.shape).map(([e,t])=>({name:e,description:t.description,required:!t.isOptional()}))}function Zt(o){return{completion:{values:o.slice(0,100),total:o.length,hasMore:o.length>100}}}var le={completion:{values:[],hasMore:!1}};var ue=process.env.personalToken||""||"",zt="F2C MCP",Ut="0.2.0";var je=class{constructor(){this.f2cHost="https://f2c-figma-api.yy.com/api";this.personalToken=ue}async nodeToCode(e){let t={fileKey:e.fileKey,nodeIds:e.ids,personal_token:e.personalToken||this.personalToken,option:{cssFramework:"inlinecss",imgFormat:e.imgFormat||"png",scaleSize:e.scaleSize||2},format:"files"};e.format==="react-cssmodules"?t.option.cssFramework="cssmodules":e.format==="react-tailwind"&&(t.option.cssFramework="tailwindcss");let r=this.opToUrl(`${this.f2cHost}/nodes`,t);return this.fetch(r,"json")}async fetch(e,t="json"){try{let n=await fetch(e,{method:"GET"});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return t==="text"?await n.text():await n.json()}catch(r){throw console.error("HTTP error",r),r}}opToUrl(e,t={}){if(Object.keys(t).length===0)return e;let r=new URL(e);for(let[n,i]of Object.entries(t))if(typeof i=="object"&&i!==null)for(let[a,c]of Object.entries(i))r.searchParams.append(`${n}[${a}]`,c);else r.searchParams.append(n,i);return r.toString()}},Vt=new je;var j=require("zod");var me=ye(require("fs")),I=ye(require("path")),Ae=class{constructor(){this.imgFormat="png"}setImgFormat(e){this.imgFormat=e}async downloadImage(e,t){try{me.default.existsSync(t.localPath)||me.default.mkdirSync(t.localPath,{recursive:!0});let r=`${t.fileName}.${this.imgFormat}`,n=I.default.join(t.localPath,r),i=await fetch(e);if(!i.ok)throw new Error(`\u4E0B\u8F7D\u5931\u8D25: ${i.status} ${i.statusText}`);let a=await i.arrayBuffer();return me.default.writeFileSync(n,new Uint8Array(a)),I.default.join(I.default.basename(t.localPath),r).replace(/\\/g,"/")}catch(r){throw console.error("\u56FE\u7247\u4E0B\u8F7D\u9519\u8BEF:",r),r}}async processContent(e,t){t=I.default.join(t,"images");try{let r=/https:\/\/figma-alpha-api\.s3\.us-west-2\.amazonaws\.com\/images\/[a-f0-9-]+/g,n=e.match(r);if(!n)return e;let i=e;for(let a of n){let c=I.default.basename(a),l=await this.downloadImage(a,{localPath:t,fileName:c});i=i.replace(a,l)}return i}catch(r){throw console.error("\u5185\u5BB9\u5904\u7406\u9519\u8BEF:",r),r}}},Ne=new Ae;var Xt=o=>{o.tool("figma_to_code","Transform Figma designs into production-ready code. This tool converts selected Figma nodes into HTML, React with CSS Modules, or React with Tailwind CSS, enabling seamless design-to-code workflow.",{fileKey:j.z.string().describe("The Figma file identifier found in the file URL (e.g., https://www.figma.com/file/XXXXXXXXXXXX/). Extract the XXXXXXXXXXXX portion as the fileKey."),ids:j.z.string().describe('Comma-separated list of Figma node IDs for conversion. To obtain node IDs, select elements in Figma, right-click and select "Copy/Paste as" \u2192 "Copy ID".'),format:j.z.enum(["html","react-cssmodules","react-tailwind"]).default("html").describe('Specify the output format: "html" generates semantic HTML/CSS, "react-cssmodules" creates React components with scoped CSS modules, "react-tailwind" produces React components with utility-first Tailwind classes.'),personalToken:j.z.string().optional().describe("Figma personal access token for API authentication"),localPath:j.z.string().optional().describe("Absolute path for image asset storage. Directory will be created if non-existent. Path must follow OS-specific format without special character escaping."),imgFormat:j.z.enum(["png","jpg","svg"]).default("png").describe('Export format for image assets: "png" for lossless quality, "jpg" for compressed files, or "svg" for vector graphics.'),scaleSize:j.z.number().min(1).max(4).default(2).describe("Image export scale factor (1-4). Higher values yield better quality at the cost of larger file sizes.")},async e=>{try{let t=await Vt.nodeToCode(e)||[];return e.localPath&&(Ne.setImgFormat(e.imgFormat),await Promise.all(t.map(async r=>{r.content=await Ne.processContent(r.content,e.localPath)}))),{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return console.error("Tool execution error:",t),{content:[{type:"text",text:`Error: ${t.message}`}]}}})};var Oe=class{constructor(){this.figmaHost="https://api.figma.com/v1";this.personalToken=ue}async files(e){let t;return e.ids?t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}/nodes`,e):t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}`,e),this.fetch(t)}async images(e){let t=this.opToUrl(`${this.figmaHost}/images/${e.fileKey}`,e);return this.fetch(t)}async imageFills(e){let t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}/images`,e);return this.fetch(t)}async meta(e){let t=this.opToUrl(`${this.figmaHost}/files/${e.fileKey}/meta`,e);return this.fetch(t)}async fetch(e,t="json"){try{let r={method:"GET",headers:{"X-FIGMA-TOKEN":this.personalToken}},n=await fetch(e,r);if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return t==="text"?await n.text():await n.json()}catch(r){throw console.error("HTTP error",r),r}}opToUrl(e,t={},r=["fileKey","personalToken"]){if(Object.keys(t).length===0)return e;t.personalToken&&(this.personalToken=t.personalToken);let n=new URL(e);for(let[i,a]of Object.entries(t))r.includes(i)||n.searchParams.append(i,a);return n.toString()}},Ie=new Oe;var y=require("zod"),Gt=o=>{o.tool("figma_get_file_data","Get detailed information about a Figma file",{fileKey:y.z.string().describe("Unique identifier of the Figma file"),ids:y.z.string().describe("List of node IDs to retrieve, comma separated"),personalToken:y.z.string().optional().describe("Your Figma personal access token"),version:y.z.string().optional().describe("Specify the version to return"),depth:y.z.number().optional().describe("Specify the depth of nodes to return"),geometry:y.z.enum(["paths"]).optional().describe("Specify whether to include geometry path data"),plugin_data:y.z.string().optional().describe("Specify plugin data to return"),branch_data:y.z.boolean().optional().describe("Specify whether to return branch data")},async e=>{try{let t=await Ie.files(e);return{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return{content:[{type:"text",text:`Error: ${t.message}`}]}}}),o.tool("figma_get_images","Get images of Figma nodes",{fileKey:y.z.string().describe("Unique identifier of the Figma file"),ids:y.z.string().describe("Node IDs to get images for, comma separated"),format:y.z.enum(["jpg","png","svg","pdf"]).optional().describe("Image format, e.g., png, jpg, svg"),scale:y.z.number().optional().describe("Image scale factor"),svg_include_id:y.z.boolean().optional().describe("Whether SVG includes ID"),svg_simplify_stroke:y.z.boolean().optional().describe("Whether to simplify SVG strokes"),use_absolute_bounds:y.z.boolean().optional().describe("Whether to use absolute bounds"),version:y.z.string().optional().describe("Specify the version to return"),personalToken:y.z.string().optional().describe("Your Figma personal access token")},async e=>{try{let t=await Ie.images(e);return{content:[{type:"text",text:JSON.stringify(t)}]}}catch(t){return{content:[{type:"text",text:`Error: ${t.message}`}]}}})};var de=new pe({name:zt,version:Ut},{capabilities:{logging:{}}});Gt(de);Xt(de);var Me=ye(require("process"),1);var fe=class{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;let e=this._buffer.indexOf(`
|
7
|
+
`);if(e===-1)return null;let t=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),Qr(t)}clear(){this._buffer=void 0}};function Qr(o){return Ke.parse(JSON.parse(o))}function Jt(o){return JSON.stringify(o)+`
|
8
|
+
`}var he=class{constructor(e=Me.default.stdin,t=Me.default.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new fe,this._started=!1,this._ondata=r=>{this._readBuffer.append(r),this.processReadBuffer()},this._onerror=r=>{var n;(n=this.onerror)===null||n===void 0||n.call(this,r)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(var e,t;;)try{let r=this._readBuffer.readMessage();if(r===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,r)}catch(r){(t=this.onerror)===null||t===void 0||t.call(this,r)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),(e=this.onclose)===null||e===void 0||e.call(this)}send(e){return new Promise(t=>{let r=Jt(e);this._stdout.write(r)?t():this._stdout.once("drain",t)})}};async function Bt(o){try{let e=new he;await o.connect(e)}catch(e){console.log(JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32e3,message:`Server startup failed: ${e.message}`}})),process.exit(1)}}Bt(de);
|