@joai/warps-mcp 1.0.0-beta.29 → 1.0.0-beta.30
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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var A=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var A=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var J=(e,t)=>{for(var r in t)A(e,r,{get:t[r],enumerable:!0})},U=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of N(t))!q.call(e,o)&&o!==r&&A(e,o,{get:()=>t[o],enumerable:!(n=E(t,o))||n.enumerable});return e};var D=e=>U(A({},"__esModule",{value:!0}),e);var te={};J(te,{WarpMcp:()=>v,buildZodInputSchema:()=>M,convertActionToTool:()=>C,convertMcpActionToTool:()=>b,convertMcpArgsToWarpInputs:()=>h,convertMcpToolToWarp:()=>S,convertPromptActionToPrompt:()=>R,convertWarpToMcpCapabilities:()=>_,convertWarpsToMcpCapabilities:()=>Q,createAppResource:()=>P,createMcpServerFromWarps:()=>ee,extractTextOrUndefined:()=>m,interpolatePromptWithArgs:()=>z});module.exports=D(te);var T=require("@joai/warps"),h=(e,t)=>{let{action:r}=(0,T.getWarpPrimaryAction)(e);if(!r.inputs)return[];let n=new T.WarpSerializer;return r.inputs.map(o=>{let i=o.as||o.name,p=t[i]??o.default??null;return p===null&&o.type==="bool"?n.nativeToString(o.type,!1):n.nativeToString(o.type,p)})};var g=require("@joai/warps");var d=require("@joai/warps"),l=require("zod");var L=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},F=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,"_"),V=(e,t)=>{let r,n=e.type.toLowerCase();n==="string"||n==="address"||n==="hex"?r=l.z.string():n==="number"||n==="uint8"||n==="uint16"||n==="uint32"||n==="uint64"||n==="uint128"||n==="uint256"?r=l.z.number():n==="bool"||n==="boolean"?r=l.z.boolean():n==="biguint"?r=l.z.string():r=l.z.string(),typeof e.min=="number"&&r instanceof l.z.ZodNumber&&(r=r.min(e.min)),typeof e.max=="number"&&r instanceof l.z.ZodNumber&&(r=r.max(e.max)),e.pattern&&r instanceof l.z.ZodString&&(r=r.regex(new RegExp(e.pattern)));let o=L(e.options);if(o&&o.length>0){if(r instanceof l.z.ZodString)r=l.z.enum(o);else if(r instanceof l.z.ZodNumber){let u=o.map(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(r=r.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let i=[],p=m(e.description,t);p&&i.push(p),e.bot&&i.push(e.bot),i.push(`Type: ${e.type}`),i.push(e.required?"Required":"Optional"),o&&o.length>0&&i.push(`Options: ${o.join(", ")}`);let a=m(e.patternDescription,t);a&&i.push(a);let c=i.join(". ");return c&&(r=r.describe(c)),e.required!==!0&&(r=r.optional()),r},M=(e,t)=>{let r={};for(let n of e){if(n.source==="hidden"||n.source!=="field")continue;let o=n.as||n.name;r[o]=V(n,t)}return d.WarpLogger.info("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(r)),Object.keys(r).length>0?r:void 0},C=(e,t,r,n,o,i)=>{let p=e.meta?.identifier;if(!p)throw new Error(`Warp identifier for warp ${e.name} is required`);let a=(0,d.cleanWarpIdentifier)(p),c=n||t.inputs||[],u=M(c,i);d.WarpLogger.info(`[MCP] convertActionToTool - tool: ${a}, inputsToUse: ${c.length}, inputSchema keys:`,u?Object.keys(u):"undefined");let s={name:a,description:r,inputSchema:u,meta:I(e,o,i)};return d.WarpLogger.info(`[MCP] convertActionToTool - tool: ${a}, meta:`,JSON.stringify(s.meta,null,2)),s},b=(e,t,r,n,o,i)=>{let p=n||t.inputs||[],a=M(p,i),c=t.destination.tool,u=F(c),s={name:u,description:r,inputSchema:a,meta:I(e,o,i)};return d.WarpLogger.info(`[MCP] convertMcpActionToTool - tool: ${u}, meta:`,JSON.stringify(s.meta,null,2)),s},I=(e,t,r)=>{let n={"openai/widgetAccessible":!0};if(t&&(n["openai/outputTemplate"]=t.uri),e.messages){let o=m(e.messages.invoking,r),i=m(e.messages.invoked,r);o&&(n["openai/toolInvocation/invoking"]=o),i&&(n["openai/toolInvocation/invoked"]=i)}return n};var x=require("@joai/warps"),H=async e=>{if(e.startsWith("http://")||e.startsWith("https://")){let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download component from ${e}: HTTP ${t.status} ${t.statusText}`);return t.text()}throw new Error(`Unsupported component path: ${e}`)},P=async(e,t,r)=>{if(!e.meta?.identifier)return null;try{let n=await H(t);return{name:e.name,uri:`ui://widget/${e.meta.identifier}`,description:`ChatGPT app for ${e.name}`,mimeType:"text/html+skybridge",content:n}}catch(n){let o=n instanceof Error?n.message:String(n),i=n instanceof Error?n.stack:void 0;return x.WarpLogger.error(`[MCP] Failed to create app resource for warp "${e.name}" (path: ${t}):`,o),i&&x.WarpLogger.error("[MCP] Error stack:",i),null}};var _=async(e,t)=>{let r=null,n=null,o=null;if(e.ui&&e.ui!=="table"&&(n=await P(e,e.ui,t)),e.actions.length===0)return{tool:null,resource:n,prompt:null};try{let{action:i}=(0,g.getWarpPrimaryAction)(e),p=m(e.description,t)||m(i.description,t);if(i.type==="prompt")o=R(e,i,p,t);else if(i.type==="mcp"){let a=i;a.destination&&(r=b(e,a,p,i.inputs,n,t))}else r=C(e,i,p,i.inputs,n,t)}catch{return{tool:null,resource:n,prompt:null}}return{tool:r,resource:n,prompt:o}},Q=async(e,t)=>Promise.all(e.map(r=>_(r,t))),B=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",S=async(e,t,r,n)=>{let o=[];if(t.inputSchema?.properties){let a=t.inputSchema.properties,c=t.inputSchema.required||[];Object.entries(a).forEach(([u,s])=>{let f=c.includes(u),W=B(s.type||"string",s.format),y={name:u,label:typeof s.title=="string"?{en:s.title}:s.title||{en:u},description:s.description?{en:s.description.trim()}:null,type:W,position:`payload:${u}`,source:"field",required:f,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};o.push(y)})}let i={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(a=>{i[a]=`out.${a}`});let p={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:r,tool:t.name,headers:n},inputs:o};return await new g.WarpBuilder(e).setName(t.name||"unnamed_tool").setTitle({en:t.name||"Unnamed Tool"}).setDescription(t.description?{en:t.description.trim()}:null).addAction(p).setOutput(Object.keys(i).length>0?i:null).build(!1)},m=(e,t)=>e&&(0,g.resolveWarpText)(e,t)||void 0;var z=(e,t)=>{let r=e;for(let[n,o]of Object.entries(t)){let i=new RegExp(`\\{\\{\\s*${n}\\s*\\}\\}`,"g");r=r.replace(i,o??"")}return r},G=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,"_"),K=(e,t)=>{let r=[];for(let n of e){if(n.source==="hidden"||n.source!=="field")continue;let o=n.as||n.name,i=m(n.description,t);r.push({name:o,description:i,required:n.required===!0})}return r},R=(e,t,r,n)=>{let o=G(e.name),i=t.inputs||[],p=K(i,n);return{name:o,description:r,arguments:p.length>0?p:void 0,prompt:t.prompt}};var w=require("@modelcontextprotocol/sdk/server/mcp.js"),k=require("@modelcontextprotocol/sdk/server/zod-compat.js"),Z=require("zod");var X=e=>{if(e)return typeof e=="object"&&"_zod"in e?e._zod:typeof e=="object"&&!Array.isArray(e)&&(0,k.normalizeObjectSchema)(e)||e},Y=e=>{if(!e.arguments||e.arguments.length===0)return;let t={};for(let r of e.arguments){let n=Z.z.string();r.description&&(n=n.describe(r.description)),r.required||(n=n.optional()),t[r.name]=n}return t},ee=(e,t,r,n)=>{let o=new w.McpServer({name:e.name,version:e.version||"1.0.0"}),i=e.executor||n;for(let p=0;p<r.length;p++){let{tool:a,resource:c,prompt:u}=r[p],s=t[p];if(a){let f=X(a.inputSchema),W={description:a.description||"",inputSchema:f,...a.meta&&{_meta:a.meta}};o.registerTool(a.name,W,async y=>{if(i){let O=h(s,y||{});return await i(s,O)}return{content:[{type:"text",text:`Tool ${a.name} executed successfully`}]}})}if(c&&o.registerResource(c.name||c.uri,c.uri,{description:c.description,mimeType:c.mimeType},async()=>{let f={uri:c.uri,text:c.content||"",mimeType:c.mimeType};return c.meta&&(f._meta=c.meta),{contents:[f]}}),u){let f=Y(u);o.registerPrompt(u.name,{description:u.description||"",argsSchema:f},W=>({messages:[{role:"user",content:{type:"text",text:z(u.prompt,W)}}]}))}}return o};var $=require("@modelcontextprotocol/sdk/client/index.js"),j=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var v=class{constructor(t){this.config=t}async getWarpsFromTools(t,r){let n=new j.StreamableHTTPClientTransport(new URL(t),{requestInit:{headers:r||{}}}),o=new $.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await o.connect(n);let i=await o.listTools();return await o.close(),await Promise.all(i.tools.map(p=>S(this.config,p,t,r)))}catch(i){throw await o.close().catch(()=>{}),i}}};0&&(module.exports={WarpMcp,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertPromptActionToPrompt,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractTextOrUndefined,interpolatePromptWithArgs});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getWarpPrimaryAction as
|
|
1
|
+
import{getWarpPrimaryAction as v,WarpSerializer as I}from"@joai/warps";var y=(e,t)=>{let{action:r}=v(e);if(!r.inputs)return[];let n=new I;return r.inputs.map(i=>{let o=i.as||i.name,p=t[o]??i.default??null;return p===null&&i.type==="bool"?n.nativeToString(i.type,!1):n.nativeToString(i.type,p)})};import{WarpBuilder as j,getWarpPrimaryAction as O,resolveWarpText as E}from"@joai/warps";import{cleanWarpIdentifier as _,WarpLogger as W}from"@joai/warps";import{z as l}from"zod";var w=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},k=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,"_"),Z=(e,t)=>{let r,n=e.type.toLowerCase();n==="string"||n==="address"||n==="hex"?r=l.string():n==="number"||n==="uint8"||n==="uint16"||n==="uint32"||n==="uint64"||n==="uint128"||n==="uint256"?r=l.number():n==="bool"||n==="boolean"?r=l.boolean():n==="biguint"?r=l.string():r=l.string(),typeof e.min=="number"&&r instanceof l.ZodNumber&&(r=r.min(e.min)),typeof e.max=="number"&&r instanceof l.ZodNumber&&(r=r.max(e.max)),e.pattern&&r instanceof l.ZodString&&(r=r.regex(new RegExp(e.pattern)));let i=w(e.options);if(i&&i.length>0){if(r instanceof l.ZodString)r=l.enum(i);else if(r instanceof l.ZodNumber){let u=i.map(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(r=r.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],p=m(e.description,t);p&&o.push(p),e.bot&&o.push(e.bot),o.push(`Type: ${e.type}`),o.push(e.required?"Required":"Optional"),i&&i.length>0&&o.push(`Options: ${i.join(", ")}`);let a=m(e.patternDescription,t);a&&o.push(a);let c=o.join(". ");return c&&(r=r.describe(c)),e.required!==!0&&(r=r.optional()),r},T=(e,t)=>{let r={};for(let n of e){if(n.source==="hidden"||n.source!=="field")continue;let i=n.as||n.name;r[i]=Z(n,t)}return W.info("[MCP] buildZodInputSchema - inputs:",e.length,"shape keys:",Object.keys(r)),Object.keys(r).length>0?r:void 0},A=(e,t,r,n,i,o)=>{let p=e.meta?.identifier;if(!p)throw new Error(`Warp identifier for warp ${e.name} is required`);let a=_(p),c=n||t.inputs||[],u=T(c,o);W.info(`[MCP] convertActionToTool - tool: ${a}, inputsToUse: ${c.length}, inputSchema keys:`,u?Object.keys(u):"undefined");let s={name:a,description:r,inputSchema:u,meta:M(e,i,o)};return W.info(`[MCP] convertActionToTool - tool: ${a}, meta:`,JSON.stringify(s.meta,null,2)),s},h=(e,t,r,n,i,o)=>{let p=n||t.inputs||[],a=T(p,o),c=t.destination.tool,u=k(c),s={name:u,description:r,inputSchema:a,meta:M(e,i,o)};return W.info(`[MCP] convertMcpActionToTool - tool: ${u}, meta:`,JSON.stringify(s.meta,null,2)),s},M=(e,t,r)=>{let n={"openai/widgetAccessible":!0};if(t&&(n["openai/outputTemplate"]=t.uri),e.messages){let i=m(e.messages.invoking,r),o=m(e.messages.invoked,r);i&&(n["openai/toolInvocation/invoking"]=i),o&&(n["openai/toolInvocation/invoked"]=o)}return n};import{WarpLogger as C}from"@joai/warps";var $=async e=>{if(e.startsWith("http://")||e.startsWith("https://")){let t=await fetch(e);if(!t.ok)throw new Error(`Failed to download component from ${e}: HTTP ${t.status} ${t.statusText}`);return t.text()}throw new Error(`Unsupported component path: ${e}`)},b=async(e,t,r)=>{if(!e.meta?.identifier)return null;try{let n=await $(t);return{name:e.name,uri:`ui://widget/${e.meta.identifier}`,description:`ChatGPT app for ${e.name}`,mimeType:"text/html+skybridge",content:n}}catch(n){let i=n instanceof Error?n.message:String(n),o=n instanceof Error?n.stack:void 0;return C.error(`[MCP] Failed to create app resource for warp "${e.name}" (path: ${t}):`,i),o&&C.error("[MCP] Error stack:",o),null}};var N=async(e,t)=>{let r=null,n=null,i=null;if(e.ui&&e.ui!=="table"&&(n=await b(e,e.ui,t)),e.actions.length===0)return{tool:null,resource:n,prompt:null};try{let{action:o}=O(e),p=m(e.description,t)||m(o.description,t);if(o.type==="prompt")i=P(e,o,p,t);else if(o.type==="mcp"){let a=o;a.destination&&(r=h(e,a,p,o.inputs,n,t))}else r=A(e,o,p,o.inputs,n,t)}catch{return{tool:null,resource:n,prompt:null}}return{tool:r,resource:n,prompt:i}},ve=async(e,t)=>Promise.all(e.map(r=>N(r,t))),q=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",x=async(e,t,r,n)=>{let i=[];if(t.inputSchema?.properties){let a=t.inputSchema.properties,c=t.inputSchema.required||[];Object.entries(a).forEach(([u,s])=>{let f=c.includes(u),d=q(s.type||"string",s.format),g={name:u,label:typeof s.title=="string"?{en:s.title}:s.title||{en:u},description:s.description?{en:s.description.trim()}:null,type:d,position:`payload:${u}`,source:"field",required:f,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};i.push(g)})}let o={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(a=>{o[a]=`out.${a}`});let p={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:r,tool:t.name,headers:n},inputs:i};return await new j(e).setName(t.name||"unnamed_tool").setTitle({en:t.name||"Unnamed Tool"}).setDescription(t.description?{en:t.description.trim()}:null).addAction(p).setOutput(Object.keys(o).length>0?o:null).build(!1)},m=(e,t)=>e&&E(e,t)||void 0;var S=(e,t)=>{let r=e;for(let[n,i]of Object.entries(t)){let o=new RegExp(`\\{\\{\\s*${n}\\s*\\}\\}`,"g");r=r.replace(o,i??"")}return r},J=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 r=[];for(let n of e){if(n.source==="hidden"||n.source!=="field")continue;let i=n.as||n.name,o=m(n.description,t);r.push({name:i,description:o,required:n.required===!0})}return r},P=(e,t,r,n)=>{let i=J(e.name),o=t.inputs||[],p=U(o,n);return{name:i,description:r,arguments:p.length>0?p:void 0,prompt:t.prompt}};import{McpServer as D}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as L}from"@modelcontextprotocol/sdk/server/zod-compat.js";import{z as F}from"zod";var V=e=>{if(e)return typeof e=="object"&&"_zod"in e?e._zod:typeof e=="object"&&!Array.isArray(e)&&L(e)||e},H=e=>{if(!e.arguments||e.arguments.length===0)return;let t={};for(let r of e.arguments){let n=F.string();r.description&&(n=n.describe(r.description)),r.required||(n=n.optional()),t[r.name]=n}return t},Ee=(e,t,r,n)=>{let i=new D({name:e.name,version:e.version||"1.0.0"}),o=e.executor||n;for(let p=0;p<r.length;p++){let{tool:a,resource:c,prompt:u}=r[p],s=t[p];if(a){let f=V(a.inputSchema),d={description:a.description||"",inputSchema:f,...a.meta&&{_meta:a.meta}};i.registerTool(a.name,d,async g=>{if(o){let z=y(s,g||{});return await o(s,z)}return{content:[{type:"text",text:`Tool ${a.name} executed successfully`}]}})}if(c&&i.registerResource(c.name||c.uri,c.uri,{description:c.description,mimeType:c.mimeType},async()=>{let f={uri:c.uri,text:c.content||"",mimeType:c.mimeType};return c.meta&&(f._meta=c.meta),{contents:[f]}}),u){let f=H(u);i.registerPrompt(u.name,{description:u.description||"",argsSchema:f},d=>({messages:[{role:"user",content:{type:"text",text:S(u.prompt,d)}}]}))}}return i};import{Client as Q}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as B}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var R=class{constructor(t){this.config=t}async getWarpsFromTools(t,r){let n=new B(new URL(t),{requestInit:{headers:r||{}}}),i=new Q({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(n);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(p=>x(this.config,p,t,r)))}catch(o){throw await i.close().catch(()=>{}),o}}};export{R as WarpMcp,T as buildZodInputSchema,A as convertActionToTool,h as convertMcpActionToTool,y as convertMcpArgsToWarpInputs,x as convertMcpToolToWarp,P as convertPromptActionToPrompt,N as convertWarpToMcpCapabilities,ve as convertWarpsToMcpCapabilities,b as createAppResource,Ee as createMcpServerFromWarps,m as extractTextOrUndefined,S as interpolatePromptWithArgs};
|