@joai/warps-mcp 12.0.1 → 12.1.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/dist/index.d.cts CHANGED
@@ -120,6 +120,16 @@ type WarpMcpToolResult = {
120
120
  _meta?: ToolMeta;
121
121
  };
122
122
  type WarpMcpExecutor = (warp: Warp, inputs: string[]) => Promise<WarpMcpToolResult>;
123
+ /** App-level MCP config authored per app in joai--warps/mcp.ts */
124
+ type AppMcpConfig = WarpAppResourceUiMeta;
125
+
126
+ /**
127
+ * Builds the resource metadata `ui` block expected by MCP Apps clients.
128
+ * Applies secure defaults for any fields not provided by the app config.
129
+ *
130
+ * @see https://modelcontextprotocol.github.io/ext-apps/api/documents/Migrate_OpenAI_App.html#resource-metadata
131
+ */
132
+ declare const buildAppMcpResourceMeta: (appMcp?: AppMcpConfig) => ResourceMeta;
123
133
 
124
134
  declare const interpolatePromptWithArgs: (promptTemplate: string, args: Record<string, string>) => string;
125
135
  declare const convertPromptActionToPrompt: (warp: Warp, action: WarpPromptAction, description: string | undefined, config: WarpClientConfig) => WarpMcpPrompt;
@@ -159,4 +169,4 @@ declare class WarpMcp {
159
169
  getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
160
170
  }
161
171
 
162
- export { type JsonSchema$1 as JsonSchema, type McpAppWarpEmbedModel, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppToolVisibility, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildWarpDirectIdentifierFromMcpToolCall, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, hasMcpAppUi, interpolatePromptWithArgs, isMcpToolCallAllowedForWarp, normalizeMcpToolNameToWarpIdentifier, resolveMcpAppInputsPayload, resolveMcpAppOutputPayload, resolveMcpAppWarpEmbedModel, resolveMcpToolCallToWarpDirect };
172
+ export { type AppMcpConfig, type JsonSchema$1 as JsonSchema, type McpAppWarpEmbedModel, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppToolVisibility, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildAppMcpResourceMeta, buildWarpDirectIdentifierFromMcpToolCall, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, hasMcpAppUi, interpolatePromptWithArgs, isMcpToolCallAllowedForWarp, normalizeMcpToolNameToWarpIdentifier, resolveMcpAppInputsPayload, resolveMcpAppOutputPayload, resolveMcpAppWarpEmbedModel, resolveMcpToolCallToWarpDirect };
package/dist/index.d.ts CHANGED
@@ -120,6 +120,16 @@ type WarpMcpToolResult = {
120
120
  _meta?: ToolMeta;
121
121
  };
122
122
  type WarpMcpExecutor = (warp: Warp, inputs: string[]) => Promise<WarpMcpToolResult>;
123
+ /** App-level MCP config authored per app in joai--warps/mcp.ts */
124
+ type AppMcpConfig = WarpAppResourceUiMeta;
125
+
126
+ /**
127
+ * Builds the resource metadata `ui` block expected by MCP Apps clients.
128
+ * Applies secure defaults for any fields not provided by the app config.
129
+ *
130
+ * @see https://modelcontextprotocol.github.io/ext-apps/api/documents/Migrate_OpenAI_App.html#resource-metadata
131
+ */
132
+ declare const buildAppMcpResourceMeta: (appMcp?: AppMcpConfig) => ResourceMeta;
123
133
 
124
134
  declare const interpolatePromptWithArgs: (promptTemplate: string, args: Record<string, string>) => string;
125
135
  declare const convertPromptActionToPrompt: (warp: Warp, action: WarpPromptAction, description: string | undefined, config: WarpClientConfig) => WarpMcpPrompt;
@@ -159,4 +169,4 @@ declare class WarpMcp {
159
169
  getWarpsFromTools(url: string, headers?: Record<string, string>): Promise<Warp[]>;
160
170
  }
161
171
 
162
- export { type JsonSchema$1 as JsonSchema, type McpAppWarpEmbedModel, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppToolVisibility, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildWarpDirectIdentifierFromMcpToolCall, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, hasMcpAppUi, interpolatePromptWithArgs, isMcpToolCallAllowedForWarp, normalizeMcpToolNameToWarpIdentifier, resolveMcpAppInputsPayload, resolveMcpAppOutputPayload, resolveMcpAppWarpEmbedModel, resolveMcpToolCallToWarpDirect };
172
+ export { type AppMcpConfig, type JsonSchema$1 as JsonSchema, type McpAppWarpEmbedModel, type ResourceMeta, type ToolInputSchema, type ToolMeta, type ToolOutputSchema, type WarpAppResourceUiMeta, type WarpAppToolVisibility, type WarpAppUiMeta, WarpMcp, type WarpMcpCapabilities, type WarpMcpExecutor, type WarpMcpPrompt, type WarpMcpPromptArgument, type WarpMcpResource, type WarpMcpServerConfig, type WarpMcpTool, type WarpMcpToolArgs, type WarpMcpToolResult, buildAppMcpResourceMeta, buildWarpDirectIdentifierFromMcpToolCall, buildZodInputSchema, convertActionToTool, convertMcpActionToTool, convertMcpArgsToWarpInputs, convertMcpToolToWarp, convertPromptActionToPrompt, convertWarpToMcpCapabilities, convertWarpsToMcpCapabilities, createAppResource, createMcpServerFromWarps, extractTextOrUndefined, hasMcpAppUi, interpolatePromptWithArgs, isMcpToolCallAllowedForWarp, normalizeMcpToolNameToWarpIdentifier, resolveMcpAppInputsPayload, resolveMcpAppOutputPayload, resolveMcpAppWarpEmbedModel, resolveMcpToolCallToWarpDirect };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var Q=(t,e)=>{for(var n in e)M(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y(e))!B.call(t,i)&&i!==n&&M(t,i,{get:()=>e[i],enumerable:!(r=H(e,i))||r.enumerable});return t};var K=t=>G(M({},"__esModule",{value:!0}),t);var gt={};Q(gt,{WarpMcp:()=>k,buildWarpDirectIdentifierFromMcpToolCall:()=>E,buildZodInputSchema:()=>b,convertActionToTool:()=>C,convertMcpActionToTool:()=>x,convertMcpArgsToWarpInputs:()=>h,convertMcpToolToWarp:()=>R,convertPromptActionToPrompt:()=>I,convertWarpToMcpCapabilities:()=>j,convertWarpsToMcpCapabilities:()=>st,createAppResource:()=>w,createMcpServerFromWarps:()=>ft,extractTextOrUndefined:()=>f,hasMcpAppUi:()=>q,interpolatePromptWithArgs:()=>S,isMcpToolCallAllowedForWarp:()=>v,normalizeMcpToolNameToWarpIdentifier:()=>T,resolveMcpAppInputsPayload:()=>z,resolveMcpAppOutputPayload:()=>O,resolveMcpAppWarpEmbedModel:()=>tt,resolveMcpToolCallToWarpDirect:()=>et});module.exports=K(gt);var y=t=>!t||typeof t!="object"||Array.isArray(t)?null:t,X=t=>t==null?null:typeof t=="string"?t:JSON.stringify(t),z=t=>{let e=y(t.query);if(e)return e;let n=y(t.contentInputs);if(n)return n;let r=t.metaInputs||[];return r.length>0?{inputs:r}:null},O=t=>y(t.metaOutput)||y(t.contentOutput),tt=t=>({isMcpApp:q(t.ui),inputsPayload:z({query:t.query,contentInputs:t.contentInputs,metaInputs:t.metaInputs}),outputPayload:O({metaOutput:t.metaOutput,contentOutput:t.contentOutput})}),q=t=>typeof t=="string"&&t!=="table",T=t=>!t||t.startsWith("@")?t:t.includes(":")?`@${t.replace(/^@/,"")}`:t,v=t=>t.activeWarpIdentifier?T(t.requestedToolName)===T(t.activeWarpIdentifier):!0,E=(t,e={})=>{let n=T(t),r=new URLSearchParams;return Object.entries(e).forEach(([i,o])=>{let c=X(o);c!=null&&r.set(i,c)}),r.size>0?`${n}?${r.toString()}`:n},et=t=>{let e=v({requestedToolName:t.requestedToolName,activeWarpIdentifier:t.activeWarpIdentifier}),n=E(t.requestedToolName,t.args||{});return{allowed:e,warpIdentifier:n}};var _=require("@joai/warps"),h=(t,e)=>{let{action:n}=(0,_.getWarpInputAction)(t);return n.inputs?n.inputs.map(r=>{let i=r.as||r.name,o=e[i]??r.default??null;return o===null&&r.type==="bool"?"false":o==null?"":String(o)}):[]};var U=require("@joai/warps");var g=require("@joai/warps");var Z=require("@joai/warps"),l=require("zod");var rt=t=>{if(t){if(Array.isArray(t))return t;if(typeof t=="object")return Object.keys(t)}},nt=(t,e)=>{let n,r=t.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=l.z.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=l.z.number():r==="bool"||r==="boolean"?n=l.z.boolean():r==="biguint"?n=l.z.string():n=l.z.string(),typeof t.min=="number"&&n instanceof l.z.ZodNumber&&(n=n.min(t.min)),typeof t.max=="number"&&n instanceof l.z.ZodNumber&&(n=n.max(t.max)),t.pattern&&n instanceof l.z.ZodString&&(n=n.regex(new RegExp(t.pattern)));let i=rt(t.options);if(i&&i.length>0){if(n instanceof l.z.ZodString)n=l.z.enum(i);else if(n instanceof l.z.ZodNumber){let u=i.map(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(n=n.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],c=f(t.description,e);c&&o.push(c),t.bot&&o.push(t.bot),o.push(`Type: ${t.type}`),o.push(t.required?"Required":"Optional"),i&&i.length>0&&o.push(`Options: ${i.join(", ")}`);let p=f(t.patternDescription,e);p&&o.push(p);let a=o.join(". ");return a&&(n=n.describe(a)),t.required!==!0&&(n=n.optional()),n},b=(t,e)=>{let n={};for(let r of t){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=nt(r,e)}return Object.keys(n).length>0?n:void 0},C=(t,e,n,r,i,o)=>{let c=ot(t),p=r||e.inputs||[],a=b(p,o);return{name:c,description:n,inputSchema:a,meta:$(t,i,o)}},x=(t,e,n,r,i,o)=>{let c=r||e.inputs||[],p=b(c,o),a=e.destination?.tool;if(!a)throw new Error(`Tool name is required for MCP action ${e.type}`);return{name:a,description:n,inputSchema:p,meta:$(t,i,o)}},$=(t,e,n)=>{let r={visibility:["model","app"]};return e&&(r.resourceUri=e.uri),{ui:r}},ot=t=>{let e=t.meta?.identifier;if(!e)throw new Error(`Warp identifier for warp ${t.name} is required`);return(0,Z.removeWarpChainPrefix)(e)};var P=require("@joai/warps"),it="text/html;profile=mcp-app",pt=async t=>{if(t.startsWith("http://")||t.startsWith("https://")){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to download component from ${t}: HTTP ${e.status} ${e.statusText}`);return e.text()}throw new Error(`Unsupported component path: ${t}`)},w=async(t,e,n)=>{if(!t.meta?.identifier)return null;try{let r=await pt(e);return{name:t.name,uri:`ui://widget/${t.meta.identifier}`,description:`MCP app for ${t.name}`,mimeType:it,content:r}}catch(r){let i=r instanceof Error?r.message:String(r),o=r instanceof Error?r.stack:void 0;return P.WarpLogger.error(`[MCP] Failed to create app resource for warp "${t.name}" (path: ${e}):`,i),o&&P.WarpLogger.error("[MCP] Error stack:",o),null}};var j=async(t,e)=>{let n=null,r=null,i=null;if(t.ui&&t.ui!=="table"&&(r=await w(t,t.ui,e)),t.actions.length===0)return{tool:null,resource:r,prompt:null};try{let{action:o}=(0,g.getWarpInputAction)(t),c=f(t.description,e)||f(o.description,e);if(o.type==="prompt")i=I(t,o,c,e);else if(o.type==="mcp"){let p=o;p.destination&&(n=x(t,p,c,o.inputs,r,e))}else n=C(t,o,c,o.inputs,r,e)}catch{return{tool:null,resource:r,prompt:null}}return{tool:n,resource:r,prompt:i}},st=async(t,e)=>Promise.all(t.map(n=>j(n,e))),ct=(t,e)=>e==="date-time"||e==="date"||t==="string"?"string":t==="number"||t==="integer"?"uint256":t==="boolean"?"bool":"string",R=async(t,e,n,r)=>{let i=[];if(e.inputSchema?.properties){let p=e.inputSchema.properties,a=e.inputSchema.required||[];Object.entries(p).forEach(([u,s])=>{let m=a.includes(u),d=ct(s.type||"string",s.format),A={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:m,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};i.push(A)})}let o={};e.outputSchema?.properties&&Object.keys(e.outputSchema.properties).forEach(p=>{o[p]=`out.${p}`});let c={type:"mcp",label:{en:e.name},description:e.description?{en:e.description.trim()}:null,destination:{url:n,tool:e.name,headers:r},inputs:i};return await new g.WarpBuilder(t).setName(e.name||"unnamed_tool").setTitle({en:e.name||"Unnamed Tool"}).setDescription(e.description?{en:e.description.trim()}:null).addAction(c).setOutput(Object.keys(o).length>0?o:null).build(!1)},f=(t,e)=>t&&(0,g.resolveWarpText)(t,e)||void 0;var S=(t,e)=>{let n=t;for(let[r,i]of Object.entries(e)){let o=new RegExp(`\\{\\{\\s*${r}\\s*\\}\\}`,"g");n=n.replace(o,i??"")}return n},at=t=>(t.includes(":")?t.split(":").slice(1).join(":"):t).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,e=>e.includes("_")?"_":e).replace(/_+/g,"_"),ut=(t,e)=>{let n=[];for(let r of t){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name,o=f(r.description,e);n.push({name:i,description:o,required:r.required===!0})}return n},I=(t,e,n,r)=>{let i=at(t.name),o=e.inputs||[],c=ut(o,r);return{name:i,description:n,arguments:c.length>0?c:void 0,prompt:(0,U.resolvePlatformValue)(e.prompt,r.platform)}};var N=require("@modelcontextprotocol/sdk/server/mcp.js"),D=require("@modelcontextprotocol/sdk/server/zod-compat.js"),W=require("@modelcontextprotocol/ext-apps/server"),F=require("zod");var lt=t=>{if(t)return typeof t=="object"&&"_zod"in t?t._zod:typeof t=="object"&&!Array.isArray(t)&&(0,D.normalizeObjectSchema)(t)||t},mt=t=>{if(!t.arguments||t.arguments.length===0)return;let e={};for(let n of t.arguments){let r=F.z.string();n.description&&(r=r.describe(n.description)),n.required||(r=r.optional()),e[n.name]=r}return e},dt=(t,e)=>t.startsWith("ui://")?!0:e?.includes("profile=mcp-app")??!1,ft=(t,e,n,r)=>{let i=new N.McpServer({name:t.name,version:t.version||"1.0.0"});for(let o=0;o<n.length;o++){let{tool:c,resource:p,prompt:a}=n[o],u=e[o];if(c){let s=lt(c.inputSchema),m={description:c.description||"",inputSchema:s,...c.meta&&{_meta:c.meta}},d=async A=>{let L=h(u,A||{});return await r(u,L)};c.meta?.ui?.resourceUri?(0,W.registerAppTool)(i,c.name,m,d):i.registerTool(c.name,m,d)}if(p)if(dt(p.uri,p.mimeType)){let s=p.meta,m=p.mimeType||W.RESOURCE_MIME_TYPE;(0,W.registerAppResource)(i,p.name||p.uri,p.uri,{description:p.description,mimeType:m,...s&&{_meta:s}},async()=>{let d={uri:p.uri,text:p.content||"",mimeType:m};return s&&(d._meta=s),{contents:[d]}})}else i.registerResource(p.name||p.uri,p.uri,{description:p.description,mimeType:p.mimeType},async()=>{let s={uri:p.uri,text:p.content||"",mimeType:p.mimeType};return p.meta&&(s._meta=p.meta),{contents:[s]}});if(a){let s=mt(a);i.registerPrompt(a.name,{description:a.description||"",argsSchema:s},m=>({messages:[{role:"user",content:{type:"text",text:S(a.prompt,m)}}]}))}}return i};var J=require("@modelcontextprotocol/sdk/client/index.js"),V=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var k=class{constructor(e){this.config=e}async getWarpsFromTools(e,n){let r=new V.StreamableHTTPClientTransport(new URL(e),{requestInit:{headers:n||{}}}),i=new J.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(r);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(c=>R(this.config,c,e,n)))}catch(o){throw await i.close().catch(()=>{}),o}}};0&&(module.exports={WarpMcp,buildWarpDirectIdentifierFromMcpToolCall,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertPromptActionToPrompt,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractTextOrUndefined,hasMcpAppUi,interpolatePromptWithArgs,isMcpToolCallAllowedForWarp,normalizeMcpToolNameToWarpIdentifier,resolveMcpAppInputsPayload,resolveMcpAppOutputPayload,resolveMcpAppWarpEmbedModel,resolveMcpToolCallToWarpDirect});
1
+ "use strict";var b=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var G=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Y(t))!Q.call(e,i)&&i!==n&&b(e,i,{get:()=>t[i],enumerable:!(r=H(t,i))||r.enumerable});return e};var X=e=>K(b({},"__esModule",{value:!0}),e);var ye={};G(ye,{WarpMcp:()=>z,buildAppMcpResourceMeta:()=>ne,buildWarpDirectIdentifierFromMcpToolCall:()=>D,buildZodInputSchema:()=>C,convertActionToTool:()=>x,convertMcpActionToTool:()=>P,convertMcpArgsToWarpInputs:()=>h,convertMcpToolToWarp:()=>I,convertPromptActionToPrompt:()=>S,convertWarpToMcpCapabilities:()=>U,convertWarpsToMcpCapabilities:()=>ce,createAppResource:()=>w,createMcpServerFromWarps:()=>We,extractTextOrUndefined:()=>f,hasMcpAppUi:()=>v,interpolatePromptWithArgs:()=>k,isMcpToolCallAllowedForWarp:()=>E,normalizeMcpToolNameToWarpIdentifier:()=>T,resolveMcpAppInputsPayload:()=>O,resolveMcpAppOutputPayload:()=>q,resolveMcpAppWarpEmbedModel:()=>te,resolveMcpToolCallToWarpDirect:()=>re});module.exports=X(ye);var y=e=>!e||typeof e!="object"||Array.isArray(e)?null:e,ee=e=>e==null?null:typeof e=="string"?e:JSON.stringify(e),O=e=>{let t=y(e.query);if(t)return t;let n=y(e.contentInputs);if(n)return n;let r=e.metaInputs||[];return r.length>0?{inputs:r}:null},q=e=>y(e.metaOutput)||y(e.contentOutput),te=e=>({isMcpApp:v(e.ui),inputsPayload:O({query:e.query,contentInputs:e.contentInputs,metaInputs:e.metaInputs}),outputPayload:q({metaOutput:e.metaOutput,contentOutput:e.contentOutput})}),v=e=>typeof e=="string"&&e!=="table",T=e=>!e||e.startsWith("@")?e:e.includes(":")?`@${e.replace(/^@/,"")}`:e,E=e=>e.activeWarpIdentifier?T(e.requestedToolName)===T(e.activeWarpIdentifier):!0,D=(e,t={})=>{let n=T(e),r=new URLSearchParams;return Object.entries(t).forEach(([i,o])=>{let a=ee(o);a!=null&&r.set(i,a)}),r.size>0?`${n}?${r.toString()}`:n},re=e=>{let t=E({requestedToolName:e.requestedToolName,activeWarpIdentifier:e.activeWarpIdentifier}),n=D(e.requestedToolName,e.args||{});return{allowed:t,warpIdentifier:n}};var _=require("@joai/warps"),h=(e,t)=>{let{action:n}=(0,_.getWarpInputAction)(e);return n.inputs?n.inputs.map(r=>{let i=r.as||r.name,o=t[i]??r.default??null;return o===null&&r.type==="bool"?"false":o==null?"":String(o)}):[]};var A={connectDomains:[],resourceDomains:[],frameDomains:[],baseUriDomains:[]},ne=e=>({ui:{prefersBorder:e?.prefersBorder??!0,csp:{connectDomains:e?.csp?.connectDomains??[...A.connectDomains],resourceDomains:e?.csp?.resourceDomains??[...A.resourceDomains],frameDomains:e?.csp?.frameDomains??[...A.frameDomains],baseUriDomains:e?.csp?.baseUriDomains??[...A.baseUriDomains]},permissions:e?.permissions??{},...e?.domain?{domain:e.domain}:{}}});var j=require("@joai/warps");var g=require("@joai/warps");var Z=require("@joai/warps"),l=require("zod");var oe=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},ie=(e,t)=>{let n,r=e.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=l.z.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=l.z.number():r==="bool"||r==="boolean"?n=l.z.boolean():r==="biguint"?n=l.z.string():n=l.z.string(),typeof e.min=="number"&&n instanceof l.z.ZodNumber&&(n=n.min(e.min)),typeof e.max=="number"&&n instanceof l.z.ZodNumber&&(n=n.max(e.max)),e.pattern&&n instanceof l.z.ZodString&&(n=n.regex(new RegExp(e.pattern)));let i=oe(e.options);if(i&&i.length>0){if(n instanceof l.z.ZodString)n=l.z.enum(i);else if(n instanceof l.z.ZodNumber){let u=i.map(p=>Number(p)).filter(p=>!isNaN(p));u.length>0&&(n=n.refine(p=>u.includes(p),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],a=f(e.description,t);a&&o.push(a),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 s=f(e.patternDescription,t);s&&o.push(s);let c=o.join(". ");return c&&(n=n.describe(c)),e.required!==!0&&(n=n.optional()),n},C=(e,t)=>{let n={};for(let r of e){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=ie(r,t)}return Object.keys(n).length>0?n:void 0},x=(e,t,n,r,i,o)=>{let a=se(e),s=r||t.inputs||[],c=C(s,o);return{name:a,description:n,inputSchema:c,meta:$(e,i,o)}},P=(e,t,n,r,i,o)=>{let a=r||t.inputs||[],s=C(a,o),c=t.destination?.tool;if(!c)throw new Error(`Tool name is required for MCP action ${t.type}`);return{name:c,description:n,inputSchema:s,meta:$(e,i,o)}},$=(e,t,n)=>{let r={visibility:["model","app"]};return t&&(r.resourceUri=t.uri),{ui:r}},se=e=>{let t=e.meta?.identifier;if(!t)throw new Error(`Warp identifier for warp ${e.name} is required`);return(0,Z.removeWarpChainPrefix)(t)};var R=require("@joai/warps"),pe="text/html;profile=mcp-app",ae=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}`)},w=async(e,t,n)=>{if(!e.meta?.identifier)return null;try{let r=await ae(t);return{name:e.name,uri:`ui://widget/${e.meta.identifier}`,description:`MCP app for ${e.name}`,mimeType:pe,content:r}}catch(r){let i=r instanceof Error?r.message:String(r),o=r instanceof Error?r.stack:void 0;return R.WarpLogger.error(`[MCP] Failed to create app resource for warp "${e.name}" (path: ${t}):`,i),o&&R.WarpLogger.error("[MCP] Error stack:",o),null}};var U=async(e,t)=>{let n=null,r=null,i=null;if(e.ui&&e.ui!=="table"&&(r=await w(e,e.ui,t)),e.actions.length===0)return{tool:null,resource:r,prompt:null};try{let{action:o}=(0,g.getWarpInputAction)(e),a=f(e.description,t)||f(o.description,t);if(o.type==="prompt")i=S(e,o,a,t);else if(o.type==="mcp"){let s=o;s.destination&&(n=P(e,s,a,o.inputs,r,t))}else n=x(e,o,a,o.inputs,r,t)}catch{return{tool:null,resource:r,prompt:null}}return{tool:n,resource:r,prompt:i}},ce=async(e,t)=>Promise.all(e.map(n=>U(n,t))),ue=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",I=async(e,t,n,r)=>{let i=[];if(t.inputSchema?.properties){let s=t.inputSchema.properties,c=t.inputSchema.required||[];Object.entries(s).forEach(([u,p])=>{let m=c.includes(u),d=ue(p.type||"string",p.format),M={name:u,label:typeof p.title=="string"?{en:p.title}:p.title||{en:u},description:p.description?{en:p.description.trim()}:null,type:d,position:`payload:${u}`,source:"field",required:m,...p.default!==void 0&&typeof p.default=="string"||typeof p.default=="number"||typeof p.default=="boolean"?{default:p.default}:{}};i.push(M)})}let o={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(s=>{o[s]=`out.${s}`});let a={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:n,tool:t.name,headers:r},inputs:i};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(a).setOutput(Object.keys(o).length>0?o:null).build(!1)},f=(e,t)=>e&&(0,g.resolveWarpText)(e,t)||void 0;var k=(e,t)=>{let n=e;for(let[r,i]of Object.entries(t)){let o=new RegExp(`\\{\\{\\s*${r}\\s*\\}\\}`,"g");n=n.replace(o,i??"")}return n},le=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,"_"),me=(e,t)=>{let n=[];for(let r of e){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name,o=f(r.description,t);n.push({name:i,description:o,required:r.required===!0})}return n},S=(e,t,n,r)=>{let i=le(e.name),o=t.inputs||[],a=me(o,r);return{name:i,description:n,arguments:a.length>0?a:void 0,prompt:(0,j.resolvePlatformValue)(t.prompt,r.platform)}};var N=require("@modelcontextprotocol/sdk/server/mcp.js"),F=require("@modelcontextprotocol/sdk/server/zod-compat.js"),W=require("@modelcontextprotocol/ext-apps/server"),J=require("zod");var de=e=>{if(e)return typeof e=="object"&&"_zod"in e?e._zod:typeof e=="object"&&!Array.isArray(e)&&(0,F.normalizeObjectSchema)(e)||e},fe=e=>{if(!e.arguments||e.arguments.length===0)return;let t={};for(let n of e.arguments){let r=J.z.string();n.description&&(r=r.describe(n.description)),n.required||(r=r.optional()),t[n.name]=r}return t},ge=(e,t)=>e.startsWith("ui://")?!0:t?.includes("profile=mcp-app")??!1,We=(e,t,n,r)=>{let i=new N.McpServer({name:e.name,version:e.version||"1.0.0"});for(let o=0;o<n.length;o++){let{tool:a,resource:s,prompt:c}=n[o],u=t[o];if(a){let p=de(a.inputSchema),m={description:a.description||"",inputSchema:p,...a.meta&&{_meta:a.meta}},d=async M=>{let B=h(u,M||{});return await r(u,B)};a.meta?.ui?.resourceUri?(0,W.registerAppTool)(i,a.name,m,d):i.registerTool(a.name,m,d)}if(s)if(ge(s.uri,s.mimeType)){let p=s.meta,m=s.mimeType||W.RESOURCE_MIME_TYPE;(0,W.registerAppResource)(i,s.name||s.uri,s.uri,{description:s.description,mimeType:m,...p&&{_meta:p}},async()=>{let d={uri:s.uri,text:s.content||"",mimeType:m};return p&&(d._meta=p),{contents:[d]}})}else i.registerResource(s.name||s.uri,s.uri,{description:s.description,mimeType:s.mimeType},async()=>{let p={uri:s.uri,text:s.content||"",mimeType:s.mimeType};return s.meta&&(p._meta=s.meta),{contents:[p]}});if(c){let p=fe(c);i.registerPrompt(c.name,{description:c.description||"",argsSchema:p},m=>({messages:[{role:"user",content:{type:"text",text:k(c.prompt,m)}}]}))}}return i};var L=require("@modelcontextprotocol/sdk/client/index.js"),V=require("@modelcontextprotocol/sdk/client/streamableHttp.js");var z=class{constructor(t){this.config=t}async getWarpsFromTools(t,n){let r=new V.StreamableHTTPClientTransport(new URL(t),{requestInit:{headers:n||{}}}),i=new L.Client({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(r);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(a=>I(this.config,a,t,n)))}catch(o){throw await i.close().catch(()=>{}),o}}};0&&(module.exports={WarpMcp,buildAppMcpResourceMeta,buildWarpDirectIdentifierFromMcpToolCall,buildZodInputSchema,convertActionToTool,convertMcpActionToTool,convertMcpArgsToWarpInputs,convertMcpToolToWarp,convertPromptActionToPrompt,convertWarpToMcpCapabilities,convertWarpsToMcpCapabilities,createAppResource,createMcpServerFromWarps,extractTextOrUndefined,hasMcpAppUi,interpolatePromptWithArgs,isMcpToolCallAllowedForWarp,normalizeMcpToolNameToWarpIdentifier,resolveMcpAppInputsPayload,resolveMcpAppOutputPayload,resolveMcpAppWarpEmbedModel,resolveMcpToolCallToWarpDirect});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var g=t=>!t||typeof t!="object"||Array.isArray(t)?null:t,k=t=>t==null?null:typeof t=="string"?t:JSON.stringify(t),z=t=>{let e=g(t.query);if(e)return e;let n=g(t.contentInputs);if(n)return n;let r=t.metaInputs||[];return r.length>0?{inputs:r}:null},O=t=>g(t.metaOutput)||g(t.contentOutput),at=t=>({isMcpApp:q(t.ui),inputsPayload:z({query:t.query,contentInputs:t.contentInputs,metaInputs:t.metaInputs}),outputPayload:O({metaOutput:t.metaOutput,contentOutput:t.contentOutput})}),q=t=>typeof t=="string"&&t!=="table",y=t=>!t||t.startsWith("@")?t:t.includes(":")?`@${t.replace(/^@/,"")}`:t,v=t=>t.activeWarpIdentifier?y(t.requestedToolName)===y(t.activeWarpIdentifier):!0,E=(t,e={})=>{let n=y(t),r=new URLSearchParams;return Object.entries(e).forEach(([i,o])=>{let c=k(o);c!=null&&r.set(i,c)}),r.size>0?`${n}?${r.toString()}`:n},ut=t=>{let e=v({requestedToolName:t.requestedToolName,activeWarpIdentifier:t.activeWarpIdentifier}),n=E(t.requestedToolName,t.args||{});return{allowed:e,warpIdentifier:n}};import{getWarpInputAction as _}from"@joai/warps";var T=(t,e)=>{let{action:n}=_(t);return n.inputs?n.inputs.map(r=>{let i=r.as||r.name,o=e[i]??r.default??null;return o===null&&r.type==="bool"?"false":o==null?"":String(o)}):[]};import{resolvePlatformValue as Y}from"@joai/warps";import{WarpBuilder as F,getWarpInputAction as J,resolveWarpText as V}from"@joai/warps";import{removeWarpChainPrefix as Z}from"@joai/warps";import{z as l}from"zod";var $=t=>{if(t){if(Array.isArray(t))return t;if(typeof t=="object")return Object.keys(t)}},j=(t,e)=>{let n,r=t.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=l.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=l.number():r==="bool"||r==="boolean"?n=l.boolean():r==="biguint"?n=l.string():n=l.string(),typeof t.min=="number"&&n instanceof l.ZodNumber&&(n=n.min(t.min)),typeof t.max=="number"&&n instanceof l.ZodNumber&&(n=n.max(t.max)),t.pattern&&n instanceof l.ZodString&&(n=n.regex(new RegExp(t.pattern)));let i=$(t.options);if(i&&i.length>0){if(n instanceof l.ZodString)n=l.enum(i);else if(n instanceof l.ZodNumber){let u=i.map(s=>Number(s)).filter(s=>!isNaN(s));u.length>0&&(n=n.refine(s=>u.includes(s),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],c=f(t.description,e);c&&o.push(c),t.bot&&o.push(t.bot),o.push(`Type: ${t.type}`),o.push(t.required?"Required":"Optional"),i&&i.length>0&&o.push(`Options: ${i.join(", ")}`);let p=f(t.patternDescription,e);p&&o.push(p);let a=o.join(". ");return a&&(n=n.describe(a)),t.required!==!0&&(n=n.optional()),n},A=(t,e)=>{let n={};for(let r of t){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=j(r,e)}return Object.keys(n).length>0?n:void 0},M=(t,e,n,r,i,o)=>{let c=U(t),p=r||e.inputs||[],a=A(p,o);return{name:c,description:n,inputSchema:a,meta:b(t,i,o)}},h=(t,e,n,r,i,o)=>{let c=r||e.inputs||[],p=A(c,o),a=e.destination?.tool;if(!a)throw new Error(`Tool name is required for MCP action ${e.type}`);return{name:a,description:n,inputSchema:p,meta:b(t,i,o)}},b=(t,e,n)=>{let r={visibility:["model","app"]};return e&&(r.resourceUri=e.uri),{ui:r}},U=t=>{let e=t.meta?.identifier;if(!e)throw new Error(`Warp identifier for warp ${t.name} is required`);return Z(e)};import{WarpLogger as C}from"@joai/warps";var N="text/html;profile=mcp-app",D=async t=>{if(t.startsWith("http://")||t.startsWith("https://")){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to download component from ${t}: HTTP ${e.status} ${e.statusText}`);return e.text()}throw new Error(`Unsupported component path: ${t}`)},x=async(t,e,n)=>{if(!t.meta?.identifier)return null;try{let r=await D(e);return{name:t.name,uri:`ui://widget/${t.meta.identifier}`,description:`MCP app for ${t.name}`,mimeType:N,content:r}}catch(r){let i=r instanceof Error?r.message:String(r),o=r instanceof Error?r.stack:void 0;return C.error(`[MCP] Failed to create app resource for warp "${t.name}" (path: ${e}):`,i),o&&C.error("[MCP] Error stack:",o),null}};var L=async(t,e)=>{let n=null,r=null,i=null;if(t.ui&&t.ui!=="table"&&(r=await x(t,t.ui,e)),t.actions.length===0)return{tool:null,resource:r,prompt:null};try{let{action:o}=J(t),c=f(t.description,e)||f(o.description,e);if(o.type==="prompt")i=w(t,o,c,e);else if(o.type==="mcp"){let p=o;p.destination&&(n=h(t,p,c,o.inputs,r,e))}else n=M(t,o,c,o.inputs,r,e)}catch{return{tool:null,resource:r,prompt:null}}return{tool:n,resource:r,prompt:i}},Nt=async(t,e)=>Promise.all(t.map(n=>L(n,e))),H=(t,e)=>e==="date-time"||e==="date"||t==="string"?"string":t==="number"||t==="integer"?"uint256":t==="boolean"?"bool":"string",P=async(t,e,n,r)=>{let i=[];if(e.inputSchema?.properties){let p=e.inputSchema.properties,a=e.inputSchema.required||[];Object.entries(p).forEach(([u,s])=>{let m=a.includes(u),d=H(s.type||"string",s.format),W={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:m,...s.default!==void 0&&typeof s.default=="string"||typeof s.default=="number"||typeof s.default=="boolean"?{default:s.default}:{}};i.push(W)})}let o={};e.outputSchema?.properties&&Object.keys(e.outputSchema.properties).forEach(p=>{o[p]=`out.${p}`});let c={type:"mcp",label:{en:e.name},description:e.description?{en:e.description.trim()}:null,destination:{url:n,tool:e.name,headers:r},inputs:i};return await new F(t).setName(e.name||"unnamed_tool").setTitle({en:e.name||"Unnamed Tool"}).setDescription(e.description?{en:e.description.trim()}:null).addAction(c).setOutput(Object.keys(o).length>0?o:null).build(!1)},f=(t,e)=>t&&V(t,e)||void 0;var R=(t,e)=>{let n=t;for(let[r,i]of Object.entries(e)){let o=new RegExp(`\\{\\{\\s*${r}\\s*\\}\\}`,"g");n=n.replace(o,i??"")}return n},B=t=>(t.includes(":")?t.split(":").slice(1).join(":"):t).trim().toLowerCase().replace(/\s+/g,"_").replace(/:/g,"_").replace(/[^a-z0-9_.-]/g,"_").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").replace(/[_-]+/g,e=>e.includes("_")?"_":e).replace(/_+/g,"_"),Q=(t,e)=>{let n=[];for(let r of t){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name,o=f(r.description,e);n.push({name:i,description:o,required:r.required===!0})}return n},w=(t,e,n,r)=>{let i=B(t.name),o=e.inputs||[],c=Q(o,r);return{name:i,description:n,arguments:c.length>0?c:void 0,prompt:Y(e.prompt,r.platform)}};import{McpServer as G}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as K}from"@modelcontextprotocol/sdk/server/zod-compat.js";import{RESOURCE_MIME_TYPE as X,registerAppTool as tt,registerAppResource as et}from"@modelcontextprotocol/ext-apps/server";import{z as rt}from"zod";var nt=t=>{if(t)return typeof t=="object"&&"_zod"in t?t._zod:typeof t=="object"&&!Array.isArray(t)&&K(t)||t},ot=t=>{if(!t.arguments||t.arguments.length===0)return;let e={};for(let n of t.arguments){let r=rt.string();n.description&&(r=r.describe(n.description)),n.required||(r=r.optional()),e[n.name]=r}return e},it=(t,e)=>t.startsWith("ui://")?!0:e?.includes("profile=mcp-app")??!1,re=(t,e,n,r)=>{let i=new G({name:t.name,version:t.version||"1.0.0"});for(let o=0;o<n.length;o++){let{tool:c,resource:p,prompt:a}=n[o],u=e[o];if(c){let s=nt(c.inputSchema),m={description:c.description||"",inputSchema:s,...c.meta&&{_meta:c.meta}},d=async W=>{let S=T(u,W||{});return await r(u,S)};c.meta?.ui?.resourceUri?tt(i,c.name,m,d):i.registerTool(c.name,m,d)}if(p)if(it(p.uri,p.mimeType)){let s=p.meta,m=p.mimeType||X;et(i,p.name||p.uri,p.uri,{description:p.description,mimeType:m,...s&&{_meta:s}},async()=>{let d={uri:p.uri,text:p.content||"",mimeType:m};return s&&(d._meta=s),{contents:[d]}})}else i.registerResource(p.name||p.uri,p.uri,{description:p.description,mimeType:p.mimeType},async()=>{let s={uri:p.uri,text:p.content||"",mimeType:p.mimeType};return p.meta&&(s._meta=p.meta),{contents:[s]}});if(a){let s=ot(a);i.registerPrompt(a.name,{description:a.description||"",argsSchema:s},m=>({messages:[{role:"user",content:{type:"text",text:R(a.prompt,m)}}]}))}}return i};import{Client as pt}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as st}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var I=class{constructor(e){this.config=e}async getWarpsFromTools(e,n){let r=new st(new URL(e),{requestInit:{headers:n||{}}}),i=new pt({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(r);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(c=>P(this.config,c,e,n)))}catch(o){throw await i.close().catch(()=>{}),o}}};export{I as WarpMcp,E as buildWarpDirectIdentifierFromMcpToolCall,A as buildZodInputSchema,M as convertActionToTool,h as convertMcpActionToTool,T as convertMcpArgsToWarpInputs,P as convertMcpToolToWarp,w as convertPromptActionToPrompt,L as convertWarpToMcpCapabilities,Nt as convertWarpsToMcpCapabilities,x as createAppResource,re as createMcpServerFromWarps,f as extractTextOrUndefined,q as hasMcpAppUi,R as interpolatePromptWithArgs,v as isMcpToolCallAllowedForWarp,y as normalizeMcpToolNameToWarpIdentifier,z as resolveMcpAppInputsPayload,O as resolveMcpAppOutputPayload,at as resolveMcpAppWarpEmbedModel,ut as resolveMcpToolCallToWarpDirect};
1
+ var g=e=>!e||typeof e!="object"||Array.isArray(e)?null:e,z=e=>e==null?null:typeof e=="string"?e:JSON.stringify(e),O=e=>{let t=g(e.query);if(t)return t;let n=g(e.contentInputs);if(n)return n;let r=e.metaInputs||[];return r.length>0?{inputs:r}:null},q=e=>g(e.metaOutput)||g(e.contentOutput),ue=e=>({isMcpApp:v(e.ui),inputsPayload:O({query:e.query,contentInputs:e.contentInputs,metaInputs:e.metaInputs}),outputPayload:q({metaOutput:e.metaOutput,contentOutput:e.contentOutput})}),v=e=>typeof e=="string"&&e!=="table",T=e=>!e||e.startsWith("@")?e:e.includes(":")?`@${e.replace(/^@/,"")}`:e,E=e=>e.activeWarpIdentifier?T(e.requestedToolName)===T(e.activeWarpIdentifier):!0,D=(e,t={})=>{let n=T(e),r=new URLSearchParams;return Object.entries(t).forEach(([i,o])=>{let a=z(o);a!=null&&r.set(i,a)}),r.size>0?`${n}?${r.toString()}`:n},le=e=>{let t=E({requestedToolName:e.requestedToolName,activeWarpIdentifier:e.activeWarpIdentifier}),n=D(e.requestedToolName,e.args||{});return{allowed:t,warpIdentifier:n}};import{getWarpInputAction as _}from"@joai/warps";var A=(e,t)=>{let{action:n}=_(e);return n.inputs?n.inputs.map(r=>{let i=r.as||r.name,o=t[i]??r.default??null;return o===null&&r.type==="bool"?"false":o==null?"":String(o)}):[]};var W={connectDomains:[],resourceDomains:[],frameDomains:[],baseUriDomains:[]},ye=e=>({ui:{prefersBorder:e?.prefersBorder??!0,csp:{connectDomains:e?.csp?.connectDomains??[...W.connectDomains],resourceDomains:e?.csp?.resourceDomains??[...W.resourceDomains],frameDomains:e?.csp?.frameDomains??[...W.frameDomains],baseUriDomains:e?.csp?.baseUriDomains??[...W.baseUriDomains]},permissions:e?.permissions??{},...e?.domain?{domain:e.domain}:{}}});import{resolvePlatformValue as Y}from"@joai/warps";import{WarpBuilder as J,getWarpInputAction as L,resolveWarpText as V}from"@joai/warps";import{removeWarpChainPrefix as Z}from"@joai/warps";import{z as l}from"zod";var $=e=>{if(e){if(Array.isArray(e))return e;if(typeof e=="object")return Object.keys(e)}},U=(e,t)=>{let n,r=e.type.toLowerCase();r==="string"||r==="address"||r==="hex"?n=l.string():r==="number"||r==="uint8"||r==="uint16"||r==="uint32"||r==="uint64"||r==="uint128"||r==="uint256"?n=l.number():r==="bool"||r==="boolean"?n=l.boolean():r==="biguint"?n=l.string():n=l.string(),typeof e.min=="number"&&n instanceof l.ZodNumber&&(n=n.min(e.min)),typeof e.max=="number"&&n instanceof l.ZodNumber&&(n=n.max(e.max)),e.pattern&&n instanceof l.ZodString&&(n=n.regex(new RegExp(e.pattern)));let i=$(e.options);if(i&&i.length>0){if(n instanceof l.ZodString)n=l.enum(i);else if(n instanceof l.ZodNumber){let u=i.map(p=>Number(p)).filter(p=>!isNaN(p));u.length>0&&(n=n.refine(p=>u.includes(p),{message:`Value must be one of: ${u.join(", ")}`}))}}let o=[],a=f(e.description,t);a&&o.push(a),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 s=f(e.patternDescription,t);s&&o.push(s);let c=o.join(". ");return c&&(n=n.describe(c)),e.required!==!0&&(n=n.optional()),n},M=(e,t)=>{let n={};for(let r of e){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name;n[i]=U(r,t)}return Object.keys(n).length>0?n:void 0},b=(e,t,n,r,i,o)=>{let a=j(e),s=r||t.inputs||[],c=M(s,o);return{name:a,description:n,inputSchema:c,meta:C(e,i,o)}},h=(e,t,n,r,i,o)=>{let a=r||t.inputs||[],s=M(a,o),c=t.destination?.tool;if(!c)throw new Error(`Tool name is required for MCP action ${t.type}`);return{name:c,description:n,inputSchema:s,meta:C(e,i,o)}},C=(e,t,n)=>{let r={visibility:["model","app"]};return t&&(r.resourceUri=t.uri),{ui:r}},j=e=>{let t=e.meta?.identifier;if(!t)throw new Error(`Warp identifier for warp ${e.name} is required`);return Z(t)};import{WarpLogger as x}from"@joai/warps";var N="text/html;profile=mcp-app",F=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,n)=>{if(!e.meta?.identifier)return null;try{let r=await F(t);return{name:e.name,uri:`ui://widget/${e.meta.identifier}`,description:`MCP app for ${e.name}`,mimeType:N,content:r}}catch(r){let i=r instanceof Error?r.message:String(r),o=r instanceof Error?r.stack:void 0;return x.error(`[MCP] Failed to create app resource for warp "${e.name}" (path: ${t}):`,i),o&&x.error("[MCP] Error stack:",o),null}};var B=async(e,t)=>{let n=null,r=null,i=null;if(e.ui&&e.ui!=="table"&&(r=await P(e,e.ui,t)),e.actions.length===0)return{tool:null,resource:r,prompt:null};try{let{action:o}=L(e),a=f(e.description,t)||f(o.description,t);if(o.type==="prompt")i=w(e,o,a,t);else if(o.type==="mcp"){let s=o;s.destination&&(n=h(e,s,a,o.inputs,r,t))}else n=b(e,o,a,o.inputs,r,t)}catch{return{tool:null,resource:r,prompt:null}}return{tool:n,resource:r,prompt:i}},Je=async(e,t)=>Promise.all(e.map(n=>B(n,t))),H=(e,t)=>t==="date-time"||t==="date"||e==="string"?"string":e==="number"||e==="integer"?"uint256":e==="boolean"?"bool":"string",R=async(e,t,n,r)=>{let i=[];if(t.inputSchema?.properties){let s=t.inputSchema.properties,c=t.inputSchema.required||[];Object.entries(s).forEach(([u,p])=>{let m=c.includes(u),d=H(p.type||"string",p.format),y={name:u,label:typeof p.title=="string"?{en:p.title}:p.title||{en:u},description:p.description?{en:p.description.trim()}:null,type:d,position:`payload:${u}`,source:"field",required:m,...p.default!==void 0&&typeof p.default=="string"||typeof p.default=="number"||typeof p.default=="boolean"?{default:p.default}:{}};i.push(y)})}let o={};t.outputSchema?.properties&&Object.keys(t.outputSchema.properties).forEach(s=>{o[s]=`out.${s}`});let a={type:"mcp",label:{en:t.name},description:t.description?{en:t.description.trim()}:null,destination:{url:n,tool:t.name,headers:r},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(a).setOutput(Object.keys(o).length>0?o:null).build(!1)},f=(e,t)=>e&&V(e,t)||void 0;var I=(e,t)=>{let n=e;for(let[r,i]of Object.entries(t)){let o=new RegExp(`\\{\\{\\s*${r}\\s*\\}\\}`,"g");n=n.replace(o,i??"")}return n},Q=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,"_"),G=(e,t)=>{let n=[];for(let r of e){if(r.source==="hidden"||r.source!=="field")continue;let i=r.as||r.name,o=f(r.description,t);n.push({name:i,description:o,required:r.required===!0})}return n},w=(e,t,n,r)=>{let i=Q(e.name),o=t.inputs||[],a=G(o,r);return{name:i,description:n,arguments:a.length>0?a:void 0,prompt:Y(t.prompt,r.platform)}};import{McpServer as K}from"@modelcontextprotocol/sdk/server/mcp.js";import{normalizeObjectSchema as X}from"@modelcontextprotocol/sdk/server/zod-compat.js";import{RESOURCE_MIME_TYPE as ee,registerAppTool as te,registerAppResource as re}from"@modelcontextprotocol/ext-apps/server";import{z as ne}from"zod";var oe=e=>{if(e)return typeof e=="object"&&"_zod"in e?e._zod:typeof e=="object"&&!Array.isArray(e)&&X(e)||e},ie=e=>{if(!e.arguments||e.arguments.length===0)return;let t={};for(let n of e.arguments){let r=ne.string();n.description&&(r=r.describe(n.description)),n.required||(r=r.optional()),t[n.name]=r}return t},se=(e,t)=>e.startsWith("ui://")?!0:t?.includes("profile=mcp-app")??!1,it=(e,t,n,r)=>{let i=new K({name:e.name,version:e.version||"1.0.0"});for(let o=0;o<n.length;o++){let{tool:a,resource:s,prompt:c}=n[o],u=t[o];if(a){let p=oe(a.inputSchema),m={description:a.description||"",inputSchema:p,...a.meta&&{_meta:a.meta}},d=async y=>{let k=A(u,y||{});return await r(u,k)};a.meta?.ui?.resourceUri?te(i,a.name,m,d):i.registerTool(a.name,m,d)}if(s)if(se(s.uri,s.mimeType)){let p=s.meta,m=s.mimeType||ee;re(i,s.name||s.uri,s.uri,{description:s.description,mimeType:m,...p&&{_meta:p}},async()=>{let d={uri:s.uri,text:s.content||"",mimeType:m};return p&&(d._meta=p),{contents:[d]}})}else i.registerResource(s.name||s.uri,s.uri,{description:s.description,mimeType:s.mimeType},async()=>{let p={uri:s.uri,text:s.content||"",mimeType:s.mimeType};return s.meta&&(p._meta=s.meta),{contents:[p]}});if(c){let p=ie(c);i.registerPrompt(c.name,{description:c.description||"",argsSchema:p},m=>({messages:[{role:"user",content:{type:"text",text:I(c.prompt,m)}}]}))}}return i};import{Client as pe}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as ae}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var S=class{constructor(t){this.config=t}async getWarpsFromTools(t,n){let r=new ae(new URL(t),{requestInit:{headers:n||{}}}),i=new pe({name:"warps-mcp-client",version:"1.0.0"},{capabilities:{}});try{await i.connect(r);let o=await i.listTools();return await i.close(),await Promise.all(o.tools.map(a=>R(this.config,a,t,n)))}catch(o){throw await i.close().catch(()=>{}),o}}};export{S as WarpMcp,ye as buildAppMcpResourceMeta,D as buildWarpDirectIdentifierFromMcpToolCall,M as buildZodInputSchema,b as convertActionToTool,h as convertMcpActionToTool,A as convertMcpArgsToWarpInputs,R as convertMcpToolToWarp,w as convertPromptActionToPrompt,B as convertWarpToMcpCapabilities,Je as convertWarpsToMcpCapabilities,P as createAppResource,it as createMcpServerFromWarps,f as extractTextOrUndefined,v as hasMcpAppUi,I as interpolatePromptWithArgs,E as isMcpToolCallAllowedForWarp,T as normalizeMcpToolNameToWarpIdentifier,O as resolveMcpAppInputsPayload,q as resolveMcpAppOutputPayload,ue as resolveMcpAppWarpEmbedModel,le as resolveMcpToolCallToWarpDirect};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joai/warps-mcp",
3
- "version": "12.0.1",
3
+ "version": "12.1.0",
4
4
  "description": "MCP adapter for Warps SDK",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",