@netlify/agent-runner-cli 1.22.0 → 1.22.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.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -94,7 +94,7 @@ ${e}`;var ye=(e={})=>`
|
|
|
94
94
|
|
|
95
95
|
`)),{prompt:l.join(`
|
|
96
96
|
|
|
97
|
-
`)}};import ne from"process";import{getTracer as Lt}from"@netlify/otel";import W from"process";var le=W.env.NETLIFY_API_URL,ue=W.env.NETLIFY_API_TOKEN,z=async(e,t={})=>{if(!le||!ue)throw new Error("No API URL or token");let r=new URL(e,le),o={...t,headers:{...t.headers,Authorization:`Bearer ${ue}`}};W.env.AGENT_RUNNERS_DEBUG==="true"&&(o.headers["x-nf-debug-logging"]="true"),t.json&&(o.headers||={},o.headers["Content-Type"]="application/json",o.body=JSON.stringify(t.json));let n=await fetch(r,o),s=n.ok&&n.status<=299;if(W.env.AGENT_RUNNERS_DEBUG==="true"&&(console.log(`[DEBUG] Response headers for ${r}:`),n.headers.forEach((i,a)=>{console.log(` ${a}: ${i}`)})),s||console.error(`Got status ${n.status} for request ${r}`),t.raw){if(!s)throw n;return n}let l=await(n.headers.get("content-type")
|
|
97
|
+
`)}};import ne from"process";import{getTracer as Lt}from"@netlify/otel";import W from"process";var le=W.env.NETLIFY_API_URL,ue=W.env.NETLIFY_API_TOKEN,z=async(e,t={})=>{if(!le||!ue)throw new Error("No API URL or token");let r=new URL(e,le),o={...t,headers:{...t.headers,Authorization:`Bearer ${ue}`}};W.env.AGENT_RUNNERS_DEBUG==="true"&&(o.headers["x-nf-debug-logging"]="true"),t.json&&(o.headers||={},o.headers["Content-Type"]="application/json",o.body=JSON.stringify(t.json));let n=await fetch(r,o),s=n.ok&&n.status<=299;if(W.env.AGENT_RUNNERS_DEBUG==="true"&&(console.log(`[DEBUG] Response headers for ${r}:`),n.headers.forEach((i,a)=>{console.log(` ${a}: ${i}`)})),s||console.error(`Got status ${n.status} for request ${r}`),t.raw){if(!s)throw n;return n}let l=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!s)throw l;return l},Ne=e=>{console.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(le=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(ue=e.constants.NETLIFY_API_TOKEN)},Z=(e,t)=>z(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),Q=(e,t,r)=>z(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var Ie=(e,t)=>z(`/api/v1/agent_runners/${e}/sessions/${t}`),we=(e,t,r)=>z(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r}});var Ae=async({netlify:e,config:t})=>{let r,o,n,s,l=e.constants?.SITE_ID;if(!l)throw new Error("No site id");let i=async()=>{clearTimeout(n),console.log("Requesting AI gateway information");let a=await we(l,t.id,t.sessionId);if({token:r,url:s}=a,o=a.expires_at?a.expires_at*1e3:void 0,console.log("Got AI gateway information",{token:!!r,expiresAt:o,url:s}),o){let d=o-Date.now()-6e4;d>0&&(n=setTimeout(()=>{i()},d))}};return await i(),{get url(){return s},get token(){return r}}};import Re from"process";import{execa as dt,execaCommand as yo}from"execa";var pt={preferLocal:!0},Se=(e,t,r)=>{let[o,n]=ft(t,r),s={...pt,...n},l=dt(e,o,s);return mt(l,s),l};var ft=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},mt=(e,t)=>{t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0||(e.stdout?.pipe(Re.stdout),e.stderr?.pipe(Re.stderr))};var gt=e=>new Promise(t=>{setTimeout(t,e)}),ve=(e,t=3e3)=>{let r=!1,o=null,n=[],s=null,l=(...i)=>{if(r)return o=i,new Promise(u=>{n.push(u)});r=!0;let a,d=new Promise(u=>{a=u});return s=(async()=>{await Promise.resolve();let u=await e(...i);for(a(u);;){if(await gt(t),!o)return r=!1,s=null,u;let p=o,h=n;o=null,n=[],u=await e(...p),h.forEach(_=>{_(u)})}})(),d};return l.flush=async()=>{if((r||o)&&s)return await s,l.flush()},l},ee=(e,t,r=!1)=>{let o=null,n=null,s=null,l=function(...i){n=i,s=this;let a=r&&!o;clearTimeout(o),o=setTimeout(()=>{o=null,r||(e.apply(s,n),n=null,s=null)},t),a&&(e.apply(s,n),n=null,s=null)};return l.cancel=()=>{clearTimeout(o),o=null,n=null,s=null},l.flush=()=>{if(o){clearTimeout(o);let i=n,a=s;o=null,n=null,s=null,e.apply(a,i)}},l},te=(e,t=!0)=>{if(e)try{return JSON.parse(e)}catch(r){t&&console.error("Could not parse JSON",r)}},Ce=(e,t)=>{let n=".netlify.app",s="agent-";if(!t)return`${s}${e.slice(0,6)}`;let i=`--${t}${n}`;if(i.length>55)return"";let a=60-i.length;if(a<=0)return"";if(a>=s.length+6){let d=Math.min(a-s.length,e.length);return`${s}${e.slice(0,d)}`}return e.slice(0,a)},ht=e=>!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length===0?!1:!!he.some(t=>t in e),Pe=()=>{let e={},t={codex:process.env.NETLIFY_FF_AGENT_RUNNER_CODEX_VERSION,claude:process.env.NETLIFY_FF_AGENT_RUNNER_CLAUDE_VERSION,gemini:process.env.NETLIFY_FF_AGENT_RUNNER_GEMINI_VERSION};return Object.entries(t).forEach(([r,o])=>{if(o){let n=`NETLIFY_FF_AGENT_RUNNER_${r.toUpperCase()}_VERSION`;try{let s=JSON.parse(o);ht(s)&&(e[r]=s)}catch(s){let i=s instanceof SyntaxError?"Invalid JSON":s.message;console.error(`Could not parse ${r} model version override from ${n}: ${i}`)}}}),e};import{Buffer as Oe}from"buffer";var ke=async({config:e,netlify:t})=>{let{hasChanges:r,status:o}=await Et(t);if(!r)return{hasChanges:!1};let n=await yt(t,o);await t.utils.run("git",["add",".",...n]);let l=(await t.utils.run("git",["diff","--staged"])).stdout;if(r=!!l,!r)return{hasChanges:r,diff:l};let a=(await t.utils.run("git",["diff","--staged","--binary"])).stdout,d,u;if(e.sha){await t.utils.run("git",["commit","-m","Agent runner"]),d=(await t.utils.run("git",["diff",e.sha,"HEAD"])).stdout;let y=(await t.utils.run("git",["diff",e.sha,"HEAD","--binary"])).stdout;d!==y&&(u=Oe.from(y).toString("base64"))}let p={hasChanges:!0,diff:l,resultDiff:d};return l!==a&&(p.diffBinary=Oe.from(a).toString("base64")),u&&(p.resultDiffBinary=u),p},_t=["?? mise.toml",/\?\? .+?\.log/],Et=async e=>{let t=await e.utils.run("git",["status","-s"]);return{hasChanges:(t.stdout.trim().length===0?[]:t.stdout.split(`
|
|
98
98
|
`).filter(n=>!_t.some(s=>s instanceof RegExp?s.test(n):n===s))).length!==0,status:t.stdout}};var be=async e=>{let{stdout:t}=await e.utils.run("git",["rev-parse","HEAD"]);return t.trim()},Fe=async e=>{let{stdout:t}=await e.utils.run("git",["rev-list","--max-parents=0","HEAD"]);return t.trim()},yt=async(e,t="")=>{let r=[".netlify","mise.toml","node_modules"],o=[],n=r.map(async l=>{try{return await e.utils.run("git",["check-ignore","-v",l]),null}catch{return`:!${l}`}});return(await Promise.all(n)).forEach(l=>{l&&o.push(l)}),t.split(`
|
|
99
99
|
`).forEach(l=>{let i=l.match(/\?\? (.+?)\.log$/)?.[1];i&&o.push(`:!${i}.log`)}),o};import Tt from"fs/promises";import xt from"os";import oe from"path";import j from"process";var Nt=({catchError:e,runCmd:t,error:r,result:o,runnerName:n})=>(console.log(`${n} command completed with catch handler triggered`,{hadExistingError:!!r,hadExistingResult:!!o,resultLength:o?o.length:0,catchError:e?.message||"No error object",processExitCode:t.exitCode,processKilled:t.killed}),o?(console.log("Preserving existing result despite catch handler being triggered"),r?{error:r,result:o}:{error:"Process completed with errors but result was captured",result:o}):(console.log("Setting result to undefined because no valid result was captured"),{error:r||`${n} failed`,result:void 0}));async function ce({config:e,netlify:t,persistSteps:r,sendSteps:o,aiGateway:n}){let{accountType:s,prompt:l,modelVersionOverrides:i}=e,{model:a}=e;if(n){let{token:m,url:g}=n;if(!m||!g)throw new Error("No token or url provided from AI Gateway");let f=It[s];if(!f)throw new Error(`Claude is not supported for the account type ${s}`);if(a&&!f?.models?.[a])throw new Error(`${a} is not supported for account type ${s}`);if(i?.claude){let c=i?.claude?.[s];c&&(a=c)}j.env.ANTHROPIC_API_KEY=m,j.env.ANTHROPIC_BASE_URL=g}else if(!j.env.ANTHROPIC_API_KEY)throw new Error("ANTHROPIC_API_KEY is not provided");let d=[],u=[],p=[],h={},_=0,y=0,T,x,k=oe.join(j.cwd(),"node_modules"),v=[oe.join(j.env.NODE_PATH||k,".bin/claude"),"--permission-mode","bypassPermissions","--dangerously-skip-permissions","--output-format","stream-json","--verbose",...a?["--model",a]:[],"-p",l],C=`${j.env.NVM_BIN}/node`;console.log(`Running ${C} ${v.join(" ")}`);let A=t.utils.run(C,v,{all:!0,env:j.env});A.stdin?.end();let E=ee(()=>{r?.({steps:d,duration:y}),o?.({steps:u,duration:y}),u=[]},250),N=(m,g)=>{m.id=_,_+=1,p.push(m),d.push(m),u.push(m),g||E.flush(),E(),g&&E.flush()},R="";return A.all.on("data",m=>{if(R+=m.toString(),!m.includes(`
|
|
100
100
|
`))return;let g=R.split(`
|
package/dist/index.js
CHANGED
|
@@ -93,7 +93,7 @@ ${e}`;var ge=(e={})=>`
|
|
|
93
93
|
|
|
94
94
|
`)),{prompt:l.join(`
|
|
95
95
|
|
|
96
|
-
`)}};import te from"process";import{getTracer as Ct}from"@netlify/otel";import K from"process";var se=K.env.NETLIFY_API_URL,ie=K.env.NETLIFY_API_TOKEN,J=async(e,t={})=>{if(!se||!ie)throw new Error("No API URL or token");let r=new URL(e,se),o={...t,headers:{...t.headers,Authorization:`Bearer ${ie}`}};K.env.AGENT_RUNNERS_DEBUG==="true"&&(o.headers["x-nf-debug-logging"]="true"),t.json&&(o.headers||={},o.headers["Content-Type"]="application/json",o.body=JSON.stringify(t.json));let n=await fetch(r,o),s=n.ok&&n.status<=299;if(K.env.AGENT_RUNNERS_DEBUG==="true"&&(console.log(`[DEBUG] Response headers for ${r}:`),n.headers.forEach((a,i)=>{console.log(` ${i}: ${a}`)})),s||console.error(`Got status ${n.status} for request ${r}`),t.raw){if(!s)throw n;return n}let l=await(n.headers.get("content-type")
|
|
96
|
+
`)}};import te from"process";import{getTracer as Ct}from"@netlify/otel";import K from"process";var se=K.env.NETLIFY_API_URL,ie=K.env.NETLIFY_API_TOKEN,J=async(e,t={})=>{if(!se||!ie)throw new Error("No API URL or token");let r=new URL(e,se),o={...t,headers:{...t.headers,Authorization:`Bearer ${ie}`}};K.env.AGENT_RUNNERS_DEBUG==="true"&&(o.headers["x-nf-debug-logging"]="true"),t.json&&(o.headers||={},o.headers["Content-Type"]="application/json",o.body=JSON.stringify(t.json));let n=await fetch(r,o),s=n.ok&&n.status<=299;if(K.env.AGENT_RUNNERS_DEBUG==="true"&&(console.log(`[DEBUG] Response headers for ${r}:`),n.headers.forEach((a,i)=>{console.log(` ${i}: ${a}`)})),s||console.error(`Got status ${n.status} for request ${r}`),t.raw){if(!s)throw n;return n}let l=await(n.headers.get("content-type")?.includes("application/json")?n.json():n.text());if(!s)throw l;return l},_e=e=>{console.log("Setting details for api",{apiUrl:e?.constants?.NETLIFY_API_HOST,token:!!e?.constants?.NETLIFY_API_TOKEN}),e?.constants?.NETLIFY_API_HOST&&(se=`https://${e.constants.NETLIFY_API_HOST}`),e?.constants?.NETLIFY_API_TOKEN&&(ie=e.constants.NETLIFY_API_TOKEN)},z=(e,t)=>J(`/api/v1/agent_runners/${e}`,{method:"PUT",json:t}),W=(e,t,r)=>J(`/api/v1/agent_runners/${e}/sessions/${t}`,{method:"PUT",json:r});var xe=(e,t)=>J(`/api/v1/agent_runners/${e}/sessions/${t}`),Te=(e,t,r)=>J(`/api/v1/sites/${e}/ai-gateway/token`,{headers:{"X-Nf-Agent-Runner-Id":t,"X-Nf-Agent-Runner-Session-Id":r}});var Ee=async({netlify:e,config:t})=>{let r,o,n,s,l=e.constants?.SITE_ID;if(!l)throw new Error("No site id");let a=async()=>{clearTimeout(n),console.log("Requesting AI gateway information");let i=await Te(l,t.id,t.sessionId);if({token:r,url:s}=i,o=i.expires_at?i.expires_at*1e3:void 0,console.log("Got AI gateway information",{token:!!r,expiresAt:o,url:s}),o){let d=o-Date.now()-6e4;d>0&&(n=setTimeout(()=>{a()},d))}};return await a(),{get url(){return s},get token(){return r}}};import we from"process";import{execa as nt,execaCommand as so}from"execa";var st={preferLocal:!0},Ie=(e,t,r)=>{let[o,n]=it(t,r),s={...st,...n},l=nt(e,o,s);return at(l,s),l};var it=function(e,t){return Array.isArray(e)?[e,t]:typeof e=="object"&&e!==null?[[],e]:[[],void 0]},at=(e,t)=>{t.stdio!==void 0||t.stdout!==void 0||t.stderr!==void 0||(e.stdout?.pipe(we.stdout),e.stderr?.pipe(we.stderr))};var lt=e=>new Promise(t=>{setTimeout(t,e)}),Ae=(e,t=3e3)=>{let r=!1,o=null,n=[],s=null,l=(...a)=>{if(r)return o=a,new Promise(c=>{n.push(c)});r=!0;let i,d=new Promise(c=>{i=c});return s=(async()=>{await Promise.resolve();let c=await e(...a);for(i(c);;){if(await lt(t),!o)return r=!1,s=null,c;let p=o,h=n;o=null,n=[],c=await e(...p),h.forEach(y=>{y(c)})}})(),d};return l.flush=async()=>{if((r||o)&&s)return await s,l.flush()},l},Z=(e,t,r=!1)=>{let o=null,n=null,s=null,l=function(...a){n=a,s=this;let i=r&&!o;clearTimeout(o),o=setTimeout(()=>{o=null,r||(e.apply(s,n),n=null,s=null)},t),i&&(e.apply(s,n),n=null,s=null)};return l.cancel=()=>{clearTimeout(o),o=null,n=null,s=null},l.flush=()=>{if(o){clearTimeout(o);let a=n,i=s;o=null,n=null,s=null,e.apply(i,a)}},l},Se=(e,t=!0)=>{if(e)try{return JSON.parse(e)}catch(r){t&&console.error("Could not parse JSON",r)}},Ne=(e,t)=>{let n=".netlify.app",s="agent-";if(!t)return`${s}${e.slice(0,6)}`;let a=`--${t}${n}`;if(a.length>55)return"";let i=60-a.length;if(i<=0)return"";if(i>=s.length+6){let d=Math.min(i-s.length,e.length);return`${s}${e.slice(0,d)}`}return e.slice(0,i)};import{Buffer as ve}from"buffer";var Ce=async({config:e,netlify:t})=>{let{hasChanges:r,status:o}=await ct(t);if(!r)return{hasChanges:!1};let n=await dt(t,o);await t.utils.run("git",["add",".",...n]);let l=(await t.utils.run("git",["diff","--staged"])).stdout;if(r=!!l,!r)return{hasChanges:r,diff:l};let i=(await t.utils.run("git",["diff","--staged","--binary"])).stdout,d,c;if(e.sha){await t.utils.run("git",["commit","-m","Agent runner"]),d=(await t.utils.run("git",["diff",e.sha,"HEAD"])).stdout;let x=(await t.utils.run("git",["diff",e.sha,"HEAD","--binary"])).stdout;d!==x&&(c=ve.from(x).toString("base64"))}let p={hasChanges:!0,diff:l,resultDiff:d};return l!==i&&(p.diffBinary=ve.from(i).toString("base64")),c&&(p.resultDiffBinary=c),p},ut=["?? mise.toml",/\?\? .+?\.log/],ct=async e=>{let t=await e.utils.run("git",["status","-s"]);return{hasChanges:(t.stdout.trim().length===0?[]:t.stdout.split(`
|
|
97
97
|
`).filter(n=>!ut.some(s=>s instanceof RegExp?s.test(n):n===s))).length!==0,status:t.stdout}};var Re=async e=>{let{stdout:t}=await e.utils.run("git",["rev-parse","HEAD"]);return t.trim()},Pe=async e=>{let{stdout:t}=await e.utils.run("git",["rev-list","--max-parents=0","HEAD"]);return t.trim()},dt=async(e,t="")=>{let r=[".netlify","mise.toml","node_modules"],o=[],n=r.map(async l=>{try{return await e.utils.run("git",["check-ignore","-v",l]),null}catch{return`:!${l}`}});return(await Promise.all(n)).forEach(l=>{l&&o.push(l)}),t.split(`
|
|
98
98
|
`).forEach(l=>{let a=l.match(/\?\? (.+?)\.log$/)?.[1];a&&o.push(`:!${a}.log`)}),o};import pt from"fs/promises";import ft from"os";import Q from"path";import F from"process";var mt=({catchError:e,runCmd:t,error:r,result:o,runnerName:n})=>(console.log(`${n} command completed with catch handler triggered`,{hadExistingError:!!r,hadExistingResult:!!o,resultLength:o?o.length:0,catchError:e?.message||"No error object",processExitCode:t.exitCode,processKilled:t.killed}),o?(console.log("Preserving existing result despite catch handler being triggered"),r?{error:r,result:o}:{error:"Process completed with errors but result was captured",result:o}):(console.log("Setting result to undefined because no valid result was captured"),{error:r||`${n} failed`,result:void 0}));async function ae({config:e,netlify:t,persistSteps:r,sendSteps:o,aiGateway:n}){let{accountType:s,prompt:l,modelVersionOverrides:a}=e,{model:i}=e;if(n){let{token:m,url:g}=n;if(!m||!g)throw new Error("No token or url provided from AI Gateway");let f=gt[s];if(!f)throw new Error(`Claude is not supported for the account type ${s}`);if(i&&!f?.models?.[i])throw new Error(`${i} is not supported for account type ${s}`);if(a?.claude){let u=a?.claude?.[s];u&&(i=u)}F.env.ANTHROPIC_API_KEY=m,F.env.ANTHROPIC_BASE_URL=g}else if(!F.env.ANTHROPIC_API_KEY)throw new Error("ANTHROPIC_API_KEY is not provided");let d=[],c=[],p=[],h={},y=0,x=0,T,w,k=Q.join(F.cwd(),"node_modules"),v=[Q.join(F.env.NODE_PATH||k,".bin/claude"),"--permission-mode","bypassPermissions","--dangerously-skip-permissions","--output-format","stream-json","--verbose",...i?["--model",i]:[],"-p",l],C=`${F.env.NVM_BIN}/node`;console.log(`Running ${C} ${v.join(" ")}`);let S=t.utils.run(C,v,{all:!0,env:F.env});S.stdin?.end();let _=Z(()=>{r?.({steps:d,duration:x}),o?.({steps:c,duration:x}),c=[]},250),E=(m,g)=>{m.id=y,y+=1,p.push(m),d.push(m),c.push(m),g||_.flush(),_(),g&&_.flush()},N="";return S.all.on("data",m=>{if(N+=m.toString(),!m.includes(`
|
|
99
99
|
`))return;let g=N.split(`
|