@joai/warps-mcp 1.0.0-beta.30 → 1.0.0-beta.32

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