@netlify/agent-runner-cli 1.172.0 → 1.172.1
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/bin-local.js +239 -228
- package/dist/bin.js +309 -298
- package/dist/connections-mcp-server.js +1 -1
- package/dist/index.js +238 -227
- package/package.json +1 -1
|
@@ -85,5 +85,5 @@ ${Ce}`,d++}else Fx($,I,de)?p=$.slice($.charCodeAt(I+6)===Er?I+7:I+6,A)||void 0:S
|
|
|
85
85
|
`,I),fe=-1;if(A!==-1&&de!==-1?fe=A<de?A:de:A!==-1?A===$.length-1?fe=-1:fe=A:de!==-1&&(fe=de),fe===-1)break;S($,I,fe),I=fe+1,$.charCodeAt(I-1)===_N&&$.charCodeAt(I)===Mx&&I++}return $.slice(I)}function S($,I,A){if(I===A){T();return}let de=$.charCodeAt(I);if(Lx($,I,de)){let jt=$.charCodeAt(I+5)===Er?I+6:I+5,cg=$.slice(jt,A);l=d===0?cg:`${l}
|
|
86
86
|
${cg}`,d++;return}if(Fx($,I,de)){p=$.slice($.charCodeAt(I+6)===Er?I+7:I+6,A)||void 0;return}if(de===105&&$.charCodeAt(I+1)===100&&$.charCodeAt(I+2)===58){let jt=$.slice($.charCodeAt(I+3)===Er?I+4:I+3,A);u=jt.includes("\0")?void 0:jt;return}if(de===58){if(r){let jt=$.slice(I,A);r(jt.slice($.charCodeAt(I+1)===Er?2:1))}return}let fe=$.slice(I,A),Ce=fe.indexOf(":");if(Ce===-1){j(fe,"",fe);return}let Cn=fe.slice(0,Ce),Oi=fe.charCodeAt(Ce+1)===Er?2:1,ji=fe.slice(Ce+Oi);j(Cn,ji,fe)}function j($,I,A){switch($){case"event":p=I||void 0;break;case"data":l=d===0?I:`${l}
|
|
87
87
|
${I}`,d++;break;case"id":u=I.includes("\0")?void 0:I;break;case"retry":/^\d+$/.test(I)?o(parseInt(I,10)):n(new Ti(`Invalid \`retry\` value: "${I}"`,{type:"invalid-retry",value:I,line:A}));break;default:n(new Ti(`Unknown field "${$.length>20?`${$.slice(0,20)}\u2026`:$}"`,{type:"unknown-field",field:$,value:I,line:A}));break}}function T(){d>0&&t({id:u,event:p,data:l}),u=void 0,l="",d=0,p=void 0}function N($={}){if($.consume&&a.length>0){let I=a.join("");S(I,0,I.length)}c=!0,u=void 0,l="",d=0,p=void 0,a.length=0,s=0,f=!1}return{feed:g,reset:N}}function Lx(e,t,n){return n===100&&e.charCodeAt(t+1)===97&&e.charCodeAt(t+2)===116&&e.charCodeAt(t+3)===97&&e.charCodeAt(t+4)===58}function Fx(e,t,n){return n===101&&e.charCodeAt(t+1)===118&&e.charCodeAt(t+2)===101&&e.charCodeAt(t+3)===110&&e.charCodeAt(t+4)===116&&e.charCodeAt(t+5)===58}var bc=class extends TransformStream{constructor({onError:t,onRetry:n,onComment:o,maxBufferSize:r}={}){let i;super({start(a){i=Vx({onEvent:s=>{a.enqueue(s)},onError(s){typeof t=="function"&&t(s),(t==="terminate"||s.type==="max-buffer-size-exceeded")&&a.error(s)},onRetry:n,onComment:o,maxBufferSize:r})},transform(a){i.feed(a)}})}};var yN={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},or=class extends Error{constructor(t,n){super(`Streamable HTTP error: ${n}`),this.code=t}},xc=class{constructor(t,n){this._hasCompletedAuthFlow=!1,this._url=t,this._resourceMetadataUrl=void 0,this._scope=void 0,this._requestInit=n?.requestInit,this._authProvider=n?.authProvider,this._fetch=n?.fetch,this._fetchWithInit=zx(n?.fetch,n?.requestInit),this._sessionId=n?.sessionId,this._reconnectionOptions=n?.reconnectionOptions??yN}async _authThenStart(){if(!this._authProvider)throw new Ot("No auth provider");let t;try{t=await Pi(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})}catch(n){throw this.onerror?.(n),n}if(t!=="AUTHORIZED")throw new Ot;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){let t={};if(this._authProvider){let o=await this._authProvider.tokens();o&&(t.Authorization=`Bearer ${o.access_token}`)}this._sessionId&&(t["mcp-session-id"]=this._sessionId),this._protocolVersion&&(t["mcp-protocol-version"]=this._protocolVersion);let n=$c(this._requestInit?.headers);return new Headers({...t,...n})}async _startOrAuthSse(t){let{resumptionToken:n}=t;try{let o=await this._commonHeaders();o.set("Accept","text/event-stream"),n&&o.set("last-event-id",n);let r=await(this._fetch??fetch)(this._url,{method:"GET",headers:o,signal:this._abortController?.signal});if(!r.ok){if(await r.body?.cancel(),r.status===401&&this._authProvider)return await this._authThenStart();if(r.status===405)return;throw new or(r.status,`Failed to open SSE stream: ${r.statusText}`)}this._handleSseStream(r.body,t,!0)}catch(o){throw this.onerror?.(o),o}}_getNextReconnectionDelay(t){if(this._serverRetryMs!==void 0)return this._serverRetryMs;let n=this._reconnectionOptions.initialReconnectionDelay,o=this._reconnectionOptions.reconnectionDelayGrowFactor,r=this._reconnectionOptions.maxReconnectionDelay;return Math.min(n*Math.pow(o,t),r)}_scheduleReconnection(t,n=0){let o=this._reconnectionOptions.maxRetries;if(n>=o){this.onerror?.(new Error(`Maximum reconnection attempts (${o}) exceeded.`));return}let r=this._getNextReconnectionDelay(n);this._reconnectionTimeout=setTimeout(()=>{this._startOrAuthSse(t).catch(i=>{this.onerror?.(new Error(`Failed to reconnect SSE stream: ${i instanceof Error?i.message:String(i)}`)),this._scheduleReconnection(t,n+1)})},r)}_handleSseStream(t,n,o){if(!t)return;let{onresumptiontoken:r,replayMessageId:i}=n,a,s=!1,c=!1;(async()=>{try{let l=t.pipeThrough(new TextDecoderStream).pipeThrough(new bc({onRetry:f=>{this._serverRetryMs=f}})).getReader();for(;;){let{value:f,done:g}=await l.read();if(g)break;if(f.id&&(a=f.id,s=!0,r?.(f.id)),!!f.data&&(!f.event||f.event==="message"))try{let _=pn.parse(JSON.parse(f.data));fr(_)&&(c=!0,i!==void 0&&(_.id=i)),this.onmessage?.(_)}catch(_){this.onerror?.(_)}}(o||s)&&!c&&this._abortController&&!this._abortController.signal.aborted&&this._scheduleReconnection({resumptionToken:a,onresumptiontoken:r,replayMessageId:i},0)}catch(l){if(this.onerror?.(new Error(`SSE stream disconnected: ${l}`)),(o||s)&&!c&&this._abortController&&!this._abortController.signal.aborted)try{this._scheduleReconnection({resumptionToken:a,onresumptiontoken:r,replayMessageId:i},0)}catch(f){this.onerror?.(new Error(`Failed to reconnect: ${f instanceof Error?f.message:String(f)}`))}}})()}async start(){if(this._abortController)throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(t){if(!this._authProvider)throw new Ot("No auth provider");if(await Pi(this._authProvider,{serverUrl:this._url,authorizationCode:t,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!=="AUTHORIZED")throw new Ot("Failed to authorize")}async close(){this._reconnectionTimeout&&(clearTimeout(this._reconnectionTimeout),this._reconnectionTimeout=void 0),this._abortController?.abort(),this.onclose?.()}async send(t,n){try{let{resumptionToken:o,onresumptiontoken:r}=n||{};if(o){this._startOrAuthSse({resumptionToken:o,replayMessageId:ko(t)?t.id:void 0}).catch(p=>this.onerror?.(p));return}let i=await this._commonHeaders();i.set("content-type","application/json"),i.set("accept","application/json, text/event-stream");let a={...this._requestInit,method:"POST",headers:i,body:JSON.stringify(t),signal:this._abortController?.signal},s=await(this._fetch??fetch)(this._url,a),c=s.headers.get("mcp-session-id");if(c&&(this._sessionId=c),!s.ok){let p=await s.text().catch(()=>null);if(s.status===401&&this._authProvider){if(this._hasCompletedAuthFlow)throw new or(401,"Server returned 401 after successful authentication");let{resourceMetadataUrl:f,scope:g}=tg(s);if(this._resourceMetadataUrl=f,this._scope=g,await Pi(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!=="AUTHORIZED")throw new Ot;return this._hasCompletedAuthFlow=!0,this.send(t)}if(s.status===403&&this._authProvider){let{resourceMetadataUrl:f,scope:g,error:_}=tg(s);if(_==="insufficient_scope"){let y=s.headers.get("WWW-Authenticate");if(this._lastUpscopingHeader===y)throw new or(403,"Server returned 403 after trying upscoping");if(g&&(this._scope=g),f&&(this._resourceMetadataUrl=f),this._lastUpscopingHeader=y??void 0,await Pi(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetch})!=="AUTHORIZED")throw new Ot;return this.send(t)}}throw new or(s.status,`Error POSTing to endpoint: ${p}`)}if(this._hasCompletedAuthFlow=!1,this._lastUpscopingHeader=void 0,s.status===202){await s.body?.cancel(),vy(t)&&this._startOrAuthSse({resumptionToken:void 0}).catch(p=>this.onerror?.(p));return}let l=(Array.isArray(t)?t:[t]).filter(p=>"method"in p&&"id"in p&&p.id!==void 0).length>0,d=s.headers.get("content-type");if(l)if(d?.includes("text/event-stream"))this._handleSseStream(s.body,{onresumptiontoken:r},!1);else if(d?.includes("application/json")){let p=await s.json(),f=Array.isArray(p)?p.map(g=>pn.parse(g)):[pn.parse(p)];for(let g of f)this.onmessage?.(g)}else throw await s.body?.cancel(),new or(-1,`Unexpected content type: ${d}`);else await s.body?.cancel()}catch(o){throw this.onerror?.(o),o}}get sessionId(){return this._sessionId}async terminateSession(){if(this._sessionId)try{let t=await this._commonHeaders(),n={...this._requestInit,method:"DELETE",headers:t,signal:this._abortController?.signal},o=await(this._fetch??fetch)(this._url,n);if(await o.body?.cancel(),!o.ok&&o.status!==405)throw new or(o.status,`Failed to terminate session: ${o.statusText}`);this._sessionId=void 0}catch(t){throw this.onerror?.(t),t}}setProtocolVersion(t){this._protocolVersion=t}get protocolVersion(){return this._protocolVersion}async resumeStream(t,n){await this._startOrAuthSse({resumptionToken:t,onresumptiontoken:n?.onresumptiontoken})}};import $N from"process";var ct=(e,t)=>{$N.stderr.write(`[connections-mcp] ${e}${t?` ${JSON.stringify(t)}`:""}
|
|
88
|
-
`)};var bN=3e4,Jx=async(e,t,n)=>{let o=await fetch(e,{...n,signal:AbortSignal.timeout(bN),headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json",...n?.headers}});if(!o.ok)throw new Error(`ActionKit ${o.status}: ${await o.text()}`);return o.json()},xN=(e,t)=>Object.values(e??{}).flat().filter(n=>typeof n?.function?.name=="string"&&t.has(n.function.name)).map(({function:n})=>({name:n.name,description:n.description,inputSchema:n.parameters})),Kx=async e=>{let{actions_url:t,project_id:n,token:o,tools:r}=e,i=`${t.replace(/\/$/,"")}/projects/${n}/actions`,a=await Jx(`${i}?limit_to_available=true`,o),s=xN(a?.tools??a?.actions,new Set(r??[]));Array.isArray(a?.errors)&&a.errors.length>0&&ct("ActionKit reported errors while listing",{service:e.service,errors:a.errors});let c=(r??[]).filter(u=>!s.some(l=>l.name===u));return c.length>0&&ct("curated actions not offered by ActionKit",{service:e.service,missing:c}),{service:e.service,scope:e.scope??"project",tools:s,client:{callTool:async({name:u,arguments:l})=>{let d=await Jx(i,o,{method:"POST",body:JSON.stringify({action:u,parameters:l})});return{content:[{type:"text",text:JSON.stringify(d)}]}}}}};var kN="NETLIFY_AGENT_CONNECTIONS_LOCAL",Hx=()=>{let e=wN.env[kN];if(e){ct("using local connections from env (development only)");try{return JSON.parse(e)}catch{return ct("local connections env var is not valid JSON; continuing with none"),[]}}},SN=async e=>{let t=new yc({name:"netlify-connections",version:"1.0.0"});await t.connect(new xc(new URL(e.mcp_server_url),{requestInit:{headers:{Authorization:`Bearer ${e.token}`}}}));try{let{tools:n}=await t.listTools();return{service:e.service,scope:e.scope??"project",client:t,tools:n}}catch(n){throw await t.close().catch(()=>{}),n}}
|
|
88
|
+
`)};var bN=3e4,Jx=async(e,t,n)=>{let o=await fetch(e,{...n,signal:AbortSignal.timeout(bN),headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json",...n?.headers}});if(!o.ok)throw new Error(`ActionKit ${o.status}: ${await o.text()}`);return o.json()},xN=(e,t)=>Object.values(e??{}).flat().filter(n=>typeof n?.function?.name=="string"&&t.has(n.function.name)).map(({function:n})=>({name:n.name,description:n.description,inputSchema:n.parameters})),Kx=async e=>{let{actions_url:t,project_id:n,token:o,tools:r}=e,i=`${t.replace(/\/$/,"")}/projects/${n}/actions`,a=await Jx(`${i}?limit_to_available=true`,o),s=xN(a?.tools??a?.actions,new Set(r??[]));Array.isArray(a?.errors)&&a.errors.length>0&&ct("ActionKit reported errors while listing",{service:e.service,errors:a.errors});let c=(r??[]).filter(u=>!s.some(l=>l.name===u));return c.length>0&&ct("curated actions not offered by ActionKit",{service:e.service,missing:c}),{service:e.service,scope:e.scope??"project",tools:s,client:{callTool:async({name:u,arguments:l})=>{let d=await Jx(i,o,{method:"POST",body:JSON.stringify({action:u,parameters:l})});return{content:[{type:"text",text:JSON.stringify(d)}]}}}}};var kN="NETLIFY_AGENT_CONNECTIONS_LOCAL",Hx=()=>{let e=wN.env[kN];if(e){ct("using local connections from env (development only)");try{return JSON.parse(e)}catch{return ct("local connections env var is not valid JSON; continuing with none"),[]}}},SN=async e=>{let t=new yc({name:"netlify-connections",version:"1.0.0"});await t.connect(new xc(new URL(e.mcp_server_url),{requestInit:{headers:{Authorization:`Bearer ${e.token}`}}}));try{let{tools:n}=await t.listTools();return{service:e.service,scope:e.scope??"project",client:t,tools:n,close:()=>t.close()}}catch(n){throw await t.close().catch(()=>{}),n}};var Gx=async e=>(await Promise.all(e.map(async n=>{try{return n.type==="actionkit"?await Kx(n):await SN(n)}catch(o){return ct("upstream unavailable; dropping this service",{service:n.service,scope:n.scope??"project",error:o?.message}),null}}))).filter(n=>n!==null),Wx=e=>{let t=new Map,n=[],o=[...e].sort((r,i)=>Kh(r.scope)-Kh(i.scope));for(let r of o)for(let i of r.tools)t.has(i.name)||(t.set(i.name,r),n.push(i));return{owner:t,tools:n}},Bx=e=>{let n=typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{};return{...n,type:"object",properties:n.properties??{}}};import{renameSync as zN,writeFileSync as IN}from"fs";import wc from"process";var Xx=(e,t)=>{let n=`${e}.partial`;IN(n,JSON.stringify(t)),zN(n,e)},Yx=()=>new Promise(()=>{}),Qx=()=>{let e=()=>wc.exit(0);wc.stdin.on("close",e),wc.stdin.on("end",e)},kc=(e,t=wc.argv)=>{let n=t.indexOf(e);return n===-1?void 0:t[n+1]};var og="netlify_interactions";var Ei="netlify_connections",Dn="request_service_authorization",ew="--runner-id",tw="--session-id",rw="--request-file",nw=(e,t)=>`mcp__${e}__${t}`,ow=(e,t)=>`mcp_${e}_${t}`,iw=(e,t)=>`${e}_${t}`,Eq=nw(og,"ask"),Oq=ow(og,"ask"),jq=iw(og,"ask"),Nq=nw(Ei,Dn),Rq=ow(Ei,Dn),Uq=iw(Ei,Dn);var aw=kc(ew),sw=kc(tw),cw=kc(rw);xx({constants:{NETLIFY_API_HOST:ig.env.NETLIFY_API_HOST||"api.netlify.com",NETLIFY_API_TOKEN:ig.env.NETLIFY_AUTH_TOKEN||ig.env.NETLIFY_API_TOKEN}});var PN=async()=>{let e=Hx();if(e)return e;if(!aw||!sw)return[];try{let{connections:t}=await wx(aw,sw);return t??[]}catch(t){return ct("could not fetch connections; continuing with none",{error:t?.message}),[]}},uw=await Gx(await PN()),{owner:TN,tools:lw}=Wx(uw);ct("ready",{services:uw.map(e=>e.service),toolCount:lw.length});var sg=new fc({name:Ei,version:"1.0.0"},{capabilities:{tools:{}}}),EN={name:Dn,description:Sx,inputSchema:xt.toJSONSchema(Hh)};sg.setRequestHandler(qf,()=>({tools:[...lw.map(e=>({name:e.name,description:e.description,inputSchema:Bx(e.inputSchema)})),EN]}));var ag=e=>({content:[{type:"text",text:e}],isError:!0});sg.setRequestHandler(Oo,async e=>{let{name:t,arguments:n}=e.params;if(t===Dn){let r=Hh.safeParse(n);return r.success?(cw&&Xx(cw,r.data),Yx()):ag(xt.prettifyError(r.error))}let o=TN.get(t);if(!o)return ag(`Tool ${t} not found`);try{return await o.client.callTool({name:t,arguments:n??{}})}catch(r){return ct("upstream tool call failed",{service:o.service,tool:t,error:r?.message}),ag(r?.message??"Upstream tool call failed")}});Qx();await sg.connect(new hc);
|
|
89
89
|
//# sourceMappingURL=connections-mcp-server.js.map
|