@mistflow-ai/mcp 0.4.0 → 0.4.1-staging.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.
@@ -0,0 +1 @@
1
+ import{A as s,B as t,C as u,D as v,E as w,F as x,G as y,H as z,I as A,J as B,K as C,L as D,M as E,N as F,O as G,P as H,Q as I,R as J,S as K,T as L,U as M,V as N,W as O,X as P,Y as Q,Z as R,_ as S,h as a,j as b,k as c,l as d,m as e,n as f,o as g,p as h,q as i,r as j,s as k,t as l,u as m,v as n,w as o,x as p,y as q,z as r}from"./chunk-OIW7LXTF.js";export{e as MistflowApiError,u as addDomain,i as checkAuth,j as checkAuthDetailed,l as checkSubdomain,n as createDeployment,m as createProject,D as deleteEnvVar,t as discoverDecisions,K as downloadSource,Q as downloadSourceWithToken,q as fetchDesignDirections,N as fetchModule,L as fetchScaffold,M as fetchStepContext,P as forkTemplate,r as generatePlan,f as getAuthHeaders,b as getBaseUrl,d as getDashboardUrl,y as getDbCredentials,E as getDeployLogs,p as getDeploymentStatus,k as getProject,F as getProjectErrors,z as getSeedInfo,c as getSiteUrl,O as getTemplate,a as hasCredentialsOnDisk,h as hasLocalCredentials,G as listDeployments,v as listDomains,B as listEnvVars,R as markLocalSetupDone,s as modifyPlan,g as pingBackend,I as promotePreview,H as redeployProject,x as removeDomain,J as rollbackDeployment,S as shareProject,o as uploadAndDeploy,A as uploadQAResults,C as upsertEnvVar,w as verifyDomain};
@@ -1,2 +1,2 @@
1
- import{a as o,b as s,j as i,n as a}from"./chunk-Y3F6QWAR.js";import{existsSync as u,readFileSync as f,writeFileSync as d,mkdirSync as m}from"fs";import{join as l}from"path";function p(t){return l(t,".mistflow","state.json")}function P(t){let e=p(t);if(!u(e))return null;try{return JSON.parse(f(e,"utf-8"))}catch{return null}}function w(t,e){let r=l(t,".mistflow");u(r)||m(r,{recursive:!0}),d(p(t),JSON.stringify(e,null,2)+`
1
+ import{a as o,b as s,j as i,n as a}from"./chunk-OIW7LXTF.js";import{existsSync as u,readFileSync as f,writeFileSync as d,mkdirSync as m}from"fs";import{join as l}from"path";function p(t){return l(t,".mistflow","state.json")}function P(t){let e=p(t);if(!u(e))return null;try{return JSON.parse(f(e,"utf-8"))}catch{return null}}function w(t,e){let r=l(t,".mistflow");u(r)||m(r,{recursive:!0}),d(p(t),JSON.stringify(e,null,2)+`
2
2
  `)}function C(t,e){return{projectId:t,name:e,template:"",features:[],dbSchema:[],deployCount:0,decisions:[],provenance:[]}}async function x(t){let e;try{e=a()}catch{return null}try{let r=await fetch(`${i()}/api/projects/${encodeURIComponent(t)}/state`,{headers:{...e,"Content-Type":"application/json","X-Mistflow-MCP-Version":o()}});try{s(r.headers)}catch{}return r.ok?await r.json():null}catch{return null}}async function R(t,e){let r;try{r=a()}catch{return!1}try{let n=await fetch(`${i()}/api/projects/${encodeURIComponent(t)}/state`,{method:"PUT",headers:{...r,"Content-Type":"application/json","X-Mistflow-MCP-Version":o()},body:JSON.stringify(e)});try{s(n.headers)}catch{}return n.ok}catch{return!1}}function L(t,e){let r=t.toLowerCase(),n=e.toLowerCase();return n.includes(r)||r.includes(n)?!0:r.split(/\s+/).some(c=>c.length>=3&&n.includes(c))}export{p as a,P as b,w as c,C as d,x as e,R as f,L as g};
@@ -0,0 +1,23 @@
1
+ import{readFileSync as $,existsSync as P,writeFileSync as z,mkdirSync as G,renameSync as X,unlinkSync as Y}from"fs";import{join as v,dirname as Z}from"path";import{homedir as ee}from"os";import{randomBytes as te}from"crypto";function M(){return v(ee(),".mistflow","credentials.json")}function x(){return(process.env.MISTFLOW_API_URL||"https://api.mistflow.ai").replace(/\/+$/,"")}var ne="https://api.mistflow.ai";function E(){let e=M();if(!P(e))return null;try{let t=JSON.parse($(e,"utf-8"));return typeof t.apiKey=="string"?{[ne]:t}:t}catch{return null}}function m(){let e=process.env.MISTFLOW_API_KEY;if(e)return{ok:!0,creds:{apiKey:e,orgId:"",orgSlug:"env"}};let t=E();if(!t)return{ok:!1,reason:"missing"};let n=x(),r=t[n];return r&&typeof r.apiKey=="string"&&r.apiKey&&typeof r.orgId=="string"?{ok:!0,creds:r}:{ok:!1,reason:"missing"}}function Re(e){let t=M(),n=Z(t);P(n)||G(n,{recursive:!0});let r=E()??{},o=x();r[o]=e;let s=v(n,`.credentials.tmp.${te(8).toString("hex")}`);try{z(s,JSON.stringify(r,null,2)+`
2
+ `,{mode:384}),X(s,t)}catch(c){try{Y(s)}catch{}throw c}}function xe(){let e=m();return e.ok?e.creds:null}function re(){return m().ok}function Se(e){let t=v(e,"mistflow.json");if(!P(t))return null;try{return JSON.parse($(t,"utf-8"))}catch{return null}}import{existsSync as I,readFileSync as F,writeFileSync as oe,mkdirSync as se}from"fs";import{join as D,dirname as U}from"path";import{homedir as ie}from"os";import{fileURLToPath as ae}from"url";var S=null;function f(){if(S)return S;try{let e=ae(import.meta.url),t=U(e);for(let n=0;n<6;n++){let r=D(t,"package.json");if(I(r)){let s=JSON.parse(F(r,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return S=s.version,s.version}let o=U(t);if(o===t)break;t=o}}catch{}return S="0.0.0","0.0.0"}function k(e){let t=/^(\d+)\.(\d+)\.(\d+)/.exec(e.trim());return t?[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3],10)]:null}function j(e,t){let n=k(e),r=k(t);if(!n||!r)return 0;for(let o=0;o<3;o++){if(n[o]<r[o])return-1;if(n[o]>r[o])return 1}return 0}function V(e,t,n){if(n&&j(e,n)<0)return"unsupported";if(!t||j(e,t)>=0)return"none";let o=k(e),s=k(t);return!o||!s?"none":o[0]<s[0]?"major":o[1]<s[1]?"minor":"patch"}var u=null;function L(e){let t=e.get("x-mistflow-mcp-latest")??"",n=e.get("x-mistflow-mcp-min-supported")??"",r=e.get("x-mistflow-mcp-changelog-url")??"";!t&&!n||(u={latest:t,minSupported:n,changelogUrl:r})}function N(){let e=process.env.MISTFLOW_STATE_DIR||D(ie(),".mistflow");return D(e,"upgrade-state.json")}function ce(){try{let e=N();return I(e)?JSON.parse(F(e,"utf-8")):{}}catch{return{}}}function le(e){try{let t=N(),n=U(t);I(n)||se(n,{recursive:!0}),oe(t,JSON.stringify(e,null,2)+`
3
+ `,{mode:384})}catch{}}var A=!1;function ue(e){return e==="patch"?7*864e5:e==="minor"?1*864e5:0}function De(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!u)return null;let e=f();if(e==="0.0.0")return null;let t=V(e,u.latest,u.minSupported);if(t==="none")return null;if(t==="unsupported")return O(t,e,u);if(A)return null;let n=ce(),r=Date.now(),o=ue(t);return n.dismissedForVersion===u.latest&&t!=="major"||n.lastLatestSeen===u.latest&&n.lastShownMs&&r-n.lastShownMs<o?null:(A=!0,le({...n,lastShownMs:r,lastLatestSeen:u.latest}),O(t,e,u))}function O(e,t,n){let r="npx -y mistflow-ai install",o=n.changelogUrl?`
4
+ What's new: ${n.changelogUrl}`:"";return e==="unsupported"?`
5
+
6
+ ---
7
+ Mistflow ${t} is no longer supported.
8
+ You must upgrade to ${n.latest} or newer to continue:
9
+
10
+ ${r}
11
+
12
+ After upgrading, restart your AI editor.${o}
13
+ ---`:e==="major"?`
14
+
15
+ ---
16
+ Mistflow ${n.latest} is available (you have ${t}).
17
+ This is a major update. Run \`${r}\` and restart your editor.${o}
18
+ ---`:e==="minor"?`
19
+
20
+ --- Mistflow update available: ${t} -> ${n.latest} ---
21
+ Run \`${r}\` to upgrade, then restart your editor.${o}`:`
22
+
23
+ (Mistflow ${n.latest} is out, you have ${t}. Run \`${r}\` when convenient.)`}function Ue(){let e=f(),t=u??{latest:"",minSupported:"",changelogUrl:""},n=V(e,t.latest,t.minSupported);return{current:e,latest:t.latest,minSupported:t.minSupported,severity:n,upgradeCmd:"npx -y mistflow-ai install",changelogUrl:t.changelogUrl,backendSignalReceived:u!==null}}function y(){return x()}function Me(){let e=process.env.MISTFLOW_API_URL;if(e){if(e.includes("mistflow.localhost"))return e.replace("api.mistflow","mistflow");if(e.includes("localhost:9100"))return e.replace(":9100",":9102")}return"https://mistflow.ai"}function Ee(){let e=process.env.MISTFLOW_API_URL;if(e){if(e.includes("mistflow.localhost"))return e.replace("api.mistflow","app.mistflow");if(e.includes("localhost:9100"))return e.replace(":9100",":9101")}return"https://app.mistflow.ai"}var a=class extends Error{constructor(n,r,o,s){super(r);this.code=n;this.statusCode=o;this.details=s;this.name="MistflowApiError"}get isAuth(){return this.code.startsWith("auth_")}get isTransient(){return this.code==="server_error"||this.code==="upstream_error"||this.code==="network_error"||this.code==="rate_limited"}};function pe(){let e=m();if(!e.ok)throw new a("auth_missing","No Mistflow credentials found.",401);return de(e.creds)}function de(e){return{Authorization:`ApiKey ${e.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":f()}}function h(e){try{L(e.headers)}catch{}}async function je(){try{let e=await fetch(`${y()}/health`,{method:"GET",signal:AbortSignal.timeout(5e3)});h(e)}catch{}}async function q(e,t,n,r){for(let o=0;o<2;o++)try{return await fetch(e,{...t,signal:AbortSignal.timeout(n)})}catch(s){let c=s instanceof Error&&s.name==="TimeoutError",p=s instanceof TypeError;if(r&&o===0&&(c||p)){console.error(`[api] Retrying ${e} after ${c?"timeout":"network error"}`);continue}throw s}throw new Error("fetchWithRetry: exhausted retries")}async function _(e){let t=null;try{t=await e.json()}catch{t=null}let n=t&&typeof t.code=="string"?t.code:void 0,r=t&&typeof t.message=="string"?t.message:t&&typeof t.detail=="string"?t.detail:e.statusText||"Request failed";if(n)return new a(n,r,e.status,t?.details);let o=e.status;return o===401?new a("auth_invalid",r,o):o===403?new a("permission_denied",r,o):o===404?new a("not_found",r,o):o===409?new a("conflict",r,o):o===422?new a("validation_error",r,o):o===429?new a("rate_limited",r,o):o>=500?new a("server_error",e.statusText||"Internal server error",o):new a("client_error",r,o)}async function i(e,t={}){let n=pe(),{timeoutMs:r,idempotent:o,...s}=t,c=r??3e4,p=(s.method??"GET").toUpperCase(),d=o??(p==="GET"||p==="HEAD"),l;try{l=await q(`${y()}${e}`,{...s,headers:{...n,...s.headers}},c,d)}catch(R){throw R instanceof Error&&R.name==="TimeoutError"?new a("network_error","Request timed out. Try again in a moment."):new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(h(l),!l.ok)throw await _(l);return l.json()}function ge(){return m().ok}var b=null,B=0,fe=300*1e3;async function Ae(){return(await me()).ok}async function me(){if(b!==null&&Date.now()<B)return b?{ok:!0}:{ok:!1,reason:"no_credentials"};if(!ge())return{ok:!1,reason:"no_credentials"};try{return await i("/api/org"),b=!0,B=Date.now()+fe,{ok:!0}}catch(e){if(b=null,!(e instanceof a))return{ok:!1,reason:"network_error"};switch(e.code){case"auth_missing":case"auth_revoked":return{ok:!1,reason:"no_credentials"};case"auth_expired":case"auth_invalid":case"auth_org_not_found":return{ok:!1,reason:"expired"};case"network_error":return{ok:!1,reason:"network_error"};case"rate_limited":case"server_error":case"upstream_error":return{ok:!1,reason:"server_error"};default:return{ok:!1,reason:"server_error"}}}}async function Oe(e){return i(`/api/projects/${encodeURIComponent(e)}`)}async function Fe(e){return i(`/api/projects/check-subdomain?name=${encodeURIComponent(e)}`)}async function Ve(e,t,n="neon",r){return i("/api/projects",{method:"POST",body:JSON.stringify({name:e,template:t,db_provider:n,requested_subdomain:r})})}async function Le(e,t){return i("/api/deploy",{method:"POST",body:JSON.stringify({project_id:e,build_output_url:t})})}async function Ne(e,t,n="production",r,o,s,c){let{readFileSync:p}=await import("fs"),{basename:d}=await import("path"),l=m();if(!l.ok)throw new a("auth_missing","No Mistflow credentials found.",401);let R=l.creds,K=p(t),J=new Blob([K],{type:"application/gzip"}),g=new FormData;if(g.append("project_id",e),g.append("build",J,d(t)),n!=="production"&&g.append("environment",n),r&&g.append("admin_email",r),o&&g.append("schema_pushed","true"),s){let{existsSync:H}=await import("fs");if(H(s)){let W=p(s),Q=new Blob([W],{type:"application/gzip"});g.append("source",Q,"source.tar.gz")}}c&&g.append("git_commit_sha",c);let w;try{w=await fetch(`${y()}/api/deploy/upload`,{method:"POST",headers:{Authorization:`ApiKey ${R.apiKey}`,"X-Mistflow-MCP-Version":f()},body:g,signal:AbortSignal.timeout(3e5)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(h(w),!w.ok)throw await _(w);let T=await w.json();return{...T,id:T.deployment_id}}async function Be(e){return i(`/api/deploy/${encodeURIComponent(e)}/status`)}async function qe(e){return i(`/api/plan/design-directions/${encodeURIComponent(e)}`,{timeoutMs:15e3})}async function Ke(e,t){let n={description:e,conversation_id:t?.conversationId,answers:t?.answers};t?.autonomous&&(n.autonomous=!0),t?.language&&t.language.toLowerCase()!=="english"&&(n.language=t.language),t?.designConversationId&&(n.design_conversation_id=t.designConversationId),t?.designDirection&&(n.design_direction=t.designDirection);let r=t?.conversationId||t?.answers||t?.designConversationId?18e4:6e4;return i("/api/plan",{method:"POST",body:JSON.stringify(n),timeoutMs:r,idempotent:!1})}async function Je(e,t){return i("/api/plan/modify",{method:"POST",body:JSON.stringify({existing_plan:e,modification:t})})}async function He(e){return i("/api/plan/discover",{method:"POST",body:JSON.stringify({description:e})})}async function We(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains`,{method:"POST",body:JSON.stringify({domain:t})})}async function Qe(e){return i(`/api/projects/${encodeURIComponent(e)}/domains`)}async function ze(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}/verify`)}async function Ge(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}`,{method:"DELETE"})}async function Xe(e){return i(`/api/projects/${encodeURIComponent(e)}/db-credentials`)}async function Ye(e){try{return await i(`/api/projects/${encodeURIComponent(e)}/test-accounts`)}catch(t){return t instanceof a&&(t.statusCode===404||t.code==="not_found")||console.error("[api] Failed to fetch seed info:",t instanceof Error?t.message:t),null}}async function Ze(e,t){try{return await i(`/api/deploy/${encodeURIComponent(e)}/qa-results`,{method:"POST",body:JSON.stringify(t)})}catch(n){return console.error("[api] Failed to upload QA results:",n instanceof Error?n.message:n),null}}async function et(e){return i(`/api/projects/${encodeURIComponent(e)}/env`)}async function tt(e,t,n,r){return i(`/api/projects/${encodeURIComponent(e)}/env`,{method:"PUT",body:JSON.stringify({key:t,value:n,category:r?.category??"custom",description:r?.description,setup_url:r?.setupUrl})})}async function nt(e,t){return i(`/api/projects/${encodeURIComponent(e)}/env/${encodeURIComponent(t)}`,{method:"DELETE"})}async function rt(e){return i(`/api/deploy/${encodeURIComponent(e)}/logs`)}async function ot(e,t="7d"){return i(`/api/projects/${encodeURIComponent(e)}/errors?period=${encodeURIComponent(t)}`)}async function st(e){return i(`/api/projects/${encodeURIComponent(e)}/deployments`)}async function it(e){return i(`/api/deploy/${encodeURIComponent(e)}/redeploy`,{method:"POST"})}async function at(e,t){let n=new URLSearchParams({preview_deployment_id:t});return i(`/api/deploy/${encodeURIComponent(e)}/promote`,{method:"POST",body:n.toString(),headers:{"Content-Type":"application/x-www-form-urlencoded"}})}async function ct(e){return i(`/api/deploy/${encodeURIComponent(e)}/rollback`,{method:"POST"})}async function lt(e,t){let n=m();if(!n.ok)throw new a("auth_missing","Not authenticated.",401);let r=n.creds,o=await fetch(`${y()}/api/deploy/${encodeURIComponent(e)}/source`,{headers:{Authorization:`ApiKey ${r.apiKey}`,"X-Mistflow-MCP-Version":f()},signal:AbortSignal.timeout(12e4)});if(h(o),!o.ok)throw await _(o);let{writeFileSync:s}=await import("fs"),c=Buffer.from(await o.arrayBuffer());s(t,c)}async function C(e,t){let{timeoutMs:n,idempotent:r,...o}=t??{},s=n??3e4,c=(o.method??"GET").toUpperCase(),p=r??(c==="GET"||c==="HEAD"),d;try{d=await q(`${y()}${e}`,{headers:{"Content-Type":"application/json","X-Mistflow-MCP-Version":f()},...o},s,p)}catch(l){throw l instanceof Error&&l.name==="TimeoutError"?new a("network_error","Request timed out. Try again in a moment."):new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(h(d),!d.ok)throw await _(d);return d.json()}async function ut(e="nextjs"){return C(`/api/scaffold/${encodeURIComponent(e)}`)}async function pt(e,t){return C(`/api/scaffold/${encodeURIComponent(e)}/context?step_type=${encodeURIComponent(t)}`)}async function dt(e,t,n,r){return C(`/api/scaffold/${encodeURIComponent(e)}/module`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"crud",entity:t,fields:n,entity_plural:r})})}async function gt(e){return C(`/api/templates/${encodeURIComponent(e)}`)}async function ft(e){return i(`/api/templates/${encodeURIComponent(e)}/fork`,{method:"POST"})}async function mt(e,t,n){let r;try{r=await fetch(`${y()}/api/deploy/${encodeURIComponent(e)}/fork-source?fork_token=${encodeURIComponent(t)}`,{headers:{"X-Mistflow-MCP-Version":f()},signal:AbortSignal.timeout(12e4)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(h(r),!r.ok)throw r.status===401?new a("validation_error","Fork token expired or invalid. Re-open the project in the dashboard to get a fresh token.",r.status):await _(r);let{writeFileSync:o}=await import("fs"),s=Buffer.from(await r.arrayBuffer());o(n,s)}async function yt(e){await i(`/api/projects/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({local_setup_done:!0})})}async function ht(e,t){return i(`/api/projects/${encodeURIComponent(e)}/share`,{method:"POST",body:JSON.stringify({is_template:t?.isTemplate??!1,template_description:t?.description})})}export{f as a,L as b,De as c,Ue as d,m as e,Re as f,xe as g,re as h,Se as i,y as j,Me as k,Ee as l,a as m,pe as n,je as o,ge as p,Ae as q,me as r,Oe as s,Fe as t,Ve as u,Le as v,Ne as w,Be as x,qe as y,Ke as z,Je as A,He as B,We as C,Qe as D,ze as E,Ge as F,Xe as G,Ye as H,Ze as I,et as J,tt as K,nt as L,rt as M,ot as N,st as O,it as P,at as Q,ct as R,lt as S,ut as T,pt as U,dt as V,gt as W,ft as X,mt as Y,yt as Z,ht as _};