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