@vleap/warps-mcp 1.0.0-beta.16 → 1.0.0-beta.18
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/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var W=Object.defineProperty;var
|
|
2
|
-
${
|
|
1
|
+
"use strict";var W=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var n in t)W(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of E(t))!z.call(e,r)&&r!==n&&W(e,r,{get:()=>t[r],enumerable:!(o=_(t,r))||o.enumerable});return e};var Z=e=>N(W({},"__esModule",{value:!0}),e);var G={};O(G,{WarpMcp:()=>S,buildZodInputSchema:()=>M,convertActionToTool:()=>C,convertMcpActionToTool:()=>A,convertMcpArgsToWarpInputs:()=>T,convertMcpToolToWarp:()=>b,convertWarpToMcpCapabilities:()=>k,convertWarpsToMcpCapabilities:()=>J,createAppResource:()=>x,createMcpServerFromWarps:()=>B,extractText:()=>u});module.exports=Z(G);var y=require("@vleap/warps"),T=(e,t)=>{let{action:n}=(0,y.getWarpPrimaryAction)(e);if(!n.inputs)return[];let o=new y.WarpSerializer;return n.inputs.map(r=>{let s=r.as||r.name,c=t[s]??r.default??null;return c===null&&r.type==="bool"?o.nativeToString(r.type,!1):o.nativeToString(r.type,c)})};var m=require("zod");var g=require("@vleap/warps");var q=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download app from ${e}: HTTP ${t.status} ${t.statusText}`);return t.text()},R=(e,t)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;let n=new URL(e);return new URL(t,n).href},D=async(e,t)=>{let n=/<link[^>]+rel=["']stylesheet["'][^>]+href=["']([^"']+)["'][^>]*>/gi,o=/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/gi,r=[],s;for(;(s=n.exec(e))!==null;){let l=s[0],a=R(t,s[1]);r.push(fetch(a).then(i=>i.ok?i.text():"").then(i=>({match:l,content:i?`<style>${i}</style>`:""})).catch(()=>({match:l,content:""})))}for(;(s=o.exec(e))!==null;){let l=s[0],a=R(t,s[1]);r.push(fetch(a).then(i=>i.ok?i.text():"").then(i=>({match:l,content:i?`<script>${i}</script>`:""})).catch(()=>({match:l,content:""})))}if(r.length===0)return e;let c=await Promise.all(r),p=e;for(let{match:l,content:a}of c)p=p.replace(l,a||"");return p},F=e=>{let t=e;return t=t.replace(/<html[^>]*>/gi,"").replace(/<\/html>/gi,""),t=t.replace(/<head[^>]*>/gi,"").replace(/<\/head>/gi,""),t=t.replace(/<body[^>]*>/gi,"").replace(/<\/body>/gi,""),t.trim()},L=(e,t)=>{let n=`<script type="application/json" id="warp-app-data">${JSON.stringify(t)}</script>`,o=F(e);return`${n}
|
|
2
|
+
${o}`},x=async(e,t,n)=>{if(!e.meta?.identifier)return null;try{let o=await q(t);o=await D(o,t);let r={warp:{name:e.name,title:u(e.title,n),description:u(e.description,n)}};return{name:e.name,uri:`ui://widget/${e.meta.identifier}`,description:`ChatGPT app for ${e.name}`,mimeType:"text/html+skybridge",content:L(o,r)}}catch(o){let r=o instanceof Error?o.message:String(o),s=o instanceof Error?o.stack:void 0;return console.error(`[MCP] Failed to create app resource for warp "${e.name}" (url: ${t}):`,r),s&&console.error("[MCP] Error stack:",s),null}};var u=(e,t)=>e&&(0,g.resolveWarpText)(e,t)||void 0,k=async(e,t)=>{let n=[],o=null;e.ui&&e.ui!=="table"&&(o=await x(e,e.ui,t));try{let{action:r}=(0,g.getWarpPrimaryAction)(e);if(r.type==="mcp"){let s=r;if(s.destination){let c=u(e.description,t)||u(r.description,t),p=A(e,s,c,r.inputs,o?.uri,t);n.push(p)}}else{let s=u(e.description,t)||u(r.description,t),c=C(e,r,s,r.inputs,o?.uri,t);n.push(c)}}catch(r){console.log(`[MCP] ${e.name} - failed to get primary action:`,r)}return{tools:n,...o&&{resources:[o]}}},J=async(e,t)=>Promise.all(e.map(n=>k(n,t))),V=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",b=async(e,t,n,o)=>{let r=[];if(t.inputSchema?.properties){let p=t.inputSchema.properties,l=t.inputSchema.required||[];Object.entries(p).forEach(([a,i])=>{let d=l.includes(a),f=V(i.type,i.format),h={name:a,label:i.title||{en:a},description:i.description?{en:i.description.trim()}:null,type:f,position:`payload:${a}`,source:"field",required:d,default:i.default};r.push(h)})}let s={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(p=>{s[p]=`out.${p}`});let c={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:n,tool:t.name,headers:o},inputs:r};return await new g.WarpBuilder(e).setName(t.name).setTitle({en:t.name}).setDescription(t.description?{en:t.description.trim()}:null).addAction(c).setOutput(Object.keys(s).length>0?s:null).build(!1)};var H=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},v=e=>(e.includes(":")?e.split(":").slice(1).join(":"):e).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,t=>t.includes("_")?"_":t).replace(/_+/g,"_"),U=(e,t)=>{let n,o=e.type.toLowerCase();o==="string"||o==="address"||o==="hex"?n=m.z.string():o==="number"||o==="uint8"||o==="uint16"||o==="uint32"||o==="uint64"||o==="uint128"||o==="uint256"?n=m.z.number():o==="bool"||o==="boolean"?n=m.z.boolean():o==="biguint"?n=m.z.string():n=m.z.string(),typeof e.min=="number"&&n instanceof m.z.ZodNumber&&(n=n.min(e.min)),typeof e.max=="number"&&n instanceof m.z.ZodNumber&&(n=n.max(e.max)),e.pattern&&n instanceof m.z.ZodString&&(n=n.regex(new RegExp(e.pattern)));let r=H(e.options);if(r&&r.length>0){if(n instanceof m.z.ZodString)n=m.z.enum(r);else if(n instanceof m.z.ZodNumber){let a=r.map(i=>Number(i)).filter(i=>!isNaN(i));a.length>0&&(n=n.refine(i=>a.includes(i),{message:`Value must be one of: ${a.join(", ")}`}))}}let s=[],c=u(e.description,t);c&&s.push(c),e.bot&&s.push(e.bot),s.push(`Type: ${e.type}`),s.push(e.required?"Required":"Optional"),r&&r.length>0&&s.push(`Options: ${r.join(", ")}`);let p=u(e.patternDescription,t);p&&s.push(p);let l=s.join(". ");return l&&(n=n.describe(l)),e.required!==!0&&(n=n.optional()),n},M=(e,t)=>{let n={};for(let o of e){if(o.source==="hidden"||o.source!=="field")continue;let r=o.as||o.name;n[r]=U(o,t)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(n)),Object.keys(n).length>0?n:void 0},C=(e,t,n,o,r,s)=>{let c=o||t.inputs||[],p=M(c,s),l=v(e.name);console.log(`[MCP] convertActionToTool - tool: ${l}, inputsToUse: ${c.length}, inputSchema keys:`,p?Object.keys(p):"undefined");let a={name:l,description:n,inputSchema:p},i={"openai/widgetAccessible":!0};if(r&&(i["openai/outputTemplate"]=r),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(i["openai/toolInvocation/invoking"]=d),f&&(i["openai/toolInvocation/invoked"]=f)}return a._meta=i,console.log(`[MCP] convertActionToTool - tool: ${l}, meta:`,JSON.stringify(i,null,2)),a},A=(e,t,n,o,r,s)=>{let c=o||t.inputs||[],p=M(c,s),l=t.destination.tool,a={name:v(l),description:n,inputSchema:p},i={"openai/widgetAccessible":!0};if(r&&(i["openai/outputTemplate"]=r),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(i["openai/toolInvocation/invoking"]=d),f&&(i["openai/toolInvocation/invoked"]=f)}return a._meta=i,console.log(`[MCP] convertMcpActionToTool - tool: ${v(l)}, meta:`,JSON.stringify(i,null,2)),a};var P=require("@modelcontextprotocol/sdk/server/mcp.js"),$=require("@modelcontextprotocol/sdk/server/zod-compat.js");var Q=e=>{if(e)return e._zod?e._zod:(0,$.normalizeObjectSchema)(e)||e},B=(e,t,n,o)=>{let r=new P.McpServer({name:e.name,version:e.version||"1.0.0"}),s=e.executor||o;for(let c=0;c<n.length;c++){let{tools:p,resources:l}=n[c],a=t[c];p?.forEach(i=>{let d=Q(i.inputSchema),f={description:i.description||"",inputSchema:d};i._meta&&(f._meta=i._meta),r.registerTool(i.name,f,async h=>{if(s){let w=T(a,h||{});return await s(a,w)}return{content:[{type:"text",text:`Tool ${i.name} executed successfully`}]}})}),l?.forEach(i=>{r.registerResource(i.name||i.uri,i.uri,{description:i.description,mimeType:i.mimeType},async()=>({contents:[{uri:i.uri,mimeType:i.mimeType||"text/plain",text:i.content||"Resource content"}]}))})}return r};var I=require("@modelcontextprotocol/sdk/client/index.js"),j=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var S=class{constructor(t){this.config=t}async getWarpsFromTools(t,n){let o=new j.StreamableHTTPClientTransport(new URL(t),{requestInit:{headers:n||{}}}),r=new I.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await r.connect(o);let s=await r.listTools();return await r.close(),await Promise.all(s.tools.map(c=>b(this.config,c,t,n)))}catch(s){throw await r.close().catch(()=>{}),s}}};0&&(module.exports={WarpMcp,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractText});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getWarpPrimaryAction as
|
|
2
|
-
${
|
|
1
|
+
import{getWarpPrimaryAction as S,WarpSerializer as R}from"@vleap/warps";var h=(e,t)=>{let{action:n}=S(e);if(!n.inputs)return[];let o=new R;return n.inputs.map(r=>{let s=r.as||r.name,c=t[s]??r.default??null;return c===null&&r.type==="bool"?o.nativeToString(r.type,!1):o.nativeToString(r.type,c)})};import{z as m}from"zod";import{WarpBuilder as j,getWarpPrimaryAction as w,resolveWarpText as _}from"@vleap/warps";var k=async e=>{let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download app from ${e}: HTTP ${t.status} ${t.statusText}`);return t.text()},W=(e,t)=>{if(t.startsWith("http://")||t.startsWith("https://"))return t;let n=new URL(e);return new URL(t,n).href},P=async(e,t)=>{let n=/<link[^>]+rel=["']stylesheet["'][^>]+href=["']([^"']+)["'][^>]*>/gi,o=/<script[^>]+src=["']([^"']+)["'][^>]*><\/script>/gi,r=[],s;for(;(s=n.exec(e))!==null;){let l=s[0],a=W(t,s[1]);r.push(fetch(a).then(i=>i.ok?i.text():"").then(i=>({match:l,content:i?`<style>${i}</style>`:""})).catch(()=>({match:l,content:""})))}for(;(s=o.exec(e))!==null;){let l=s[0],a=W(t,s[1]);r.push(fetch(a).then(i=>i.ok?i.text():"").then(i=>({match:l,content:i?`<script>${i}</script>`:""})).catch(()=>({match:l,content:""})))}if(r.length===0)return e;let c=await Promise.all(r),p=e;for(let{match:l,content:a}of c)p=p.replace(l,a||"");return p},$=e=>{let t=e;return t=t.replace(/<html[^>]*>/gi,"").replace(/<\/html>/gi,""),t=t.replace(/<head[^>]*>/gi,"").replace(/<\/head>/gi,""),t=t.replace(/<body[^>]*>/gi,"").replace(/<\/body>/gi,""),t.trim()},I=(e,t)=>{let n=`<script type="application/json" id="warp-app-data">${JSON.stringify(t)}</script>`,o=$(e);return`${n}
|
|
2
|
+
${o}`},T=async(e,t,n)=>{if(!e.meta?.identifier)return null;try{let o=await k(t);o=await P(o,t);let r={warp:{name:e.name,title:u(e.title,n),description:u(e.description,n)}};return{name:e.name,uri:`ui://widget/${e.meta.identifier}`,description:`ChatGPT app for ${e.name}`,mimeType:"text/html+skybridge",content:I(o,r)}}catch(o){let r=o instanceof Error?o.message:String(o),s=o instanceof Error?o.stack:void 0;return console.error(`[MCP] Failed to create app resource for warp "${e.name}" (url: ${t}):`,r),s&&console.error("[MCP] Error stack:",s),null}};var u=(e,t)=>e&&_(e,t)||void 0,E=async(e,t)=>{let n=[],o=null;e.ui&&e.ui!=="table"&&(o=await T(e,e.ui,t));try{let{action:r}=w(e);if(r.type==="mcp"){let s=r;if(s.destination){let c=u(e.description,t)||u(r.description,t),p=C(e,s,c,r.inputs,o?.uri,t);n.push(p)}}else{let s=u(e.description,t)||u(r.description,t),c=b(e,r,s,r.inputs,o?.uri,t);n.push(c)}}catch(r){console.log(`[MCP] ${e.name} - failed to get primary action:`,r)}return{tools:n,...o&&{resources:[o]}}},ie=async(e,t)=>Promise.all(e.map(n=>E(n,t))),z=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",x=async(e,t,n,o)=>{let r=[];if(t.inputSchema?.properties){let p=t.inputSchema.properties,l=t.inputSchema.required||[];Object.entries(p).forEach(([a,i])=>{let d=l.includes(a),f=z(i.type,i.format),g={name:a,label:i.title||{en:a},description:i.description?{en:i.description.trim()}:null,type:f,position:`payload:${a}`,source:"field",required:d,default:i.default};r.push(g)})}let s={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(p=>{s[p]=`out.${p}`});let c={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:n,tool:t.name,headers:o},inputs:r};return await new j(e).setName(t.name).setTitle({en:t.name}).setDescription(t.description?{en:t.description.trim()}:null).addAction(c).setOutput(Object.keys(s).length>0?s:null).build(!1)};var O=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},y=e=>(e.includes(":")?e.split(":").slice(1).join(":"):e).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,t=>t.includes("_")?"_":t).replace(/_+/g,"_"),N=(e,t)=>{let n,o=e.type.toLowerCase();o==="string"||o==="address"||o==="hex"?n=m.string():o==="number"||o==="uint8"||o==="uint16"||o==="uint32"||o==="uint64"||o==="uint128"||o==="uint256"?n=m.number():o==="bool"||o==="boolean"?n=m.boolean():o==="biguint"?n=m.string():n=m.string(),typeof e.min=="number"&&n instanceof m.ZodNumber&&(n=n.min(e.min)),typeof e.max=="number"&&n instanceof m.ZodNumber&&(n=n.max(e.max)),e.pattern&&n instanceof m.ZodString&&(n=n.regex(new RegExp(e.pattern)));let r=O(e.options);if(r&&r.length>0){if(n instanceof m.ZodString)n=m.enum(r);else if(n instanceof m.ZodNumber){let a=r.map(i=>Number(i)).filter(i=>!isNaN(i));a.length>0&&(n=n.refine(i=>a.includes(i),{message:`Value must be one of: ${a.join(", ")}`}))}}let s=[],c=u(e.description,t);c&&s.push(c),e.bot&&s.push(e.bot),s.push(`Type: ${e.type}`),s.push(e.required?"Required":"Optional"),r&&r.length>0&&s.push(`Options: ${r.join(", ")}`);let p=u(e.patternDescription,t);p&&s.push(p);let l=s.join(". ");return l&&(n=n.describe(l)),e.required!==!0&&(n=n.optional()),n},A=(e,t)=>{let n={};for(let o of e){if(o.source==="hidden"||o.source!=="field")continue;let r=o.as||o.name;n[r]=N(o,t)}return console.log("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(n)),Object.keys(n).length>0?n:void 0},b=(e,t,n,o,r,s)=>{let c=o||t.inputs||[],p=A(c,s),l=y(e.name);console.log(`[MCP] convertActionToTool - tool: ${l}, inputsToUse: ${c.length}, inputSchema keys:`,p?Object.keys(p):"undefined");let a={name:l,description:n,inputSchema:p},i={"openai/widgetAccessible":!0};if(r&&(i["openai/outputTemplate"]=r),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(i["openai/toolInvocation/invoking"]=d),f&&(i["openai/toolInvocation/invoked"]=f)}return a._meta=i,console.log(`[MCP] convertActionToTool - tool: ${l}, meta:`,JSON.stringify(i,null,2)),a},C=(e,t,n,o,r,s)=>{let c=o||t.inputs||[],p=A(c,s),l=t.destination.tool,a={name:y(l),description:n,inputSchema:p},i={"openai/widgetAccessible":!0};if(r&&(i["openai/outputTemplate"]=r),e.messages){let d=u(e.messages.invoking,s),f=u(e.messages.invoked,s);d&&(i["openai/toolInvocation/invoking"]=d),f&&(i["openai/toolInvocation/invoked"]=f)}return a._meta=i,console.log(`[MCP] convertMcpActionToTool - tool: ${y(l)}, meta:`,JSON.stringify(i,null,2)),a};import{McpServer as Z}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as q}from"@modelcontextprotocol/sdk/server/zod-compat.js";var D=e=>{if(e)return e._zod?e._zod:q(e)||e},fe=(e,t,n,o)=>{let r=new Z({name:e.name,version:e.version||"1.0.0"}),s=e.executor||o;for(let c=0;c<n.length;c++){let{tools:p,resources:l}=n[c],a=t[c];p?.forEach(i=>{let d=D(i.inputSchema),f={description:i.description||"",inputSchema:d};i._meta&&(f._meta=i._meta),r.registerTool(i.name,f,async g=>{if(s){let M=h(a,g||{});return await s(a,M)}return{content:[{type:"text",text:`Tool ${i.name} executed successfully`}]}})}),l?.forEach(i=>{r.registerResource(i.name||i.uri,i.uri,{description:i.description,mimeType:i.mimeType},async()=>({contents:[{uri:i.uri,mimeType:i.mimeType||"text/plain",text:i.content||"Resource content"}]}))})}return r};import{Client as F}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as L}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var v=class{constructor(t){this.config=t}async getWarpsFromTools(t,n){let o=new L(new URL(t),{requestInit:{headers:n||{}}}),r=new F({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await r.connect(o);let s=await r.listTools();return await r.close(),await Promise.all(s.tools.map(c=>x(this.config,c,t,n)))}catch(s){throw await r.close().catch(()=>{}),s}}};export{v as WarpMcp,A as buildZodInputSchema,b as convertActionToTool,C as convertMcpActionToTool,h as convertMcpArgsToWarpInputs,x as convertMcpToolToWarp,E as convertWarpToMcpCapabilities,ie as convertWarpsToMcpCapabilities,T as createAppResource,fe as createMcpServerFromWarps,u as extractText};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vleap/warps-mcp",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
4
4
|
"description": "MCP adapter for Warps SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"zod": "^4.1.13"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@vleap/warps": "^3.0.0-beta.
|
|
45
|
+
"@vleap/warps": "^3.0.0-beta.174"
|
|
46
46
|
}
|
|
47
47
|
}
|