@mistflow-ai/mcp 0.1.0 → 0.1.2

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,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-5IQGENNI.js";export{e as MistflowApiError,s as addDomain,h as checkAuth,i as checkAuthDetailed,k as checkSubdomain,m as createDeployment,l as createProject,B as deleteEnvVar,r as discoverDecisions,I as downloadSource,O as downloadSourceWithToken,L as fetchModule,J as fetchScaffold,K as fetchStepContext,N as forkTemplate,p as generatePlan,f as getAuthHeaders,b as getBaseUrl,d as getDashboardUrl,w as getDbCredentials,C as getDeployLogs,o as getDeploymentStatus,j as getProject,D as getProjectErrors,c as getSiteUrl,M as getTemplate,x as getTestAccounts,a as hasCredentialsOnDisk,g as hasLocalCredentials,E as listDeployments,t as listDomains,z as listEnvVars,P as markLocalSetupDone,q as modifyPlan,G as promotePreview,F as redeployProject,v as removeDomain,H as rollbackDeployment,Q as shareProject,n as uploadAndDeploy,y as uploadQAResults,A as upsertEnvVar,u as verifyDomain};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e}from"./chunk-ANYHR4WA.js";export{b as closeBrowser,c as getIsolatedContext,a as getPage,d as getSnapshot,e as takeScreenshot};
@@ -1,6 +1,6 @@
1
- import{readFileSync as I,existsSync as S,writeFileSync as H,mkdirSync as z,renameSync as X,unlinkSync as Y}from"fs";import{join as x,dirname as Q}from"path";import{homedir as G}from"os";import{randomBytes as Z}from"crypto";function $(){return x(G(),".mistflow","credentials.json")}function d(){let e=process.env.MISTFLOW_API_KEY;if(e)return{ok:!0,creds:{apiKey:e,orgId:"",orgSlug:"env"}};let t=$();if(!S(t))return{ok:!1,reason:"missing"};try{let n=JSON.parse(I(t,"utf-8"));return typeof n.apiKey=="string"&&n.apiKey&&typeof n.orgId=="string"?{ok:!0,creds:n}:{ok:!1,reason:"invalid"}}catch{return{ok:!1,reason:"invalid"}}}function he(e){let t=$(),n=Q(t);S(n)||z(n,{recursive:!0});let r=x(n,`.credentials.tmp.${Z(8).toString("hex")}`);try{H(r,JSON.stringify(e,null,2)+`
2
- `,{mode:384}),X(r,t)}catch(o){try{Y(r)}catch{}throw o}}function we(){let e=d();return e.ok?e.creds:null}function ee(){return d().ok}function _e(e){let t=x(e,"mistflow.json");if(!S(t))return null;try{return JSON.parse(I(t,"utf-8"))}catch{return null}}import{existsSync as C,readFileSync as M,writeFileSync as te,mkdirSync as ne}from"fs";import{join as b,dirname as v}from"path";import{homedir as re}from"os";import{fileURLToPath as oe}from"url";var w=null;function p(){if(w)return w;try{let e=oe(import.meta.url),t=v(e);for(let n=0;n<6;n++){let r=b(t,"package.json");if(C(r)){let s=JSON.parse(M(r,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return w=s.version,s.version}let o=v(t);if(o===t)break;t=o}}catch{}return w="0.0.0","0.0.0"}function _(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 T(e,t){let n=_(e),r=_(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 E(e,t,n){if(n&&T(e,n)<0)return"unsupported";if(!t||T(e,t)>=0)return"none";let o=_(e),s=_(t);return!o||!s?"none":o[0]<s[0]?"major":o[1]<s[1]?"minor":"patch"}var l=null;function O(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||(l={latest:t,minSupported:n,changelogUrl:r})}function A(){let e=process.env.MISTFLOW_STATE_DIR||b(re(),".mistflow");return b(e,"upgrade-state.json")}function se(){try{let e=A();return C(e)?JSON.parse(M(e,"utf-8")):{}}catch{return{}}}function ie(e){try{let t=A(),n=v(t);C(n)||ne(n,{recursive:!0}),te(t,JSON.stringify(e,null,2)+`
3
- `,{mode:384})}catch{}}var D=!1;function ae(e){return e==="patch"?7*864e5:e==="minor"?1*864e5:0}function ve(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!l)return null;let e=p();if(e==="0.0.0")return null;let t=E(e,l.latest,l.minSupported);if(t==="none")return null;if(t==="unsupported")return j(t,e,l);if(D)return null;let n=se(),r=Date.now(),o=ae(t);return n.dismissedForVersion===l.latest&&t!=="major"||n.lastLatestSeen===l.latest&&n.lastShownMs&&r-n.lastShownMs<o?null:(D=!0,ie({...n,lastShownMs:r,lastLatestSeen:l.latest}),j(t,e,l))}function j(e,t,n){let r="npx -y mistflow-ai install",o=n.changelogUrl?`
1
+ import{readFileSync as I,existsSync as S,writeFileSync as Q,mkdirSync as H,renameSync as z,unlinkSync as X}from"fs";import{join as x,dirname as Y}from"path";import{homedir as G}from"os";import{randomBytes as Z}from"crypto";function T(){return x(G(),".mistflow","credentials.json")}function d(){let e=process.env.MISTFLOW_API_KEY;if(e)return{ok:!0,creds:{apiKey:e,orgId:"",orgSlug:"env"}};let t=T();if(!S(t))return{ok:!1,reason:"missing"};try{let n=JSON.parse(I(t,"utf-8"));return typeof n.apiKey=="string"&&n.apiKey&&typeof n.orgId=="string"?{ok:!0,creds:n}:{ok:!1,reason:"invalid"}}catch{return{ok:!1,reason:"invalid"}}}function he(e){let t=T(),n=Y(t);S(n)||H(n,{recursive:!0});let r=x(n,`.credentials.tmp.${Z(8).toString("hex")}`);try{Q(r,JSON.stringify(e,null,2)+`
2
+ `,{mode:384}),z(r,t)}catch(o){try{X(r)}catch{}throw o}}function we(){let e=d();return e.ok?e.creds:null}function ee(){return d().ok}function _e(e){let t=x(e,"mistflow.json");if(!S(t))return null;try{return JSON.parse(I(t,"utf-8"))}catch{return null}}import{existsSync as v,readFileSync as M,writeFileSync as te,mkdirSync as ne}from"fs";import{join as b,dirname as C}from"path";import{homedir as re}from"os";import{fileURLToPath as oe}from"url";var w=null;function p(){if(w)return w;try{let e=oe(import.meta.url),t=C(e);for(let n=0;n<6;n++){let r=b(t,"package.json");if(v(r)){let s=JSON.parse(M(r,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return w=s.version,s.version}let o=C(t);if(o===t)break;t=o}}catch{}return w="0.0.0","0.0.0"}function _(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 $(e,t){let n=_(e),r=_(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 A(e,t,n){if(n&&$(e,n)<0)return"unsupported";if(!t||$(e,t)>=0)return"none";let o=_(e),s=_(t);return!o||!s?"none":o[0]<s[0]?"major":o[1]<s[1]?"minor":"patch"}var l=null;function E(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||(l={latest:t,minSupported:n,changelogUrl:r})}function O(){let e=process.env.MISTFLOW_STATE_DIR||b(re(),".mistflow");return b(e,"upgrade-state.json")}function se(){try{let e=O();return v(e)?JSON.parse(M(e,"utf-8")):{}}catch{return{}}}function ie(e){try{let t=O(),n=C(t);v(n)||ne(n,{recursive:!0}),te(t,JSON.stringify(e,null,2)+`
3
+ `,{mode:384})}catch{}}var D=!1;function ae(e){return e==="patch"?7*864e5:e==="minor"?1*864e5:0}function Ce(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!l)return null;let e=p();if(e==="0.0.0")return null;let t=A(e,l.latest,l.minSupported);if(t==="none")return null;if(t==="unsupported")return j(t,e,l);if(D)return null;let n=se(),r=Date.now(),o=ae(t);return n.dismissedForVersion===l.latest&&t!=="major"||n.lastLatestSeen===l.latest&&n.lastShownMs&&r-n.lastShownMs<o?null:(D=!0,ie({...n,lastShownMs:r,lastLatestSeen:l.latest}),j(t,e,l))}function j(e,t,n){let r="npx -y mistflow-ai install",o=n.changelogUrl?`
4
4
  What's new: ${n.changelogUrl}`:"";return e==="unsupported"?`
5
5
 
6
6
  ---
@@ -20,4 +20,4 @@ This is a major update. Run \`${r}\` and restart your editor.${o}
20
20
  --- Mistflow update available: ${t} -> ${n.latest} ---
21
21
  Run \`${r}\` to upgrade, then restart your editor.${o}`:`
22
22
 
23
- (Mistflow ${n.latest} is out, you have ${t}. Run \`${r}\` when convenient.)`}function Ce(){let e=p(),t=l??{latest:"",minSupported:"",changelogUrl:""},n=E(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:l!==null}}function f(){return process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"}function $e(){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 Te(){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 ce(){let e=d();if(!e.ok)throw new a("auth_missing","No Mistflow credentials found.",401);return le(e.creds)}function le(e){return{Authorization:`ApiKey ${e.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":p()}}function y(e){try{O(e.headers)}catch{}}async function V(e,t,n){for(let r=0;r<2;r++)try{return await fetch(e,{...t,signal:AbortSignal.timeout(n)})}catch(o){let s=o instanceof Error&&o.name==="TimeoutError",c=o instanceof TypeError;if(r===0&&(s||c)){console.error(`[api] Retrying ${e} after ${s?"timeout":"network error"}`);continue}throw o}throw new Error("fetchWithRetry: exhausted retries")}async function h(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=ce(),{timeoutMs:r,...o}=t,s=r??3e4,c;try{c=await V(`${f()}${e}`,{...o,headers:{...n,...o.headers}},s)}catch(g){throw g instanceof Error&&g.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(y(c),!c.ok)throw await h(c);return c.json()}function ue(){return d().ok}var R=null,F=0,pe=300*1e3;async function De(){return(await de()).ok}async function de(){if(R!==null&&Date.now()<F)return R?{ok:!0}:{ok:!1,reason:"no_credentials"};if(!ue())return{ok:!1,reason:"no_credentials"};try{return await i("/api/org"),R=!0,F=Date.now()+pe,{ok:!0}}catch(e){if(R=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 je(e){return i(`/api/projects/${encodeURIComponent(e)}`)}async function Me(e){return i(`/api/projects/check-subdomain?name=${encodeURIComponent(e)}`)}async function Ee(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 Oe(e,t){return i("/api/deploy",{method:"POST",body:JSON.stringify({project_id:e,build_output_url:t})})}async function Ae(e,t,n="production",r,o,s,c){let{readFileSync:g}=await import("fs"),{basename:N}=await import("path"),P=d();if(!P.ok)throw new a("auth_missing","No Mistflow credentials found.",401);let L=P.creds,q=g(t),K=new Blob([q],{type:"application/gzip"}),u=new FormData;if(u.append("project_id",e),u.append("build",K,N(t)),n!=="production"&&u.append("environment",n),r&&u.append("admin_email",r),o&&u.append("schema_pushed","true"),s){let{existsSync:B}=await import("fs");if(B(s)){let J=g(s),W=new Blob([J],{type:"application/gzip"});u.append("source",W,"source.tar.gz")}}c&&u.append("git_commit_sha",c);let m;try{m=await fetch(`${f()}/api/deploy/upload`,{method:"POST",headers:{Authorization:`ApiKey ${L.apiKey}`,"X-Mistflow-MCP-Version":p()},body:u,signal:AbortSignal.timeout(3e5)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(m),!m.ok)throw await h(m);let U=await m.json();return{...U,id:U.deployment_id}}async function Fe(e){return i(`/api/deploy/${encodeURIComponent(e)}/status`)}async function Ve(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);let r=t?.conversationId||t?.answers?12e4:6e4;return i("/api/plan",{method:"POST",body:JSON.stringify(n),timeoutMs:r})}async function Ne(e,t){return i("/api/plan/modify",{method:"POST",body:JSON.stringify({existing_plan:e,modification:t})})}async function Le(e){return i("/api/plan/discover",{method:"POST",body:JSON.stringify({description:e})})}async function qe(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains`,{method:"POST",body:JSON.stringify({domain:t})})}async function Ke(e){return i(`/api/projects/${encodeURIComponent(e)}/domains`)}async function Be(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}/verify`)}async function Je(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}`,{method:"DELETE"})}async function We(e){return i(`/api/projects/${encodeURIComponent(e)}/db-credentials`)}async function He(e){return i(`/api/projects/${encodeURIComponent(e)}/env`)}async function ze(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 Xe(e,t){return i(`/api/projects/${encodeURIComponent(e)}/env/${encodeURIComponent(t)}`,{method:"DELETE"})}async function Ye(e){return i(`/api/deploy/${encodeURIComponent(e)}/logs`)}async function Qe(e,t="7d"){return i(`/api/projects/${encodeURIComponent(e)}/errors?period=${encodeURIComponent(t)}`)}async function Ge(e){return i(`/api/projects/${encodeURIComponent(e)}/deployments`)}async function Ze(e){return i(`/api/deploy/${encodeURIComponent(e)}/redeploy`,{method:"POST"})}async function et(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 tt(e){return i(`/api/deploy/${encodeURIComponent(e)}/rollback`,{method:"POST"})}async function nt(e,t){let n=d();if(!n.ok)throw new a("auth_missing","Not authenticated.",401);let r=n.creds,o=await fetch(`${f()}/api/deploy/${encodeURIComponent(e)}/source`,{headers:{Authorization:`ApiKey ${r.apiKey}`,"X-Mistflow-MCP-Version":p()},signal:AbortSignal.timeout(12e4)});if(y(o),!o.ok)throw await h(o);let{writeFileSync:s}=await import("fs"),c=Buffer.from(await o.arrayBuffer());s(t,c)}async function k(e,t){let{timeoutMs:n,...r}=t??{},o=n??3e4,s;try{s=await V(`${f()}${e}`,{headers:{"Content-Type":"application/json","X-Mistflow-MCP-Version":p()},...r},o)}catch(c){throw c instanceof Error&&c.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(y(s),!s.ok)throw await h(s);return s.json()}async function rt(e="nextjs"){return k(`/api/scaffold/${encodeURIComponent(e)}`)}async function ot(e,t){return k(`/api/scaffold/${encodeURIComponent(e)}/context?step_type=${encodeURIComponent(t)}`)}async function st(e,t,n,r){return k(`/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 it(e){return k(`/api/templates/${encodeURIComponent(e)}`)}async function at(e){return i(`/api/templates/${encodeURIComponent(e)}/fork`,{method:"POST"})}async function ct(e,t,n){let r;try{r=await fetch(`${f()}/api/deploy/${encodeURIComponent(e)}/fork-source?fork_token=${encodeURIComponent(t)}`,{headers:{"X-Mistflow-MCP-Version":p()},signal:AbortSignal.timeout(12e4)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(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 h(r);let{writeFileSync:o}=await import("fs"),s=Buffer.from(await r.arrayBuffer());o(n,s)}async function lt(e){await i(`/api/projects/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({local_setup_done:!0})})}async function ut(e,t){return i(`/api/projects/${encodeURIComponent(e)}/share`,{method:"POST",body:JSON.stringify({is_template:t?.isTemplate??!1,template_description:t?.description})})}export{p as a,O as b,ve as c,Ce as d,d as e,he as f,we as g,ee as h,_e as i,f as j,$e as k,Te as l,a as m,ce as n,ue as o,De as p,de as q,je as r,Me as s,Ee as t,Oe as u,Ae as v,Fe as w,Ve as x,Ne as y,Le as z,qe as A,Ke as B,Be as C,Je as D,We as E,He as F,ze as G,Xe as H,Ye as I,Qe as J,Ge as K,Ze as L,et as M,tt as N,nt as O,rt as P,ot as Q,st as R,it as S,at as T,ct as U,lt as V,ut as W};
23
+ (Mistflow ${n.latest} is out, you have ${t}. Run \`${r}\` when convenient.)`}function ve(){let e=p(),t=l??{latest:"",minSupported:"",changelogUrl:""},n=A(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:l!==null}}function m(){return process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"}function Te(){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 $e(){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 ce(){let e=d();if(!e.ok)throw new a("auth_missing","No Mistflow credentials found.",401);return le(e.creds)}function le(e){return{Authorization:`ApiKey ${e.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":p()}}function y(e){try{E(e.headers)}catch{}}async function V(e,t,n){for(let r=0;r<2;r++)try{return await fetch(e,{...t,signal:AbortSignal.timeout(n)})}catch(o){let s=o instanceof Error&&o.name==="TimeoutError",c=o instanceof TypeError;if(r===0&&(s||c)){console.error(`[api] Retrying ${e} after ${s?"timeout":"network error"}`);continue}throw o}throw new Error("fetchWithRetry: exhausted retries")}async function h(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=ce(),{timeoutMs:r,...o}=t,s=r??3e4,c;try{c=await V(`${m()}${e}`,{...o,headers:{...n,...o.headers}},s)}catch(g){throw g instanceof Error&&g.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(y(c),!c.ok)throw await h(c);return c.json()}function ue(){return d().ok}var R=null,F=0,pe=300*1e3;async function De(){return(await de()).ok}async function de(){if(R!==null&&Date.now()<F)return R?{ok:!0}:{ok:!1,reason:"no_credentials"};if(!ue())return{ok:!1,reason:"no_credentials"};try{return await i("/api/org"),R=!0,F=Date.now()+pe,{ok:!0}}catch(e){if(R=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 je(e){return i(`/api/projects/${encodeURIComponent(e)}`)}async function Me(e){return i(`/api/projects/check-subdomain?name=${encodeURIComponent(e)}`)}async function Ae(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 Ee(e,t){return i("/api/deploy",{method:"POST",body:JSON.stringify({project_id:e,build_output_url:t})})}async function Oe(e,t,n="production",r,o,s,c){let{readFileSync:g}=await import("fs"),{basename:N}=await import("path"),P=d();if(!P.ok)throw new a("auth_missing","No Mistflow credentials found.",401);let L=P.creds,q=g(t),J=new Blob([q],{type:"application/gzip"}),u=new FormData;if(u.append("project_id",e),u.append("build",J,N(t)),n!=="production"&&u.append("environment",n),r&&u.append("admin_email",r),o&&u.append("schema_pushed","true"),s){let{existsSync:K}=await import("fs");if(K(s)){let B=g(s),W=new Blob([B],{type:"application/gzip"});u.append("source",W,"source.tar.gz")}}c&&u.append("git_commit_sha",c);let f;try{f=await fetch(`${m()}/api/deploy/upload`,{method:"POST",headers:{Authorization:`ApiKey ${L.apiKey}`,"X-Mistflow-MCP-Version":p()},body:u,signal:AbortSignal.timeout(3e5)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(f),!f.ok)throw await h(f);let U=await f.json();return{...U,id:U.deployment_id}}async function Fe(e){return i(`/api/deploy/${encodeURIComponent(e)}/status`)}async function Ve(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);let r=t?.conversationId||t?.answers?12e4:6e4;return i("/api/plan",{method:"POST",body:JSON.stringify(n),timeoutMs:r})}async function Ne(e,t){return i("/api/plan/modify",{method:"POST",body:JSON.stringify({existing_plan:e,modification:t})})}async function Le(e){return i("/api/plan/discover",{method:"POST",body:JSON.stringify({description:e})})}async function qe(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains`,{method:"POST",body:JSON.stringify({domain:t})})}async function Je(e){return i(`/api/projects/${encodeURIComponent(e)}/domains`)}async function Ke(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}/verify`)}async function Be(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}`,{method:"DELETE"})}async function We(e){return i(`/api/projects/${encodeURIComponent(e)}/db-credentials`)}async function Qe(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 test accounts:",t instanceof Error?t.message:t),null}}async function He(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 ze(e){return i(`/api/projects/${encodeURIComponent(e)}/env`)}async function Xe(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 Ye(e,t){return i(`/api/projects/${encodeURIComponent(e)}/env/${encodeURIComponent(t)}`,{method:"DELETE"})}async function Ge(e){return i(`/api/deploy/${encodeURIComponent(e)}/logs`)}async function Ze(e,t="7d"){return i(`/api/projects/${encodeURIComponent(e)}/errors?period=${encodeURIComponent(t)}`)}async function et(e){return i(`/api/projects/${encodeURIComponent(e)}/deployments`)}async function tt(e){return i(`/api/deploy/${encodeURIComponent(e)}/redeploy`,{method:"POST"})}async function nt(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 rt(e){return i(`/api/deploy/${encodeURIComponent(e)}/rollback`,{method:"POST"})}async function ot(e,t){let n=d();if(!n.ok)throw new a("auth_missing","Not authenticated.",401);let r=n.creds,o=await fetch(`${m()}/api/deploy/${encodeURIComponent(e)}/source`,{headers:{Authorization:`ApiKey ${r.apiKey}`,"X-Mistflow-MCP-Version":p()},signal:AbortSignal.timeout(12e4)});if(y(o),!o.ok)throw await h(o);let{writeFileSync:s}=await import("fs"),c=Buffer.from(await o.arrayBuffer());s(t,c)}async function k(e,t){let{timeoutMs:n,...r}=t??{},o=n??3e4,s;try{s=await V(`${m()}${e}`,{headers:{"Content-Type":"application/json","X-Mistflow-MCP-Version":p()},...r},o)}catch(c){throw c instanceof Error&&c.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(y(s),!s.ok)throw await h(s);return s.json()}async function st(e="nextjs"){return k(`/api/scaffold/${encodeURIComponent(e)}`)}async function it(e,t){return k(`/api/scaffold/${encodeURIComponent(e)}/context?step_type=${encodeURIComponent(t)}`)}async function at(e,t,n,r){return k(`/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 ct(e){return k(`/api/templates/${encodeURIComponent(e)}`)}async function lt(e){return i(`/api/templates/${encodeURIComponent(e)}/fork`,{method:"POST"})}async function ut(e,t,n){let r;try{r=await fetch(`${m()}/api/deploy/${encodeURIComponent(e)}/fork-source?fork_token=${encodeURIComponent(t)}`,{headers:{"X-Mistflow-MCP-Version":p()},signal:AbortSignal.timeout(12e4)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(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 h(r);let{writeFileSync:o}=await import("fs"),s=Buffer.from(await r.arrayBuffer());o(n,s)}async function pt(e){await i(`/api/projects/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({local_setup_done:!0})})}async function dt(e,t){return i(`/api/projects/${encodeURIComponent(e)}/share`,{method:"POST",body:JSON.stringify({is_template:t?.isTemplate??!1,template_description:t?.description})})}export{p as a,E as b,Ce as c,ve as d,d as e,he as f,we as g,ee as h,_e as i,m as j,Te as k,$e as l,a as m,ce as n,ue as o,De as p,de as q,je as r,Me as s,Ae as t,Ee as u,Oe as v,Fe as w,Ve as x,Ne as y,Le as z,qe as A,Je as B,Ke as C,Be as D,We as E,Qe as F,He as G,ze as H,Xe as I,Ye as J,Ge as K,Ze as L,et as M,tt as N,nt as O,rt as P,ot as Q,st as R,it as S,at as T,ct as U,lt as V,ut as W,pt as X,dt as Y};
@@ -0,0 +1 @@
1
+ var e=null,a=null,t=null,i=null;async function r(){try{return await import("playwright")}catch{throw new Error("Playwright is not installed. Run: cd packages/mcp-server && pnpm add playwright && npx playwright install chromium")}}async function l(){let n=await r();return(!e||!e.isConnected())&&(e=await n.chromium.launch({headless:!0})),a&&(await a.close().catch(()=>{}),a=null),a=await e.newContext({viewport:{width:1280,height:720},deviceScaleFactor:2}),t=await a.newPage(),t}async function w(){return t&&!t.isClosed()?t:(i||(i=l().finally(()=>{i=null})),i)}async function s(){t&&!t.isClosed()&&await t.close().catch(()=>{}),a&&await a.close().catch(()=>{}),e?.isConnected()&&await e.close().catch(()=>{}),t=null,a=null,e=null}process.once("SIGTERM",()=>{s().finally(()=>process.exit(0))});process.once("SIGINT",()=>{s().finally(()=>process.exit(0))});async function u(){let n=await r();(!e||!e.isConnected())&&(e=await n.chromium.launch({headless:!0}));let o=await e.newContext({viewport:{width:1280,height:720},deviceScaleFactor:2}),c=await o.newPage();return{context:o,page:c}}async function p(n){return await n.locator("body").ariaSnapshot()}async function g(n,o=!1){return await n.screenshot({fullPage:o,type:"png"})}export{w as a,s as b,u as c,p as d,g as e};
@@ -1,2 +1,2 @@
1
- import{a as o,b as s,j as i,n as a}from"./chunk-VQN2JJRZ.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-5IQGENNI.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};